Regarding the number of data included in the API response for retrieving folder file lists when specifying the top parameter in SharePoint.

Ayase Morita 180 Reputation points
2025-03-03T07:25:49.2433333+00:00

In the response of the SharePoint folder list retrieval API using GraphAPI (API used: drives/{drive-id}/items/root/search(q='1')?$top=50), despite specifying top=50, the data within value was 49 items.

Please explain the cause of the discrepancy between the top parameter and the data returned in value when using this API, as well as possible solutions.

https://learn.microsoft.com/ja-jp/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=http

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,394 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Ling Zhou_MSFT 22,575 Reputation points Microsoft External Staff
    2025-03-03T08:12:16.5366667+00:00

    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:

    1. 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.
    2. 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
      
    3. 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.
    4. 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.


  2. Ayase Morita 180 Reputation points
    2025-03-04T00:44:21.6466667+00:00

    @Ling Zhou_MSFT

    Please allow me to ask an additional question.

    I need to specify top=50 to retrieve exactly 50 pieces of data. Is there a way to make hidden files visible?


  3. Ling Zhou_MSFT 22,575 Reputation points Microsoft External Staff
    2025-03-04T02:22:10.0066667+00:00

    Hi @Ayase Morita,

    Hope everything is going well.

    Please allow me to re-explain why your top attribute is not returning accurate results.

    When using the Microsoft Graph API, the top attribute is used to limit the number of results returned in a single response. However, it's important to note that the top attribute specifies the maximum number of items to return, not the exact number. This means that the actual number of results returned can be less than the specified value due to various reasons such as filtering, permissions, or the availability of data.

    I****f the user making the request has API full control but no access to the files in the site, then he won't be able to see them in the response either. This causes you to return fewer results.

    In my test, user Karley has API full control. However, she only has access to one file in the document library, so only one result will be returned.

    User's image

    User's image

    User's image

    User's imageRegarding the hidden files, I apologize that I may not have made myself clear**. Hidden files are those files that users don't have access to, and for them these are said to be hidden files.** The number of results returned by the user should match the number of results they see in the UI. As for system-hidden files, the Graph API does not count them in the results. I may have answered this point incorrectly.You can have your users start by first querying the UI for the first 50 eligible files and comparing them to the results obtained by the Graph API to see if they match. If they don't, then see which file is the problem.

    If you have any questions, please do not hesitate to contact me.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. It will be beneficial to more community members reading here. Your contribution will be highly appreciated.


  4. Ling Zhou_MSFT 22,575 Reputation points Microsoft External Staff
    2025-03-04T06:21:06.4166667+00:00

    Hi @Ayase Morita,

    Appreciate for letting us know about your user experience.

    Question 1:

    The maximum number of queries that $top can retrieve varies with different APIs. For the API you are using the default maximum returned is 200 (one page).

    User's image

    User's image

    Reference:

    If the UI is not convenient for statistics, we can click the Export to excel button above the document library. This will export the properties of all the files (including the ones under the folder), and then we filter the excel file for all the files that are of type item and have column q with a value of 1.

    User's image

    User's image

    If there is any question, please feel free to contact me.


    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.


Your answer

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