I am trying to create a subscription in the Graph API, following this documentation. It states that I need to do the following to validate my notification URL:
The client must respond with the following characteristics within 10 seconds of step 1:
- A status code of HTTP 200 OK.
- A content type of text/plain.
- A body that includes the URL decoded plain text validation token.
When I am testing this, I am receiving the following validation error:
{
"error": {
"code": "ValidationError",
"message": "\"Validation: Testing client application reachability for subscription Request-Id: bd78c77c-fcdc-4ed2-9a95-ea9e704380ed\"",
"innerError": {
"date": "2024-06-28T11:21:49",
"request-id": "bd78c77c-fcdc-4ed2-9a95-ea9e704380ed",
"client-request-id": "bd78c77c-fcdc-4ed2-9a95-ea9e704380ed"
}
}
}
The error here does not make sense, as the message here just contains the validation token I was sent to my endpoint. I have been testing this using DevTunnels in Visual Studio, and I have also tested this using ngrok and received the same result.
I can confirm that when I call this endpoint in Postman, using the exact same request that is sent, I get a 200 OK response, with a Content-Type of text/plain
, and the response body being "Validation: Testing client application reachability for subscription Request-Id: cdf5239b-8137-4a79-bada-8cdd1ac2fdf"
I have been developing this in C#, and I have tested this both with the Microsoft.Graph NuGet package, and writing it all out manually in HttpClient.
If anyone could let me know what I'm doing wrong here, or if someone from the relevant Microsoft Graph team could have a look at this specific request id, that would be great.
Much like other answers I've seen, it boils down to text/plain
, but I was a little surprised by why the error occurred.
In my ApiBaseController for where my code was, I have the following attribute: [Produces(System.Net.Mime.MediaTypeNames.Application.Json)]
. Then, in my code, I was calling
return new JsonResult(validationToken)
{
ContentType = "text/plain"
};
This was returning the result with the ContentType of text/plain
, but Microsoft was not accepting the value. This is because the result was getting a set of quotes added to the result. When I tested this on a completely plain controller not linked to any of my base code, I received the validation token back without any quotes.
In order to fix this, I added the following to the methods where I needed to return text/plain
: [Produces(System.Net.Mime.MediaTypeNames.Text.Plain)]
.
This does seem to not quite match up with what Microsoft state in their documentation, as they state the response must have:
A body that includes the URL decoded plain text validation token.
All I can assume, is that because there were quotes around the response, it did not count it as text/plain
and rejected it. Furthermore, it seems the response has to match exactly, as I tried returning a response with more data than just the validation token, and it was also rejected.
Just to keep it simple, the code is now just returning new OkObjectResult(validationToken);
and everything is behaving, and my issue was around the attribute headers of my controller/method.