Search files with given file name substring in OneDrive

Dhruvin Moradiya 55 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
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,452 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    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".