question

ChristosGeorgiou-4000 avatar image
0 Votes"
ChristosGeorgiou-4000 asked MarcoEnxuto commented

How can I track changes to specific OneDrive folder under approot?

State


I have a personal OneDrive and a registered application “MyApplication”. In the personal OneDrive, there is this structure:

 /
  Apps
   MyApplication
    A_Subfolder

The id of “A_Subfolder” is BLABLABLABLA!112.

I can do an API GET for either drive/root:/Apps/MyApplication/A_Subfolder or drive/items/BLABLABLABLA!112 and I successfully get info about the folder.

Now, I want to subscribe to changes for “A_Subfolder”. If I want to subscribe to changes to the “MyApplication” folder, I can do it by API POST to /subscriptions with payload:

 {
 "changeType": "updated",
 "notificationUrl": "https://my.domain/my_webhook",
 "resource": "/drive/special/approot",
 "expirationDateTime": "2021-04-10T12:00:00Z",
 "clientState": "myState"
 }

After that, I get callbacks to my webhook.

Question


I want to subscribe to changes to “A_Subfolder”. So what do I need to supply as “resource” in the payload below of the /subscriptions POST?

 {
 "changeType": "updated",
 "notificationUrl": "https://my.domain/my_webhook",
 "resource": "??????????????????",
 "expirationDateTime": "2021-04-10T12:00:00Z",
 "clientState": "myState"
 }

What do I substitute for "??????????????????"?

More history


In the documentation for webhooks, there are these two distinct paragraphs:

driveItem on OneDrive (personal)
Changes to content within the hierarchy of any folder:
/users/{id}/drive/root

and:

driveItem on OneDrive for Business
Changes to content within the hierarchy of the root folder:
/drives/{id}/root
/users/{id}/drive/root

This distinction between “any folder” and “root folder” makes me understand that I can subscribe to the changes of a specific folder in a personal OneDrive drive. This is for an backend application that access specifically an app folder in the user's drive, under the associated app root folder.

However, all attempts so far to subscribe to anything else than drive/special/approot have failed; other attempts with drive/special/approot:/path/to/folder, drive/special/approot:path/to/folder, and drive/items/‹folder-id› result in 4xx errors.

Do I understand incorrectly the documentation? If not, how can I subscribe to a specific folder (including its subfolders, I have verified that this is the case as documented)?

PS In Use the Microsoft Graph API to get change notifications there is this:

On a personal OneDrive, you can subscribe to the root folder or any subfolder in that drive.

PS0 sample 4xx payloads
- "message": "resource '/drive/root:/Apps/‹my_app_name›' is not supported.",
- "message": "resource '/drive/items/xxxxxxxxxxxxxxxx!242' is not supported.",
- "message": "resource 'drive/items/xxxxxxxxxxxxxxxx!242' is not supported.",

The only one that works so far:

 {
 "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#subscriptions/$entity",
 "id": "xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx",
 "resource": "drive/special/approot",

PS1 In Use the Microsoft Graph API to get change notifications there is also this under “driveItem”:

On a personal OneDrive, you can subscribe to the root folder or any subfolder in that drive.

PS2: in Set up notifications for changes in user data - Microsoft Graph | Microsoft Docs there is this:

‣ Content within the hierarchy of any folder driveItem on a user's personal OneDrive
‣ Content within the hierarchy of the root folder driveItem on OneDrive for Business

PS3 In Create subscription - Microsoft Graph v1.0 | Microsoft Docs, there is this:

On a personal OneDrive, you can subscribe to the root folder or any subfolder in that drive.
On OneDrive for Business, you can subscribe to only the root folder.
Change notifications are sent for the requested types of changes on
the subscribed folder, or any file, folder, or other driveItem
instances in its hierarchy. You cannot subscribe to drive or driveItem
instances that are not folders, such as individual files.

So again: how do I specify the folder under the approot folder that I can subscribe to?


Update


Elsewhere I was asked if I tried with a /me prefix for the resource, so I copy here my response:

There is this folder:
GET /drive/items/7DCD75924995F1EC!242 or GET /drive/root:/Apps/tzot OneDrive handler/Extra data:

 {"parentReference": {"driveId": "7dcd75924995f1ec", "driveType": "personal", "path": "/drive/items/7DCD75924995F1EC!233:", "id": "7DCD75924995F1EC!233", "name": "tzot OneDrive handler"}, "cTag": "adDo3RENENzU5MjQ5OTVGMUVDITI0Mi42Mzc1Mjk4NzY4NzgyNzAwMDA", "lastModifiedDateTime": "2021-04-02T19:14:47.827Z", "name": "Extra data", "createdDateTime": "2021-03-16T13:48:55.97Z", "webUrl": "https://1drv.ms/f/s!AOzxlUmSdc19gXI", "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drive/items/$entity", "fileSystemInfo": {"createdDateTime": "2021-03-16T13:48:55.97Z", "lastModifiedDateTime": "2021-03-16T13:48:55.97Z"}, "lastModifiedBy": {"application": {"displayName": "OneDrive website", "id": "44048800"}, "user": {"displayName": "\u039a\u03bb\u03ac\u03bc\u03c0\u03b7\u03c2 \u039e\u03b5\u03bd\u03cd\u03c7\u03c4\u03b7\u03c2", "id": "7dcd75924995f1ec"}}, "eTag": "aN0RDRDc1OTI0OTk1RjFFQyEyNDIuMA", "createdBy": {"application": {"displayName": "OneDrive website", "id": "44048800"}, "user": {"displayName": "\u039a\u03bb\u03ac\u03bc\u03c0\u03b7\u03c2 \u039e\u03b5\u03bd\u03cd\u03c7\u03c4\u03b7\u03c2", "id": "7dcd75924995f1ec"}}, "folder": {"childCount": 4, "view": {"viewType": "thumbnails", "sortBy": "takenOrCreatedDateTime", "sortOrder": "ascending"}}, "id": "7DCD75924995F1EC!242", "size": 4754732}

(At this point, I don't care about protecting real IDs; these are the verbatim responses)

Attempt subscription using /me/drive/items/7DCD75924995F1EC!242:

{"innerError": {"date": "2021-04-11T10:23:30", "request-id": "d2dd8c64-d738-4442-ac68-0fd570ff8e98", "client-request-id": "d2dd8c64-d738-4442-ac68-0fd570ff8e98"}, "message": "resource '/me/drive/items/7DCD75924995F1EC!242' is not supported.", "code": "InvalidRequest"}

Attempt subscription using /me/drive/root:/Apps/tzot OneDrive handler/Extra Data:

{"innerError": {"date": "2021-04-11T10:57:46", "request-id": "a2647558-138b-4917-831e-84b62c1b5e3d", "client-request-id": "a2647558-138b-4917-831e-84b62c1b5e3d"}, "message": "resource '/me/drive/root:/Apps/tzot OneDrive handler/Extra Data' is not supported.", "code": "InvalidRequest"}

But I get a different message when I attempt subscription using '/me/drive:/Apps/tzot OneDrive handler/Extra Data' (no '/root'):

{"innerError": {"date": "2021-04-11T10:32:12", "request-id": "71e5009e-abe6-4b6a-8bd2-70b6a1650c69", "client-request-id": "71e5009e-abe6-4b6a-8bd2-70b6a1650c69"}, "message": "Specified resource is not supported for MSA requests.", "code": "InvalidRequest"}

So: how do I subscribe to that folder of my personal OneDrive?

microsoft-graph-files
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Deva-MSFT avatar image
0 Votes"
Deva-MSFT answered ChristosGeorgiou-4000 commented

Yes, you're correct and it's by design. On a personal OneDrive, you can subscribe to the root folder or any subfolder in that drive. On OneDrive for Business, you can subscribe to only the root folder. Change notifications are sent for the requested types of changes on the subscribed folder, or any file, folder, or other driveItem instances in its hierarchy. You cannot subscribe to drive or driveItem instances that are not folders, such as individual files.

Additional limitations apply for subscriptions on OneDrive items. The limitations apply to creating as well as managing (getting, updating, and deleting) subscriptions.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I updated the question above to (hopefully) clarify what the issue is.

0 Votes 0 ·

The question still stands: how do I subscribe to a subfolder in a Personal drive? I don't know how to specify the resource. Only “drive/special/approot” works.

0 Votes 0 ·
MarcoEnxuto avatar image
0 Votes"
MarcoEnxuto answered MarcoEnxuto commented

Hi all,
I have the exact same issue!
Can't subscribe to subfolders of the Approot.

Is this possible or not?
The docs are not clear.

I tried to use the DriveItem id, but without success.

DriveItemId option

170644-graphchangenotificationsonsubfolders.png

Path to folder option

170489-image.png


@Deva-MSFT do we need to open an issue on GitHub regarding the documentation or this is an issue with the API?


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Well there is this github onedrive documentation issue: https://github.com/OneDrive/onedrive-api-docs/issues/1471

0 Votes 0 ·
MarcoEnxuto avatar image MarcoEnxuto ChristosGeorgiou-3357 ·

No one is assigned to that issue @ChristosGeorgiou-4000
And that is the problem.

Let's give @Deva-MSFT some time to reply to this thread.

0 Votes 0 ·

Any news @Deva-MSFT?

0 Votes 0 ·

Just posted an update on GitHub, since it is related to this question. 1471


0 Votes 0 ·
MarcoEnxuto avatar image
0 Votes"
MarcoEnxuto answered

Update 2: I did an workaround since i cannot wait any longer for a reply.
I subscribe to the root folder with the changeType Updated.
It is the only way to monitor changes regarding subfolders, at least for now.

It's quite inconvenient, since i can create a file, or save from another file within the root folder, and that raises a notification. But i think i can live with that. I hope this suggestion helps.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.