Graph API for searching OneDrive files always returns empty result until I search on the OneDrive website manually

Richie Hao 20 Reputation points
2025-01-03T02:41:57.24+00:00

I use this Graph API https://graph.microsoft.com/v1.0/me/drive/root/search(q='q') to search files in my personal OneDrive. It worked last night, but the API returned an empty result this morning. Then, I tried the same search keyword on the OneDrive website, it can find relevant files. After this, I executed the same Graph API again, it returned the correct files this time. I have met this problem several times, the Graph API always returns an empty result if I haven't called it for a few hours. I have to execute the search on the website manually, and then searching with Graph API can return the current results.

Microsoft 365 and Office | OneDrive | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Saranya Madhu-MSFT 2,375 Reputation points Microsoft External Staff
    2025-01-03T03:50:57.52+00:00

    Hi @Richie Hao ,

    Thanks for reaching out to Microsoft!

    As per the documentation here: "Microsoft 365 and announcing that we will no longer be making improvements to the OneDrive and SharePoint search APIs in favor of Microsoft Search APIs in Microsoft Graph."

    If your application uses the drive search query against a non-OneDrive for Business drive, then use the following query:

    POST https://graph.microsoft.com/v1.0/search/query

    Content-type: application/json

    {"requests": [

            {

                "entityTypes": [

                    "driveItem"

                ],

                "query": {

                    "queryString": "contoso (path:[https://contoso-my.sharepoint.com/personal/johndoe_contoso_com])"

                }

            }

        ]

    }

    For personal OneDrive, currently POST https://graph.microsoft.com/v1.0/search/query not retrieving the successful response, consider submitting a support ticket New support request - Microsoft Entra admin center or https://admin.microsoft.com/#/support/requests to Microsoft. They can provide more detailed insights and help resolve any underlying issues.

    Hope this helps.

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


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.