1
votes

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://docs.microsoft.com/en-us/graph/webhooks and https://docs.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' \
1
Are you able to find the Drive using Graph Explorer (https://graph.microsoft.com/v1.0/drives/{id})? - Marc LaFleur
Yes, I can find the drive using Graph Explorer - nunespascal
I am also able to list folder items and download files using the api calls. It is only the subscription call that fails - nunespascal
Are you still experiencing the same issue? Could you try again and provide the request id from the response please? - baywet
Yup, still the same error "request-id": "0ea56aef-3a85-4573-82e2-d684a58a9df7", - nunespascal

1 Answers

1
votes

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.