Share via

Look only for files while searching document

captain_atharv 511 Reputation points
2022-06-06T10:57:21.483+00:00

Hi,

I'm using https://learn.microsoft.com/en-us/graph/api/driveitem-search?view=graph-rest-1.0&tabs=http to search for documents in drive.
This search returns both folders and files.
What is the most optimal way to filter out folders while searching so result only contains files?
I cannot filter after the API has responded as pagination logic is built around items returned in search response
PS. I cannot use Microsoft Search API as it only works for delegated access whereas I'm working on application context

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph

Answer accepted by question author

Tong Zhang_MSFT 9,261 Reputation points
2022-06-07T08:11:38.203+00:00

Hi @captain_atharv ,

Based on my research and testing, there is no way to filter out folders while searching, as a workaround ,you can use the following Graph API to look only for files.

https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$expand=fields&$filter=fields/ContentType ne 'Folder'  

Headers : Prefer HonorNonIndexedQueriesWarningMayFailRandomly

209002-image.png


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.


Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

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