Reputation: 47
I'm trying to create a subscription to Microsoft Graph API to receive webhook notifications. To validate the endpoint, Microsoft Graph API sends a validation token in a POST request to the notification URL. I've set up an endpoint to respond to this validation request with the token, but I'm encountering an issue where the subscription validation request times out.
@RestController
public class ListenController {
@PostMapping(value = "/listen", headers = {"content-type=text/plain"})
@ResponseBody
public ResponseEntity<String> handleValidation(
HttpServletRequest request,
@RequestParam(value = "validationToken") final String validationToken) {
return ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN).body(validationToken);
}
}
When I test the endpoint by sending a POST request directly (for example, through Postman), it returns the expected 200 OK response. However, when I create a subscription through the Graph API, I receive a timeout error.
this is the post request that i use in Postman:
POST https://graph.microsoft.com/v1.0/subscriptions
{
"changeType": "updated",
"notificationUrl": url.com/listen,
"resource": "/sites/siteID/lists/listId ",
"expirationDateTime":"2023-11-20T18:23:45.9356913Z",
"clientState": "secretClientValue"
}
Upvotes: 0
Views: 571
Reputation: 37
Not sure if it will help you, but i have experienced this kind of behavior when the resource was not right and when the expirationDateTime was more than 3 days (we can't do a subscription for more than 3 days)
Upvotes: 1
Reputation: 51
Based on the scenario you've called out, a likely issue is that your notificationURL endpoint is not publicly accessible for Graph to call back and verify, so Graph is sending a timeout.
As a troubleshooting step, can you verify that your endpoint is accessible from another external location? An external ping tool like this may help: https://www.site24x7.com/ping-test.html
Upvotes: 0