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 Learn 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 Learn, 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?