Hi @Ayase Morita,
Thanks for reaching out to us. We are very pleased to support you.
There are several reasons for the problem of you getting the wrong number of results:
- Insufficient access: The search API (
search(q='1')
) respects the user's access permissions. If there are items that match the query but are inaccessible due to permission restrictions, they will be excluded from the results. For example, if there are 50 items found by the search, but the user only has permission to view 49 of them, the response will contain 49 items. Solution: Please ensure the requesting user has sufficient permissions to view all potential search results. - Hidden or System Files: SharePoint has hidden system files (e.g., metadata, thumbnails, or content types) that might be internally counted but excluded from the returned results. Solution: Please use additional filtering parameters to include or exclude specific item types. This filters out hidden files or ensures that only desired items are retrieved.
/drives/{drive-id}/items/root/search(q='1')?$top=50&$filter=folder ne null
- API Behavior with $top: The
$top
parameter is a suggestion rather than a strict limit. Graph API may return slightly fewer or more items based on internal logic and optimization. Solution: Please adjust the$top
value slightly higher (e.g.,$top=55
) to mitigate minor discrepancies. - Caching and Indexing Delays: SharePoint search relies on indexed data. If recent changes have occurred (e.g., new files uploaded or permissions changed), the search index may lag behind the current state. Solution: Please wait for indexing to complete (can take a few minutes to hours) and retry the search. Alternatively, confirm via the SharePoint UI if all expected files are visible.
If you have any questions, please do not hesitate to contact me. Moreover, if the issue can be fixed successfully, please click "Accept Answer" so that we can better archive the case and the other community members who are suffering the same issue can benefit from it.
Your kind contribution is much appreciated.