I am trying to expand all items of MS Teams drive (SharePoint document library) using the Graph API.
I can access the team (group) but am unable to directly expand the Items collection. It would be great if that would be possible, so I don't need another query for that (performance!).
According to the documentation there is the $expand= option, in C# I have the Expand() extension method. Unfortunately I cannot find any working example of how to use it. Well, there is one example in the official documentation:
string messageId = "<guid>";
Message message = await graphClient.Me.Messages[messageId]
.Request()
.Expand("attachments")
.GetAsync();
But I am unable to reproduce it successfully. The property should be "Items", so I guess I should use lowercase "items" (but I also tried it with "Items").
Here is the teamsDrive
, when I won't expand anything, you see the properties is "Null" (it should have items, documents are present in the library):
teamDrive
{Microsoft.Graph.Drive}
Activities [IDriveActivitiesCollectionPage]:null
AdditionalData [IDictionary]:Count = 3
Bundles [IDriveBundlesCollectionPage]:null
CreatedBy:{Microsoft.Graph.IdentitySet}
CreatedByUser [User]:null
CreatedDateTime:{30/05/2020 23:46:46 +00:00}
Description [string]:""
DriveType [string]:"documentLibrary"
ETag [string]:null
Following [IDriveFollowingCollectionPage]:null
Id [string]:"b!QXf1ydGT80WWzfKB0A5IvAkI2isDR2NEh9jgSseDzmFpXz0eAriVS6TXSBEiZhVP"
Items [IDriveItemsCollectionPage]:null
LastModifiedBy [IdentitySet]:null
LastModifiedByUser [User]:null
So, I tried the following:
var teamDrive = await graphClient.Groups[group.Id].Drive.Request().Expand("items").GetAsync();
But this gives me an exception:
Status Code: BadRequest
Microsoft.Graph.ServiceException: Code: invalidRequest
Message: The request is malformed or incorrect.
Inner error:
AdditionalData:
request-id: 93ab7efd-0a33-4ff0-800e-d7e95acd8eb4
date: 2020-06-17T08:41:39
ClientRequestId: 93ab7efd-0a33-4ff0-800e-d7e95acd8eb4
at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
I am using the BETA Graph endpoint (https://graph.microsoft.com using an access token retrieved from https://login.microsoftonline.com/{our tenant Id}) with the Microsoft.Graph.Beta NuGet Package (Version 0.18.0-preview - the latest version).
Note that I don't use any select or filter statements in this request, as others have mentioned that this is not allowed when expanding: Expanding and Filtering MS Graph API Does Not Work