List threshold behavior for REST API getItems different for lists and libraries?

asked 2022-06-09T08:50:34.38+00:00
IRDC 1 Reputation point

I have a SPFX based webpart that makes recursive calls to the REST API to fetch all items from lists using RowLimit and Paged to make calls with max 5000 items. This works for lists (with more than 25000 items) but does not work for document libraries at all. Any try to call getitems for a library with more than 5000 files ends with "The attempted operation is prohibited because it exceeds the list view threshold." Even when I reduce the RowLimit to 1.

My query call looks like this:

const camlQueryPayLoad = {  
	query: {  
	  __metadata: { type: 'SP.CamlQuery' },  
	  ViewXml: '<View><RowLimit Paged="TRUE">5000</RowLimit><Query></Query></View>'  
	}  
};  

const query = '/_api/web/lists('GUID')/getitems?$select=ID,FileRef,FileSystemObjectType,ServerRedirectedEmbedUri,FileDirRef,FieldValuesAsText/DocIcon,DocIcon,FieldValuesAsText/LinkFilename,LinkFilename,FieldValuesAsText/Modified,Modified,FieldValuesAsText/Editor,EditorId,FieldValuesAsText/A,A,FieldValuesAsText/B,B,FieldValuesAsText/OData__x0043_,OData__x0043_,FieldValuesAsText/E,E&$expand=FieldValuesAsText'  

    const spOpts: ISPHttpClientOptions = {  
      headers: { 'Accept': 'application/json;odata=nometadata', 'odata-version': '3.0' },  
      body: JSON.stringify(camlQueryPayLoad)  
    };  

    t.context.spHttpClient.post(  
        t.context.pageContext.web.serverRelativeUrl + query,  
        SPHttpClient.configurations.v1,  
        spOpts  
      )  

Does anyone know of a relevant difference between calls to a list and a doc lib that might trigger this behavior? Anything else I could try? I considered using a GET request to "items" instead of the POST to "getItems" but that would mean a complete restructuring since I still want to be able to copy the full filtering and ordering from a selected view into the request if the list item count is below 5000 and that can't be done with "items". (Not sure about queries to certain folders with more than 5000 files and "items").

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.
1,664 questions
{count} votes

1 answer

Sort by: Most helpful
  1. answered 2022-06-10T06:36:50.667+00:00
    Tong Zhang_MSFT 8,706 Reputation points Microsoft Employee

    Hi @IRDC ,

    According to my research and testing, I recommend you try to use the following REST API to get more than 5000 Items in SPFX:

    {YourSiteCollectionUrl}/_api/web/Lists/GetByTitle('{YourListTitle}')/items?%24skiptoken=Paged%3DTRUE%26p_ID%3D{ItemToStartsWith}&%24top={TopCount}&$select=Attachments,AttachmentFiles,*&$expand=AttachmentFiles    
    

    More information for reference:
    https://www.c-sharpcorner.com/article/reading-more-than-5000-items-using-rest-api-in-sharepoint-framework-spfx-with/

    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    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.