0

We have a SharePoint 2016 list with 15,000 records and we need to get all the items using REST API. We can use top to read only top 5000 records.

If I need to read data in sets of 5000 items and then push it to a JavaScript array, how to achieve this?

Ganesh Sanap - MVP
  • 44,918
  • 21
  • 30
  • 61
Vikas Kottari
  • 468
  • 2
  • 8
  • 18

1 Answers1

2

You can use data.d.__next property and recursive calls to fetch more than 5000 items from SharePoint list like:

var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('DocumentList')/items?$select=customerID&$top=5000";
    var response = response || [];  // this variable is used for storing list items
    function GetListItems(){
        return $.ajax({
            url: url,  
            method: "GET",  
            headers: {  
                "Accept": "application/json; odata=verbose"  
            },
            success: function(data){
                response = response.concat(data.d.results);
                if (data.d.__next) {
                    url = data.d.__next;
                    GetListItems();
                }
                $.each(response, function(index, item) {
                    arrayCustomerID[index] = item.customerID;
                });
            },
            error: function(error){
            }
        });
    }

Similar thread: Rest to read more than 5000 items from document library

Ganesh Sanap - MVP
  • 44,918
  • 21
  • 30
  • 61