Subscription validation request failed. Notification endpoint must respond with 200 OK to validation request.

Khushbu Dave 6 Reputation points
2021-05-31T13:35:22.86+00:00

I'm trying to use the subscriptions endpoint for resource /me/messages. But getting 400 . Can someone please help me to figure out what am i doing wrong ??
Below are the details:

CODE:

const options = {
authProvider,
};

const client = Client.init(options);

const subscription = {changeType: 'updated',notificationUrl: 'https://<domain-name>/flows/ae176be5-72db-4a3a-a2b1-efaa0b8fbd4d/components/ba8b7727-ebb8-4d37-873d-f8bad09058a5',resource: '/me/messages',expirationDateTime: '2021-06-02T10:40:57.553Z',clientState: 'ba8b7727-ebb8-4d37-873d-f8bad09058a5'};

await client.api('/subscriptions')
.post(subscription);

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,735 questions
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Shweta Choudhary 601 Reputation points Microsoft Employee
    2021-06-03T14:44:41.727+00:00

    Few things to check here -

    1. Try isolating the code and use Postman/Graph Explorer to call same API and observe results.
    2. Do note notificationUrl must be capable of responding to the validation request. Also, you need to make sure that the validation token returns as plain/text. Please refer to the Notification endpoint validation document for details.
    3. Other requirements(from the same reference):
      response within 10 seconds
      200 (OK) status code.
      content type must be text/plain.
      body must include the validation token.
      1. Code Samples
        ASP.NET MVC Sample - Specifically look at the NotificationController.cs file
      [HttpPost]
      public async Task<ActionResult> Listen()
      {
      // Validate the new subscription by sending the token back to Microsoft Graph.  
      // This response is required for each subscription.  
      if (Request.QueryString["validationToken"] != null)  
      {  
          var token = Request.QueryString["validationToken"];  
          return Content(token, "plain/text");  
      }  
      

    Please upvote if this helps. Thanks!