I just implemented such a feature for our webapp accessing a customer's SharePoint site. So to make the process for anyone searching for this a bit less painful than it was for me, here's a quick rundown:
Get Notified of changes
You subscribe to the SharePoint drive root folder just like a OneDrive root folder, i.e. at /drives/{driveid}/root
with a POST request like so:
POST https://graph.microsoft.com/v1.0/subscriptions
Content-Type: application/json
{
"changeType": "updated",
"notificationUrl": "{notificationUrl}",
"resource": "/drives/{driveId}/root",
"expirationDateTime": "{expirationDateTime}",
"clientState": "{secretClientState}"
}
The only changeType supported for a driveItem is "updated" ( https://docs.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0#properties ) and on SharePoint / OneDrive for Business you can only subscribe to the root folder ( https://docs.microsoft.com/en-us/graph/api/subscription-get?view=graph-rest-1.0&tabs=http#driveitem ).
The expirationDateTime is only valid if set at maximum 4230 minutes in the future!
So you'd have to renew the subscription almost daily to keep it alive. ( https://docs.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0#maximum-length-of-subscription-per-resource-type )
Find out what has changed
Microsoft does not deliver resource metadata with the update notification, so for that you'd have to leverage the delta API. (https://docs.microsoft.com/en-us/graph/api/driveitem-delta?view=graph-rest-1.0&tabs=http)
Essentially, you get a token representing a baseline state and when you query the API again with this token, it returns the resources that have changed since then.
So you get a token at a given time
GET https://graph.microsoft.com/v1.0/drives/{driveId}/root/delta?token=latest
and then, when you get a change notification after that, you query the API with that token to find out what has happened.
After this, you get another delta token so you're up to date. Repeat.
(This is simplified a bit, you can also get a full list of items as a baseline, but we only care about new items).
https://docs.microsoft.com/en-us/graph/api/driveitem-delta?view=graph-rest-1.0&tabs=http#retrieving-the-current-deltalink
See https://docs.microsoft.com/en-us/graph/webhooks and https://docs.microsoft.com/en-us/graph/delta-query-overview for an overview.