Search files with given file name substring in OneDrive

Dhruvin Moradiya 30 Reputation points
2023-03-09T10:55:22.5966667+00:00

I want to search for files in a specific folder based on the given file name (it can be a substring of the file name).
/me/drive/search(q='Contoso Project') Endpoint searches this q parameter across several fields. I want that it to search for file names only.

If five files have 'test' as a substring in their name, then /me/drive/search(q='test') API should return five files only. Right now, it's returning mode then five files (comparing substring 'test' with multiple fields).

Any Idea how to limit search queries to file names only?

Also, /me/drive/search(q='Contoso Project') endpoint doesn't return all types of files. I want all types (mimeTypes) files in search results.

Microsoft Graph Files API
Microsoft Graph Files API
A Microsoft API to create an app that connects with files across OneDrive, OneDrive for Business, and SharePoint document libraries.
321 questions
Microsoft Graph Search API
Microsoft Graph Search API
A Microsoft API that searches for information in email messages, returns messages ranked by relevance, and renders a dedicated search experience.
164 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sayantan Ganguly-MSFT 530 Reputation points Microsoft Vendor
    2023-03-09T22:37:54.71+00:00

    Hello Dhruvin Moradiya,

    Thanks for reaching out!

    To get files in a specific folder based on the given file name please refer to the documentation. Including ParentLink:/FolderName, along with Path should be able to retrieve files and images as well from a parent folder.

    POST https://graph.microsoft.com/v1.0/search/query  
    {  
    "requests": [  
        {  
            "entityTypes": [  
                "driveItem"  
            ],  
            "query": {  
                "queryString": "searchstring AND Path:https://contoso.sharepoint.com/sites/Library/Shared Documents AND ParentLink:/FolderName"  
            }  
        }  
    ]  
    }  
    

    Please refer to the similar post:
    https://learn.microsoft.com/en-us/answers/questions/702018/graph-api-search-for-driveitems-within-a-drive-doe#answer-704760

    Hope this helps.

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