Microsoft Graph API:/me/drive/root/search无法筛选特定扩展名文件咨询
/me/drive/root/search The core issue here is that you’re using the wrong search operator for file extensions in the Graph API’s q parameter. Unlike some other search tools that use filetype:, Microsoft Graph’s search syntax relies on ext: to target specific file extensions—and that’s why your original query returned no results.
Correct Query Syntax
Swap out filetype: for ext: in your query string, and you’ll get the filtered results you’re expecting:
https://graph.microsoft.com/v1.0/me/drive/root/search(q='book ext:xlsx OR ext:xls OR ext:svg OR ext:json OR ext:txt')
Why This Works
Microsoft Graph’s built-in search query language uses ext: as the dedicated operator for filtering by file extension. The filetype: keyword isn’t recognized by this endpoint, so your original query was effectively asking for files that matched "book" but had no valid extension filter applied.
Quick Notes
- Double-check your app has the necessary permissions (like
Files.ReadorFiles.Read.All) to access the files you’re searching for—though it sounds like your permissions are already set correctly since you can retrieve results and filter them manually. - The
/searchendpoint doesn’t support combining theqparameter with$filter, so using theext:operator is the proper server-side way to narrow down results by file type, avoiding the need for post-response manual filtering.
内容的提问来源于stack exchange,提问作者Paweł Wojtaszko

