Dogu Arslan
Dogu Arslan

Reputation: 3384

OneDrive Search api does not support Expand query on ListItems

I need to search for files with .docx extension in my OneDrive. So this bit is simple and it works using OneDrive search api. The piece that does not work, is that in the response, with each DriveItem, I also need the custom properties we created under ListItem.Fields associated with this DriveItem. These custom properties contain information I need to create some sort of a report.

Expanding ListItem seems to work on root/children resource without any search, but it does not solve my problem, I need the files with the .docx extension in their filenames, these files can be under root or any sub folder under the root.

So this request returns the CustomProperty with the response

/_api/v2.0/drives/[drive id]/root/children?select=*%2cwebDavUrl
%2csharepointIds&expand=listItem(select%3dfields%3bexpand%3dfields(select%3dCustomProperty))

But when I try to expand ListItem on the DriveItems returned from search query as below:

/_api/v2.0/drives/[drive id]/root/search(q='docx')?select=*%2cwebDavUrl%2csharepointIds&expand=listItem(select%3dfields%3bexpand%3dfields(select%3dCustomProperty))

I get an error:

Error: {"error":{"code":"notSupported","message":"The request is not supported by the system."}}

Is expanding ListItem.Fields on a DriveItem not supported in OneDrive Search api ?

If it is not, then is there another way for me to achieve what I want to do here? I am not trying to search on the CustomProperty, just want to retrieve that value as part of the response with its associated DriveItem.

Expectedly, I get same/similar error if I run this through Microsoft Graph Search api instead of OneDrive api.

One workaround I could do, is to first search for .docx files without the expand keyword and it will recursively search and return all .docx files in my OneDrive. Then I could make individual calls to request these items again one by one from OneDrive using their DriveItem.Id and the expanded ListItem.Fields property. That would be a terrible workaround though. Because instead of achieving what I need in a single request, I would have to make 1000s or 10000s of individual I/O requests (one per .docx file) to get the expanded ListItem properties..

Upvotes: 1

Views: 921

Answers (1)

Marc LaFleur
Marc LaFleur

Reputation: 33094

This is a known issue with the /search endpoint. Unfortunately, there isn't a good workaround available at the moment either. In order to retrieve the ListItem resources, you will need to retrieve each DriveItem from your search result directly:

/drives/{drive-id}/items/{item-id}?$expand=listItem

Upvotes: 2

Related Questions