Graph API Drive Search does only show my own files

Shadi Rashed 66 Reputation points
2024-07-08T15:35:01.3166667+00:00

Hello,

I am using REST API to search for Excel files that are visible to me. Basically I want to replicate the results that I get on the OneDrive UI if I search with the "All files" filter ( see screenshot)

My problem is that the endpoint only returns files that I own. However I want to see all files that I have access to, not only where I am owner. This is what I tried so far

https://graph.microsoft.com/v1.0/me/drive/search(q='.xlsx')
https://graph.microsoft.com/v1.0/me/drive/root/search(q='.xlsx')

The weird part is that the results show me some files that are not from me, but not all of them. So I wonder if the files need to fulfill some extra requirements to be returned by the search? One thing I noticed is that the files that are not shown are usually uploaded in a Sharepoint Document Library (that I also have acccess to). This should not be an issue from what I understand, because a document library also acts like a drive behind the scenes?

I can rule out page size, because I dont have access to many files.

So how can I search for files in Graph API and include all files that are visible to me?

Thanks for your help

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,380 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 40,141 Reputation points
    2024-07-09T03:03:09.0833333+00:00

    Hi @Shadi Rashed

    I recommend that you use the Microsoft Search API instead of the Drive API, the Search API allows you to search across OneDrive and SharePoint content more comprehensively.

    POST https://graph.microsoft.com/v1.0/search/query
    Content-Type: application/json
    
    {
      "requests": [
        {
          "entityTypes": [
            "driveItem"
          ],
          "query": {
            "queryString": ".xlsx"
          }
        }
      ]
    }
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.