How to fetch data more than 5000 from SharePoint list using rest api in jquery?

Fetch more than 5,000 items from SharePoint using rest api:

var resultData = []; // variable (array) is used for storing list items
var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('Company')/items?$top=1000"; //SP list URL or REST API, In rest api Company is List name
function fetchDataFromSPList(){
    $.ajax({  // Ajax 
        url: url,  
        method: "GET",  
        headers: {  
            "Accept": "application/json; odata=verbose"  
        },
        success: function(data){
            resultData = resultData.concat(data.d.results);
            if (data.d.__next != undefined) {
                url = data.d.__next;
                fetchDataFromSPList();
            }else{
                console.log(resultData);//After retrieving all data it will print on console of browser
            }
            
        },
        error: function(error){
           // error
            console.error(error);
        }
    });
}
fetchDataFromSPList();

Output:
Here in Company list , 8720 items are available. as shown in Image below

Comments

Popular posts from this blog

Get list item entity type full name of a SharePoint list using REST API

Get SharePoint list name by GUID

Get Current Web Logged In User of SharePoint Site in jQuery