Unable to Retrieve Files from SharePoint Library Using REST API Due to List View Threshold

Navin Kumar S S 0 Reputation points
2025-01-21T10:12:37.2033333+00:00

Hi everyone,

I am encountering an issue while using the SharePoint REST API to retrieve files from a folder in a SharePoint library. The folder contains more than 5,000 files, and when I make the following GET API call: {sharepoint_site_url}/_api/web/getFolderByServerRelativeUrl('{encoded_folder_path}')/Files

I receive this error response:

{"error":{"code":"-2147024860, Microsoft.SharePoint.SPQueryThrottledException","message":{"lang":"en-US","value":"The attempted operation is prohibited because it exceeds the list view threshold."}}} It seems that the operation exceeds the list view threshold limit in SharePoint.

I would appreciate help with the following:

How can I retrieve files from a folder containing more than 5,000 items using the SharePoint REST API?

Is there any way to programmatically retrieve the files without triggering this threshold?

Are there alternative approaches or best practices to manage large libraries in SharePoint?

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,414 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,135 questions
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,229 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Xyza Xue_MSFT 27,736 Reputation points Microsoft Vendor
    2025-01-22T06:36:52.74+00:00

    Hi @Navin Kumar S S ,

    Thank you for posting in this community. You seem to have posted a duplicate thread, and that's okay. I will still provide an answer here as well.

    I know what you're going through. This is a known issue with the SharePoint REST API.

    It will throw an error if the query (or the first part of the filter query) returns more than 5000 items, even if you only use and return one item. $filter $top

    This doesn't work even if you are indexing the column. If possible, try reducing the number of items returned in the first part of the query.

    1.Here is a link on how to get by recursively calling:

    https://sharepoint.stackexchange.com/questions/217254/rest-to-read-more-than-5000-items-from-document-library

    2.In addition, you can retrieve more than 5,000 records from a SharePoint list using JavaScript and CAML queries. You need to use pagination. The following is an example of how to accomplish this:

    To retrieve files from a SharePoint library containing more than 5,000 items using the REST API, you can implement the following strategies:https://learn.microsoft.com/en-us/answers/questions/1808639/how-to-retrieve-more-than-5k-records-from-a-sharep3.manage large libraries in SharePoint

    Filter and Sort: Create filtered views that limit the number of items returned. By applying filters, you can ensure that the number of items returned does not exceed the list view threshold.

    Use Folders: Organizing files into folders can help manage the number of items in a single view. By retrieving files from a specific folder, you can avoid hitting the list view threshold.


    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.


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.