Solution to use Recursive call to retrieve more than 5000 items in SharePoint REST API



var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('DocumentList')/items?$top=1000";
//By default REST API retrieve 100 items. By using top we can retrieve up to  5000 items

    var response = response || [];  // this variable is used for storing list items

    function GetListItems(){

        $.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; // to get the next set of items

                    GetListItems();//Recursive function

                }

            },

            error: function(error){

               

            }

        });

    }





Comments

Popular posts from this blog

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

Add content type to SharePoint List/Library using REST API

A type named 'SP.Data. could not be resolved by the model error