Home > database >  How to get list of activities of DriveItem with msGraph sdk
How to get list of activities of DriveItem with msGraph sdk

Time:11-03

I have DriveItem that checkedOut by User1 with graph call

    https://graph.microsoft.com/v1.0/drives/b!_MSlF-BRbkK5zwikk7fK_8LD9uV_FvlFrLZugeivaLrxBB7Ow54qQrFVxpeg8KK/items/01VMODTUDZVXS2MQJORNEYUTEPWOJ7VSB?expand=activities

i have got my list of activities

{... "id": "01VMODTUDZVXS2MQJORNEYUTEPWOJ7VSB", ... "activities": [ { "@sharePoint.localizedRelativeTime": "1|0|3|38", "action": { "checkin": {}, "edit": {}, "version": { "newVersion": "3.0" } }, "actor": { "user": { "email": "xxx.onmicrosoft.com", "displayName": "Administrator)", "self": {}, "userPrincipalName": "[email protected]" } }, "id": "oFlcWLu82kiAeJgJAAAAAA==", "times": { "recordedTime": "2022-11-02T10:16:45Z" } ... } ], ... ... "shared": { "scope": "users" } }

if i try the same in my project using sdk for c#

var activities = await this.GraphServiceClient.Drives[driveId].Items[driveItemId]
        .Request()
        .Expand("activities")
        .GetAsync();

i get an exception with message :

** Parsing OData Select and Expand failed: Could not find a property named 'activities' on type 'microsoft.graph.driveItem'.**

What i do wrong?

CodePudding user response:

The HTTP Request that you execute actually ignores your "expand?" parameter as it does not contain the '$' in front of it. Therefore it fallsback to the normal '.../items/{item-id}' url that you used there. The activities you see are the "most recent" activities, per the documentation (cf. https://learn.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0#relationships).

In order to get more activities, you will need to pull the the activities by interval as described on this link: https://learn.microsoft.com/en-us/graph/api/itemactivitystat-getactivitybyinterval?view=graph-rest-1.0&tabs=http

CodePudding user response:

for API version 1.0

 var queryOptions = new List<QueryOption>()
{
  new QueryOption("expand", "activities")
};

  var driveItem = await this.GraphServiceClient.Drives[XXXXX].Items[XXXXXX]
            .Request(queryOptions)
            .GetAsync();

Drive Item property AdditionalData i have got new key/value item with key: Activity and Value: itemActivity collection

Thank you

  • Related