1
votes

I am currently testing the implementation of a Webhook with the Graph API but I seem to have some problems with getting the notifications. I am subscribing to calendar events of a user resource (i.e. myself) like this:

    // Initialize the GraphServiceClient.
    GraphServiceClient client = await MicrosoftGraphClient.GetGraphServiceClient();

    //Create subscription
    var request = client.Subscriptions.Request();
    var subscription = new Subscription
    {
        ChangeType = "updated",
        NotificationUrl = "https://cc3949e3.ngrok.io/Communication/Listen",
        Resource = "users/b4f9f62f-0993-4288-8efa-387cff59de9d/events",
        ExpirationDateTime = DateTimeOffset.Now.AddDays(1),
        ClientState = "My_secreet_client_value"
    };
    var newSubscription = await request.AddAsync(subscription);
{
    "resource": "users/b4f9f62f-0993-4288-8efa-387cff59de9d/events",
    "changeType": "updated",
    "clientState": "My_secreet_client_value",
    "notificationUrl": "https://cc3949e3.ngrok.io/Communication/Listen",
    "expirationDateTime": "2019-12-04T10:03:37.9876214+00:00",
    "applicationId": "bd1f8386-f148-45ee-957d-90c18bb1a6e3",
    "creatorId": "35636f28-5598-4772-9d99-19bf55de60ac",
    "id": "5869875e-492c-48a6-8305-029abef6d168",
    "@odata.type": "microsoft.graph.subscription",
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#subscriptions/$entity",
    "responseHeaders": {
        "Cache-Control": ["private"],
        "Location": ["https://subscriptionstore.windows.net/1.0/subscriptions('5869875e-492c-48a6-8305-029abef6d168')"],
        "request-id": ["c85fba68-803e-42ea-8cf3-a66be8f2fae7"],
        "client-request-id": ["c85fba68-803e-42ea-8cf3-a66be8f2fae7"],
        "x-ms-ags-diagnostic": ["{\"ServerInfo\":{\"DataCenter\":\"North Europe\",\"Slice\":\"SliceC\",\"Ring\":\"3\",\"ScaleUnit\":\"002\",\"RoleInstance\":\"AGSFE_IN_11\"}}"],
        "OData-Version": ["4.0"],
        "Strict-Transport-Security": ["max-age=31536000"],
        "Date": ["Tue, 03 Dec 2019 10:03:42 GMT"]
    },
    "statusCode": "Created"
}

The response on the notification URL is handled like this:

[HttpPost("Listen")]
public async Task<IActionResult> Listen([FromQuery]string validationToken = null)
{
    // handle validation
    if (!string.IsNullOrEmpty(validationToken))
    {
        return Ok(validationToken);
    }

    // handle notifications
    MSGraphTemplate.Models.Notifications notifications;
    using (StreamReader reader = new StreamReader(Request.Body))
    {
        string content = reader.ReadToEnd();

        notifications = JsonConvert.DeserializeObject<Notifications>(content);

        [DO STUFF HERE WITH NOTIFICATIONS]
    }

    return Ok();
}

The token validation works fine. Also when checking the active subscriptions

    // Initialize the GraphServiceClient.
    GraphServiceClient client = await MicrosoftGraphClient.GetGraphServiceClient();

    var subRequest = client.Subscriptions.Request();
    var result = subRequest.GetAsync().Result;

    return Ok(result);

it shows me the active subscription:

    {
        "resource": "users/b4f9f62f-0993-4288-8efa-387cff59de9d/events",
        "changeType": "updated",
        "notificationUrl": "https://cc3949e3.ngrok.io/Communication/Listen",
        "expirationDateTime": "2019-12-04T10:08:08.7432958+00:00",
        "applicationId": "bd1f8386-f148-45ee-957d-90c18bb1a6e3",
        "creatorId": "35636f28-5598-4772-9d99-19bf55de60ac",
        "id": "1587894f-4be3-4e58-8117-dd346059911d",
        "@odata.type": "microsoft.graph.subscription"
    }

But I do not get any notifications whatsoever when I am moving a calendar event in my outlook. I tried it also with 'created' and 'deleted' but without any success.

As far as I can tell, the ngrok tunnel is also working as the token validation works fine.

Any idea on how to debug/check/improve the situation?

1

1 Answers

0
votes

There is a problem with Graph Subscriptions that has been reported several times since yesterday, which I also experienced myself. Here is an open Github Issue but there is currently no answer from Microsoft.