I’m trying to subscribe to my calendar events using Microsoft Graph API in Postman,
but I keep encountering a 400 error.
I believe I have the correct API permissions (Calendars.Read, Calendars.ReadBasic.All, Calendars.ReadWrite), but I’m not sure what is causing the issue.`
POST https://graph.microsoft.com/v1.0/subscriptions
{
"changeType": "created",
"notificationUrl" : "{myDomain}/api/comm/v1/Room/get-notify",
"resource": "/users/{myUserId}/events",
"expirationDateTime": "2024-09-13T18:23:45.9356913Z",
"clientState": "a1b2c3d4e5"
}
Response:
{
"error": {
"code": "ValidationError",
"message": "Subscription validation request failed. Notification endpoint must respond with 200 OK to validation request.",
"innerError": {
"date": "2024-09-12T02:39:53",
"request-id": "1f37444a-9b9a-43b1-bad1-996bd52c8b15",
"client-request-id": "1f37444a-9b9a-43b1-bad1-996bd52c8b15"
}
}
}
Server Code:
[HttpPost("v1/Room/get-notify")]
public IActionResult Index([FromBody] JsonElement requestBody)
{
if (Request.Headers.ContainsKey("validationToken"))
{
var token = Request.Headers["validationToken"].ToString();
return Ok(token);
}
string jsonString = JsonSerializer.Serialize(requestBody);
var query = "INSERT INTO [Room].[JsonContent] (JsonContent) VALUES (@JsonContent)";
_connection.Execute(query, new { JsonContent = jsonString });
return Ok();
}
1