1
votes

We are trying to query the Sharepoint API. We are using the below query to get the top 5000 and it works.

  https://abc.123.org/sites/js/project/_api/web/lists/GetByTitle('S%20Codes')/items?$top=5000

But breaks if we try to get more than 5000 records. We also tried to use the skip in the query parameter to get the next 5000 records and it is not working

https://abc.123.org/sites/js/project/_api/web/lists/GetByTitle('S%20Codes')/items?$skip=5000&$top=5000

How to skip the first set of records and get the next set.

2

2 Answers

1
votes

The $skip parameter does not work in SharePoint 2013 for list items. Reference- https://sharepoint.stackexchange.com/questions/126565/issue-with-skip-in-rest-api

However, the easiest way I have found is to use SharePoint PnP.js Refer this - https://github.com/SharePoint/PnP-JS-Core

You just need to add reference to jQuery and PnP.js library files to start working with it.

Refer below code. It will skip first 1000 records and will fetch next 1000 record set:

<script type="text/javascript" src="/sites/mySiteName/SiteAssets/Javascripts/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/sites/mySiteName/SiteAssets/Javascripts/pnp.js"></script>

<script type="text/javascript">

    $(document).ready(function(){
        $pnp.sp.web.lists.getByTitle("S%20Codes").items.skip(1000).top(1000).get().then(successHandler, FailureHandler);

        function successHandler(response){
            if(response.length > 0){
                console.log(response.length); 
            }
        }

        function FailureHandler(err){
            // failure handler code
        }
    });

</script>
0
votes

Call the endpoint:

https://abc.123.org/sites/js/project/_api/web/lists/GetByTitle('S%20Codes')/items?$top=5000

Search for link rel="next", in this tag you will find a property href, something like: items?%24skiptoken=Paged%3dTRUE%26p_ID%3d2&%24top=5000. In this URL, only ID parameter will change based on the ID of the last item ID of your results.

That URL gives you the next 5000 items.