Microsoft Graph API - OneDrive Webhook Subscription - Missing resourceData

JO-5324 81 Reputation points
2022-09-12T06:59:18.707+00:00

Hi there,

What I would like to accomplish:
Create a webhook subscription to get notified when a new file was added to OneDrive.
Send the URL of this file to another system.

I was able to create the webhook subscription:
POST v1.0 https://graph.microsoft.com/v1.0/subscriptions/
{
"changeType": "created",
"notificationUrl": "https://mycompany.com/endpoint",
"resource": "me/drives/b!1lVEG878979798797rY6lE6MlpN1VmjlrtoAcTJIODFA4xdEn/root",
"expirationDateTime": "2022-09-13T00:00:00Z"
}

Based on the documentation OneDrive only supports the "updated" changeType. Source

When I then create a new file on OneDrive I get the following POST body:
{
"value": [
{
"subscriptionId": "94d39be7-ba1a-4d2a-b83e-bfc3b1c746ca",
"clientState": null,
"resource": "me/drives/b!1lVEG878979798797rY6lE6MlpN1VmjlrtoAcTJIODFA4xdEn/root",
"tenantId": "f81434a7-5648-4ba6-a67f-83a42e7b1f0d",
"resourceData": null,
"subscriptionExpirationDateTime": "2022-09-13T00:00:00+00:00",
"changeType": "updated"
}
]
}

As you can see, the resourceData property is null.
How can I receive this information?
I would like to know the ID of the changed file (in my case the newly created file), fetch metadata of this file and send it to another system.

Thank you in advance.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,890 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,950 questions
{count} votes

2 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 35,071 Reputation points Microsoft Vendor
    2022-09-13T06:35:04.957+00:00

    Hi @JO-5324
    Not all resources return resourceData within the notification itself, OneDrive is one of these.
    OneDrive will return the following properties:

    {  
      "subscriptionId": "string",  
      "expirationDateTime": "datetime",  
      "resource": "relative url",  
      "clientState": "string optional",  
      "changeType": "updated"  
    }  
    

    You can find the spesific documentation for this entity here.


    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.



  2. Srinivasa Rao Darna 6,716 Reputation points Microsoft Vendor
    2022-09-14T06:41:20.11+00:00

    Hi @JO-5324 ,

    As per documentation drive subscriptions, in the subscription create request it is important to use the "changeType": "updated" as it is the only supported type for the drive resource.

    For drive subscriptions resourceData: null, you will need to use the delta functionality ( /drive/root/delta ) on the target drive’s root object to track state and find what changed.

    Refer to devblog: onedrive-webhooks-with-microsoft-graph.

    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

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.