question

KhushbuDave-7186 avatar image
0 Votes"
KhushbuDave-7186 asked ShwetaChoudhary-8869 edited

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

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-notifications
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.

1 Answer

ShwetaChoudhary-8869 avatar image
0 Votes"
ShwetaChoudhary-8869 answered ShwetaChoudhary-8869 edited

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.


  4. 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!



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.