4
votes

I am having trouble starting a Microsoft Graph webhook subscription (for a mailbox in particular). When initiating the subscription it appears as though Microsoft accepts all of the parameters I am sending to configure the subscription but fails the total subscription because it is receiving a non 2xx response from the endpoint I have configured.

The reason my endpoint is sending a 401 back to Microsoft is because their POST that includes the subscription validation token is missing the clientState.

I am using the clientState key-value pair to authenticate all the communication between Microsoft and my endpoint. If my endpoint does not see the correct clientState it will return a 401.

Any ideas on what I might be missing or if I should go about this in a different way? In my opinion allowing my endpoint to accept unauthenticated GET/POST's is not an option.

Example request body using POST method including the API key in the header:

{
    "changeType": "created",
    "clientState": "testClientState",
    "resource": "users/<UserName>/messages",
    "expirationDateTime": "2017-08-10T10:24:57.0000000Z",
    "notificationUrl": "<EndpointURL>"
}

Error Returned from Microsoft:

"error": {
    "code": "InvalidRequest",
    "message": "Subscription validation request failed. Must respond with 200 OK to this request.",
    "innerError": {
        "request-id": "adf7fc7b-6b14-4422-8526-c1391be8dd27",
        "date": "2017-08-07T16:24:59"
    }
}

I understand everything to work as intended until my endpoint is sent the validation token because I receive the validation token but my endpoint rejects it because it is missing the client state.

Endpoint Log Snippet:

queryStringParameters": {
    "validationToken": "<ValidationToken sent by Microsoft>"
}

I am basing my API endpoint logic off of some of Microsoft's developer guides. For the subscription creation in particular I am using this guide.

It appears this question was also asked but not answered on GitHub.

1

1 Answers

1
votes

I represent Microsoft Graph Web hooks team ...

We verified your request in our MS Graph Service logs and confirmed that it was failed at Subscription validation phase because of HTTP status code='Unauthorized' from your endpoint ... Up to this everything is correct per your observation ...

By design, MS Graph Web hooks do not send the clientState header as part of the Subscription validation request. Please do not expect for this header during the subscription validation.

More information

  1. You would have expected to receive the clientState as part of the validation request header because Office365 graph sends it https://msdn.microsoft.com/en-us/office/office365/api/notify-rest-operations. Office 365 Graph different from MS Graph ...
  2. There are some document improvements observed with this question at https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/subscription_post_subscriptions ... Example Publisher Notification Payload, which is after successful subscription is mentioned together with the Subscription validation … We fixed those.