如何使用Microsoft graph API为已发送邮件文件夹创建订阅

时间:2018-08-27 11:45:00

标签: json microsoft-graph

使用Microsoft Graph为“已发送邮件”文件夹创建订阅时,以下发布请求给出错误

var apiUrl = "https://graph.microsoft.com/v1.0/subscriptions";

请求

{
  "resource": "me/mailFolders('Sent Items')/messages",
  "changeType": "created,updated,deleted",
  "clientState": "320a6f10-9c62-4e59-a395-8cd27941b597",
  "notificationUrl": "https://webhook.site/aaaa-6f49-4906-aaaa-e911f9391695",
  "expirationDateTime": "2018-08-28T12:53:41.4830081+00:00"
}

错误响应

{
  "error": {
    "code": "ExtensionError",
    "message": "Operation: Create; Exception: [Status Code: BadRequest; Reason: Bad Request]",
    "innerError": {
      "request-id": "359f51a6-5b12-41f6-8a02-a68ba4c10585",
      "date": "2018-08-27T06:42:18"
    }
  }
}

2 个答案:

答案 0 :(得分:1)

很遗憾,您使用的webhook.site测试网站没有实现设置订阅所需的validation token protocol。 Webhook必须在响应正文中返回validationToken查询参数的值,才能正确创建订阅。

答案 1 :(得分:1)

i将文件夹名称“已发送邮件”的资源属性值更改为“ SentItems ”。这是工作要求

{
  "resource": "me/mailFolders('SentItems')/messages",
  "changeType": "created,updated,deleted",
  "clientState": "320a6f10-9c62-4e59-a395-8cd27941b597",
  "notificationUrl": "https://webhook.site/aaaa-6f49-4906-aaaa-e911f9391695",
  "expirationDateTime": "2018-08-29T12:53:41.4830081+00:00"
}