Reputation: 13
I've been working on implementing Microsoft Graph webhook subscriptions in my application, and I've run into an issue with subscription validation. Whenever I attempt to validate the subscription, I receive the following error message:
GraphError: Subscription validation request failed. Notification endpoint must respond with 200 OK to validation request.
Here's a snippet of my code that handles the validation request:
@Post('event')
async eventWebhook(@Req() req, @Res() res) {
if (req.query && req.query.validationToken) {
res.set('Content-Type', 'text/plain');
res.send(200, req.query.validationToken);
return;
}
//... other logics to handle events
}
Additionally, I've used the official Postman collection provided by Microsoft to simulate the validation request, and it appears to work correctly. Here's the Postman request and response:
Postman Request:
curl --location --request POST 'api.com/event?validationToken=somethin'
Postman Response:
200 OK | 641 ms | 312 B
body : somethin
However, when I run my application on the server and attempt to set up a subscription through Microsoft Graph, I consistently encounter the validation error mentioned above.
I've verified the following:
The endpoint URL matches exactly with what I've specified in the subscription setup. There are no network or firewall issues; the server is publicly accessible. Middleware and routing do not interfere with the validation request. There are no unexpected headers in the response. The server configuration for handling POST requests is correct.
GraphError: Subscription validation request failed. Notification endpoint must respond with 200 OK to validation request.
at new GraphError (/usr/src/app/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphError.js:34:28)
at Function.GraphErrorHandler.constructErrorFromResponse (/usr/src/app/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphErrorHandler.js:63:22)
at Function.<anonymous> (/usr/src/app/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphErrorHandler.js:91:48)
at step (/usr/src/app/node_modules/tslib/tslib.js:193:27)
at Object.next (/usr/src/app/node_modules/tslib/tslib.js:174:57)
at /usr/src/app/node_modules/tslib/tslib.js:167:75
at new Promise (<anonymous>)
at Object.__awaiter (/usr/src/app/node_modules/tslib/tslib.js:163:16)
at Function.GraphErrorHandler.getError (/usr/src/app/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphErrorHandler.js:87:24)
at GraphRequest.<anonymous> (/usr/src/app/node_modules/@microsoft/microsoft-graph-client/lib/src/GraphRequest.js:315:84) {
statusCode: 400,
code: 'InvalidRequest',
requestId: 'uuid',
date: Date obj,
body: '{"code":"InvalidRequest","message":"Subscription validation request failed. Notification endpoint must respond with 200 OK to validation request.","innerError":{"date":"Date obj","request-id":"uuid","client-request-id":"uuid
headers: Headers {
[Symbol(map)]: [Object: null prototype] {
'cache-control': [Array],
'transfer-encoding': [Array],
'content-type': [Array],
'content-encoding': [Array],
vary: [Array],
'strict-transport-security': [Array],
'request-id': [Array],
'client-request-id': [Array],
'x-ms-ags-diagnostic': [Array],
date: [Array],
connection: [Array]
}
}
I'm unsure why the validation request fails in my application but works with Postman. Can anyone offer guidance on what could be causing this issue or suggest potential solutions?
Upvotes: 0
Views: 782
Reputation: 51
I'm a PM on Microsoft Graph Change Notifications team.
If Postman works, then unintentional application encoding is likely culprit. There is a chance that there is something in the encoding that your application is using that may alter the response being sent Can you view the response you're sending to determine encoding?
Upvotes: 0