ekk
ekk

Reputation: 31

Trouble creating a webhook using the Microsoft Graph API

Has anyone had any luck creating a webhook to receive notifications about changes to O365 calendar's events? I've been successful with the Outlook Notifications REST API, but trying the same with the new Microsoft Graph API has been a bumpy ride.

I've acquired an app-only token for https://graph.microsoft.com and I can generally use both v1.0- and beta-endpoint services just fine. However, when I try to create a new subscription (POST https://graph.microsoft.com/beta/subscriptions), I get this rather blurry error:

401 Unauthorized: {
  "error": {
    "code": "",
    "message": "Invalid security token.",
    "innerError": {
      "request-id": "c5a64878-e643-41be-b863-a598e05f38a4",
      "date": "2015-11-28T17:59:24"
    }
  }
}

I've given the following application permissions to my app: Microsoft Graph - Read all users' full profiles, Read directory data, and Read calendars in all mailboxes. According to the documentation Calendars.Read permission is required.

I wonder what I'm doing wrong or might it be that the create subscription service is unable to properly handle app-only token's?

EDIT:

The decoded token is:

{
 typ: "JWT",
 alg: "RS256",
 x5t: "MnC_VZcATfM5pOYiJHMba9goEKY",
 kid: "MnC_VZcATfM5pOYiJHMba9goEKY"
}.
{
 aud: "https://graph.microsoft.com/",
 iss: "https://sts.windows.net/58108de9-edf3-####-b20b-817520334d13/",
 iat: 1448814967,
 nbf: 1448814967,
 exp: 1448818867,
 appid: "5e80f22f-ff14-####-962a-2a9362a6057c",
 appidacr: "2",
 idp: "https://sts.windows.net/58108de9-edf3-####-b20b-817520334d13/",
 oid: "87b9064d-3dc7-####-9071-7a61b5b57840",
 roles: [
  "Calendars.Read",
  "Directory.Read.All",
  "User.Read.All"
 ],
 sub: "87b9064d-3dc7-####-9071-7a61b5b57840",
 tid: "58108de9-edf3-####-b20b-817520334d13",
 ver: "1.0"
}.

Upvotes: 3

Views: 981

Answers (1)

Yina - MSFT
Yina - MSFT

Reputation: 1786

Subscriptions are on a per user basis right now, therefore they cannot be created using an app-only token. Thank you for the feedback we will look into adding support for this scenario.

Upvotes: 2

Related Questions