Getting Item not found error while adding subscription to SharePoint list using MS Graph Webhook

Chintan Upadhayay 21 Reputation points
2022-11-25T12:42:00.517+00:00

Hi,

I am trying to register an MS Graph webhook to the SharePoint document library. I have created an Azure AD app(With Outah 2.0, ClientID, and Secret ) to get tokens, passing the same token to the https://graph.microsoft.com/v1.0/subscriptions also created a Simple HTTP trigger on Azure Functions.

I am getting the below error when I POST a subscription request. The user has only contributed level access on the Document level only.

Request Body:
EndPoint URL : https://graph.microsoft.com/v1.0/subscriptions
Method : Post

 {  
        "changeType": "updated",  
        "notificationUrl": "https://<hostname>.azurewebsites.net/api/HttpTrigger1",  
        "resource": "/sites/ed8e5556-0c0c-466f-8ba4-30804a84300b/lists/f3818403-d27c-40f9-b490-57e760e1b8af",  
        "expirationDateTime": "2022-11-30T00:00:00.00Z",  
        "clientState": "SecretClientState"  
    }  

Status Code : 404 Not Found

Response

{  
    "error": {  
        "code": "ExtensionError",  
        "message": "Operation: Create; Exception: [Status Code: NotFound; Reason: Item not found]",  
        "innerError": {  
            "date": "2022-11-25T12:08:43",  
            "request-id": "18c0d53a-9776-40f6-98db-f7186bfff4b8",  
            "client-request-id": "18c0d53a-9776-40f6-98db-f7186bfff4b8"  
        }  
    }  
}  
Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Rob Windsor 2,001 Reputation points
    2022-11-27T11:32:16.017+00:00

    The value for resource in your request body is improperly formatted. The site Id is not just a GUID, it's a value made up of the tenant host name, the site collection GUID, and the site GUID. It should look something like this:

    contoso.sharepoint.com,130df549-fe92-4160-a4d6-151b48335fa2,427124d7-af02-4009-97f6-5b7c1d17873f

    You can get the site id by making a request using the tenant host name and the server relative URL. It would look something like this:

    https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com:/sites/Demo

    Once you have the site Id, you can update the value of resource look something like this:

    /sites/contoso.sharepoint.com,130df549-fe92-4160-a4d6-151b48335fa2,427124d7-af02-4009-97f6-5b7c1d17873f/lists/b158ba42-e98a-4813-8cc9-100c58227801


  2. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-12-01T06:56:05.583+00:00

    Hi @Chintan Upadhayay
    You could try to use SharePoint rest api to create subscription

    POST /_api/web/lists('5C77031A-9621-4DFC-BB5D-57803A94E91D')/subscriptions  
    

    Here is the document for details
    https://learn.microsoft.com/en-us/sharepoint/dev/apis/webhooks/lists/create-subscription


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.