Search code examples
c#azuremicrosoft-graph-apimicrosoft-graph-sdks

Retrieve MS Graph API DriveItem with thumbnails in one API request


I am using the following request to search for drive items in the C# SDK:

var queryOptions = new List<QueryOption>()
                       {
                           new QueryOption("select", "name,id,webUrl,webDavUrl,parentReference,thumbnails")
                       };

searchItems = await _graphServiceClient.Me.Drives[DriveID].Root
                            .ItemWithPath(PathOrDriveItemID)
                            .Search(SearchItem)
                            .Request(queryOptions)
                            .GetAsync();

DriveItem has a thumbnail option but I cannot seem to get the values via this request by setting the queryOptions. Is it not possible?

I am able to do this request separately to get the thumbnail but I want to reduce it to one call if possible:

response = await _graphServiceClient.Me.Drives[DriveID].Root
                       .ItemWithPath(PathOrDriveItemID).Thumbnails
                       .Request()
                       .GetAsync();

Solution

  • The thumbnails is not a property, but a relationship. It will be retrieved if you specify the thumbnails in $expand.

    var queryOptions = new List<QueryOption>()
                       {
                           new QueryOption("select", "name,id,webUrl,webDavUrl,parentReference"),
                           new QueryOption("expand", "thumbnails")
                       };
    
    searchItems = await _graphServiceClient.Me.Drives[DriveID].Root
                            .ItemWithPath(PathOrDriveItemID)
                            .Search(SearchItem)
                            .Request(queryOptions)
                            .GetAsync();