nunespascal
nunespascal

Reputation: 17724

Value of resource when subscribing to webhook notifications using graph api

I am trying to subscribe to the Microsoft Graph API for webhook notifications to track changes in a folder in a SharePoint Document library. I have app only access to this SharePoint site and am able to see and download all the content within the drive associate with the document library. I can also upload new files using API.

When I make the call to the subscription endpoint I receive an internal server error.

Here is the request I make

curl -X POST \
  https://graph.microsoft.com/v1.0/drive/root/subscriptions \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Authorization: Bearer TOKEN' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Length: 303' \
  -H 'Content-Type: application/json' \
  -H 'Host: graph.microsoft.com' \
  -d '{
  "changeType": "updated",
  "notificationUrl": "https://c.ngrok.io/sp-hook",
  "resource": "drives/{{DRIVE-ID}}/root",
  "expirationDateTime": "2019-09-18T11:23:00.000",
  "clientState": "test"
}'

Here is the response I get

{
  "error": {
    "code": "InternalServerError",
    "message": "Unable to find target address",
    "innerError": {
      "request-id": "c8e66e50-5b94-4593-88d5-3111e5c5c6c7",
      "date": "2019-09-13T09:50:12"
    }
  }
}

I believe this could be due to a wrong resource value, but I could not locate documentation about what the value of resource should be. I have gone over: https://learn.microsoft.com/en-us/graph/webhooks and https://learn.microsoft.com/en-us/graph/api/resources/webhooks?view=graph-rest-1.0. All the documentation seems to point to a resource value of "me/drives/root", however with app only access a my site is not defined and so the call fails.

These are the different values for resource that I have tried within the request json body

drives('DRIVE-ID')/root
drives/DRIVE-ID/root
DRIVE-ID
drive/DRIVE-ID
drive/DRIVE-ID/root
me/drive("DRIVE-ID")/root
DRIVE-ITEM-ID-FOR-ROOT

Different documentation seems to point to different subscription endpoints. These are the different endpoints I have tried https://graph.microsoft.com/v1.0/subscriptions https://graph.microsoft.com/v1.0/drive/root/subscriptions https://graph.microsoft.com/beta/drives/{{drive-id}}/root/subscriptions

The error also made me suspect that during subscription registration, it was not able to find my webhook. However having tested the endpoint I am sure it is accessible.

Additional information

I use the following call to get the drive id for a sharepoint site

curl -X GET \
  'https://graph.microsoft.com/v1.0/sites/SITE-ID/drive' \
  -H 'Accept: */*' \
  -H 'Accept-Encoding: gzip, deflate' \
  -H 'Authorization: Bearer TOKEN' \
  -H 'Cache-Control: no-cache' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/json' \
  -H 'Host: graph.microsoft.com' \

Upvotes: 1

Views: 681

Answers (1)

Venkat Chepuru
Venkat Chepuru

Reputation: 86

I see you are performing POST on https://graph.microsoft.com/v1.0/drive/root/subscriptions endpoint

Expected subscriptions endpoint is https://graph.microsoft.com/v1.0/subscriptions

Please note there is no '/drive/root' in the URL path.

Upvotes: 1

Related Questions