Getting 400 Bad Request Error for MSGraph's create subscription api [Error Code - ExtensionError]

自作多情 提交于 2020-07-08 00:45:31

问题


Trying to create a subscription to get a channel for msgraph one drive notifications for file creation/upload. I am hitting the URL -

https://graph.microsoft.com/v1.0/subscriptions  

with proper headers and the following body -

{ 
    "changeType": "updated",
    "notificationUrl": "https://xxxxx.xxxxxxxxx.com/zzzz/qwertqwert",
    "resource": "/users/{user-id}/drive/root",
    "expirationDateTime": "2017-02-18T19:49:40.000Z",
    "clientState": "justsomerandomstring"

}

I am getting the following response : 400 Bad Request Error

{
  "error": {
    "code": "ExtensionError",
    "message": "Operation: Create; Exception: [Status Code: BadRequest; Reason: Bad Request]",
    "innerError": {
      "request-id": "2862896286-5415-4921-gbn5-8741288985",
      "date": "2017-02-17T17:30:22"
    }
  }
}

I was making the same request 30-32 hrs back. Was getting the subscription-id as well as the file notifications on my redirection servlet. Not able to figure out what changed. Couldn't find any helping documentation either


回答1:


Got the same error here and it took me a while to find out what is the problem so I share this with you here.

Here's the working code:

$subscription = new Subscription([
  'resource'        => "me/mailFolders('Inbox')/messages?filter=id eq %27" . $draftEmail->getId() . '%27', 
  'notificationUrl' => 'https://my.domain.fr',
  'changeType'      => 'updated',
  'expirationDateTime' => date(DATE_ISO8601, strtotime('+48 hours'))
]);

The line which was wrong for me is:

'resource' => 'me/messages/' . $draftEmail->getParentFolderId(),

And i replace it with

'resource' => "me/mailFolders('Inbox')/messages?filter=id eq %27" . $draftEmail->getId() . '%27', 

I found my answer in this link: https://msdn.microsoft.com/en-us/office/office365/api/notify-rest-operations#subscribe-to-changes-in-my-mail-calendar-contacts-or-tasks

But in my opinion the "resource" parameter should be more documented on graph api documentation and the error message return must specify WHY this is a BadRequest.




回答2:


Using beta api version solved my problem,

https://graph.microsoft.com/beta/subscriptions


来源:https://stackoverflow.com/questions/42304324/getting-400-bad-request-error-for-msgraphs-create-subscription-api-error-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!