0

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

crucifix94
  • 193
  • 2
  • 14
  • The issue went away now. I am able to create new channel and subscriptions for the accounts which were blocked before. But I would still like to know the cause behind the issue – crucifix94 Mar 09 '17 at 06:54
  • The issue is back. This time I haven't even been calling the APIs for setting subscription channels for a long time now. The accounts just are getting the same error again – crucifix94 Apr 06 '17 at 07:23
  • You're not alone.I am having the same problem with creating subscriptions. It was working fine, I did not change anything and now gets 400 bad request a week later. – JFlox Apr 07 '17 at 22:02

2 Answers2

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.

0

Using beta api version solved my problem,

https://graph.microsoft.com/beta/subscriptions
teymourlouie
  • 6,645
  • 2
  • 21
  • 13