'How to get activities on specific Item in OneDrive for business API
I'm trying to get DriveItem activities on OneDrive for business using this Graph API https://docs.microsoft.com/en-us/graph/api/itemactivitystat-getactivitybyinterval?view=graph-rest-1.0&tabs=csharp
But the Activity property of the returned response is always null and I can not get what I need (activities on the specific DriveItem, like edits, comments etc.)
Definitely there are some activities for that driveItem, webhook is triggered on item change and I'm able to track changes using delta API: https://docs.microsoft.com/en-us/graph/delta-query-overview.
The code I'm using is like this:
var request = new GraphServiceClient(new DelegateAuthenticationProvider(msg =>
{
msg.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
return Task.CompletedTask;
}))
.Drives[driveId].Items[driveItemId]
.GetActivitiesByInterval(start, end, "day")
.Request();
var resultPage = await request.GetAsync();
The full response with Activities == null is below:
{
"Access": {
"ActionCount": 3,
"ActorCount": 1,
"AdditionalData": {
"timeSpentInSeconds": {
"ValueKind": 4
}
},
"ODataType": null
},
"Create": null,
"Delete": null,
"Edit": null,
"EndDateTime": "2022-02-12T23:59:59+00:00",
"IncompleteData": {
"MissingDataBeforeDateTime": null,
"WasThrottled": false,
"AdditionalData": {
"resultsPending": {
"ValueKind": 6
},
"notSupported": {
"ValueKind": 6
}
},
"ODataType": null
},
"IsTrending": null,
"Move": null,
"StartDateTime": "2022-02-12T00:00:00+00:00",
"Activities": null,
"ActivitiesNextLink": null,
"Id": null,
"ODataType": "#microsoft.graph.itemActivityStat",
"AdditionalData": {
"aggregationInterval": {
"ValueKind": 3
}
}
}
Is there a way to get a list of activities for the specific OneDrive item through API (comments, edits, etc.)?
Solution 1:[1]
The only way of getting user activities I've found so far is to use this SharePoint site list API instead of OneDrive API directly: https://docs.microsoft.com/en-us/graph/api/list-get?view=graph-rest-1.0&tabs=csharp
,where {list-id} is user's SharePoint site list named userActivityFeedHiddenList.
The API response is a bit cryptic, but it's possible to see who commented what on a document and when. Response examples can be found here https://charleslakes.com/2020/09/28/onedrive-hidden-list-user-activity/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vladimir Efimenko |
