POST https://graph.microsoft.com/v1.0/subscriptions resulted in a 400 Bad Request

Shruti Malode 0 Reputation points
2024-07-03T05:32:54.5866667+00:00

Below is my code for subscribing notifications from outlook calendar webhooks. The code is not responding with validation token for the client side as unable to complete the POST subscribe request. Please help.

 $client = new \GuzzleHttp\Client();   
 $response = $client->post('https://graph.microsoft.com/v1.0/subscriptions', [
        'headers' => [
            'Authorization' => 'Bearer ' . $accessToken,
            'Content-Type' => 'application/json',
    ],
        'json' => [
            'changeType' => 'created,updated,deleted',
            'notificationUrl' =>  $notifcationUrl,
            'resource' => '/me/events', 
            'expirationDateTime' => $expirationDateTime, 
            'clientState' => '12345678',
        ],
    ]);
Outlook | Windows | Classic Outlook for Windows | For business
Microsoft Security | Microsoft Graph
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2024-07-03T09:23:50.1266667+00:00

    Hi @Shruti Malode

    According to the Graph API, the notification endpoint must be able to respond to validation requests, and if validation fails, 400 error requests are returned.

    User's image

    See this link for more details:

    https://learn.microsoft.com/en-us/graph/change-notifications-overview#notification-endpoint-validation

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


  2. Shruti Malode 0 Reputation points
    2024-07-16T10:27:54.2933333+00:00

    My notification url has dev.xyz.uno is the domain name
    Because still getting 400 error for validationError
    Please check the code for any errors

    //code for subscription
     $expirationDateTime = Carbon::now()->addMinutes(4230)->toIso8601String();
        $notificationUrl='https://dev.xyz.uno/en/outlook-calendar/webhooks';
      
            $client = new \GuzzleHttp\Client();
        $response = $client->post('https://graph.microsoft.com/v1.0/subscriptions', [
            'headers' => [
              'Authorization' => 'Bearer ' . $accessToken,
              'Content-Type' => 'application/json',
            ],
            'json' => [
              'changeType' => 'created,updated,deleted',
              'notificationUrl' => $notificationUrl,
              'resource' => '/me/events',
              'expirationDateTime' => $expirationDateTime,
              'clientState' => 'test1234',
            ],
          ]);
          if ($response->getStatusCode() === 201) {
            $subscription = json_decode($response->getBody()->getContents(), true);
            print_r($subscription);
        
          }
    
    //code to recieve notifications having route as 
    https://dev.xyz.uno/en/outlook-calendar/webhooks
    
    
    public function handleNotification(Request $request)
    { 
        
        $validationToken = $request->header('validationToken');
        if ($validationToken) {
            return response($validationToken, 200)
                ->header('Content-Type', 'text/plain; charset=utf-8');
        }
        }
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.