Search code examples
sharepointmicrosoft-graph-apimicrosoft-graph-files

What is the best way to retrieve SharePoint files' '@microsoft.graph.downloadUrl' from MSGraph when using the search query?


I'm creating an application that gets SharePoint files and uses the downloadURL in various places, I'm struggling with finding an efficient way of searching files whilst also being able to get the information I need in the response.

To search the SharePoint files I am using this endpoint: https://graph.microsoft.com/v1.0/shares/{DriveID}/driveitem/search(q='{SearchQuery}')

I've looked around and it seems that when using the search criteria MSGraph doesn't retrieve instance properties like '@microsoft.graph.downloadUrl'. My current thought for a solution to this would be to retrieve the ItemID and Parent DriveID of each file from the search and then use batching to call the Graph for each file from the search.

With the limit on batching being so small, and searches being able to retrieve hundreds of files this seems like a bad solution as we would have to use many different batch calls to the graph per search.

Are there any better solutions to retrieving the downloadURL when using the search function in Microsoft Graph?


Solution

  • According to my research and testing, there is no way to use search query to retrieve @microsoft.graph.downloadUrl.Search API can retrieve only properties but not instance attributes like "@microsoft.graph.downloadUrl".

    We can only use the GET /drive/items/{item-ID}?select=id,@microsoft.graph.downloadUrl to retrieve the download URL of the file.

    For reference:

    https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http#example-1