question

avantassel avatar image
0 Votes"
avantassel asked avantassel answered

Calendar Events Subscription returns 400

I am trying to subscribe to calendar events but get a 400 with no reason. Any help would be great. Thanks.

Here is the response:

"Client error: POST https://graph.microsoft.com/v1.0/subscriptions resulted in a 400 Bad Request response: { "error": { "code": "InvalidRequest", "message": "Subscription validation request failed. Response must ex (truncated...) "

Here is my subscription post in PHP

 $subscription = [
       "changeType" => "created",
       "notificationUrl" => $notificationUrl,
       // "resource" => "me/calendars/$calendarId/events", // want to do this but not clear if this will work
       "resource" => "me/events",
       "expirationDateTime" => date('c',strtotime('+4 hour +20 minutes')),
       "latestSupportedTlsVersion" => "v1_2"
     ];
    
 $graph = new Graph();
     $graph
       ->setBaseUrl("https://graph.microsoft.com")
       ->setApiVersion("v1.0")
       ->setAccessToken($token['access_token']);
          
     try {
       $result = $graph->createRequest("POST", "/subscriptions")
               ->addHeaders(array("Content-Type" => "application/json"))
               ->attachBody($subscription)
               ->setTimeout("1000")
               ->execute();
       return json_decode(json_encode($result));
     } catch(Exception $ex){
       error_log(__METHOD__." Error: ".$ex->getMessage());
     }      
microsoft-graph-calendar
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

avantassel avatar image
0 Votes"
avantassel answered

Actually just tested this some more and looks like this
It turns out that the validationToken is coming back as GET and not a POST method as described in the docs.

https://docs.microsoft.com/en-us/graph/webhooks#notification-endpoint-validation

I was getting a 400 for not returning the validationToken

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DianaWanjuhi-1579 avatar image
0 Votes"
DianaWanjuhi-1579 answered

Hello @avantassel to answer your question: "resource" => "me/calendars/$calendarId/events" might not work - from the change notification documentation, subscription is available on an outlook event rather than a calendar. Are you able to reproduce the issue in Postman or Graph Explorer? Perhaps there is a failure parsing the timestamp as sent?

Let me know if this helps,

Diana.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.