Search by filename in drive

Olga Andreeva 126 Reputation points
2024-06-17T11:59:22.8566667+00:00

Hello,

I am using Microsoft Graph API to search for files. I am using the following API:

/groups/{group-id}/drive/items/{item-id}/search(q='search')

In my test, I expect to receive all the files with the search query in filename, file content or metadata.

The use case I am testing:

  1. I have a folder with Fir.png and test1.docx (content: 'this is first test') files.
  2. I am trying to search with the API above the search query 'fir'.

Actual result: I received only test1.docx file ( as it has content containing 'fir')

Expected result: I receive Fir.png and test1.docx. (search is by filename and by file content)

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,225 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,137 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,790 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 35,941 Reputation points Microsoft Vendor
    2024-06-18T02:29:32.58+00:00

    Hi @Olga Andreeva,

    You could refer to following api to search file.

    POST https://graph.microsoft.com/v1.0/search/query
    
    {
        "requests": [
            {
                "entityTypes": [
                    "driveItem"
                ],
                "query": {
                    "queryString": "filename:fir.txt AND path:\"https://tenant-my.sharepoint.com/sites/xxx/Documents/folder\""
                }
            }
        ]
    }
    
    
    

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

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


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.