Sharepoint 2013 REST API not returning all items for a list

36,746

Solution 1

The limitation is due to server side paging.

A workaround is to retrieve 100 items at a time, or override the limitation by entering a count of items:

https://$DOMAIN/$SITE/_api/web/Lists/getByTitle('$LIST')/Items?$top=1000

Note that there is also a threshold at 5000.

Solution 2

You can use RowLimit & RowsPerPage in rest call. Below is the example

$.ajax({
url: siteurl + "/_api/web/lists/getbytitle('NewList')/items",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
RowLimit : null, //Specify the row limit
RowsPerPage : null, //Specify no of rows in a page
success: function (data) {
     $('#oDataFilter').append("<table>");
     $.each(data.d.results, function(index, item){
         $('#oDataFilter').append("<tr><td class="+styleClass+">" + item.ID + "</td><td class="+styleClass+">"+ item.Title + "</td></tr>");
     });
     $('#oDataFilter').append("</table>");
},
error: function (error) {
    alert('Error getListItems :: '+JSON.stringify(error));
}

Solution 3

Adding to Christophe's answer I would say listing all (potentially 5000) items in a list and parsing them would result in performance issues.

If you query sharepoint to show all items in a particular list it would only print out the first 100. But the xml response also provides the url to query for the next 100 list items.

At the very end of the xml response you will see a tag like this

<link rel="next" href="https://xxxxx.sharepoint.com/_api/web/lists/GetByTitle('list')/items?%24skiptoken=Paged%3dTRUE%26p_ID%3d100" />

The url inside href="...."is what you'll need.

Querying the above would provide you with a list of the next 100 or less items. If there are still more items left this xml response would in turn provide an other <link rel="next"> tag and if not this tag won't exist.

Better to handle 5000 items in sets of 100 rather than them all together in my opinion.

Solution 4

To anyone now seeing this, you can use data.d.__next to get the next 100 items. Using some good old recursion, you can get all the items like so

function getItems(url) {
  $.ajax({
    url: url,
    type: "GET",
    headers: {
      "accept": "application/json;odata=verbose",
    },
    success: function(data) {
      console.log(data);

      // Do work

      if (data.d.__next) {
        getItems(data.d.__next);
      }
    },
    error: function(jqxhr) {
      alert(jqxhr.responseText);
    }
  });
}

Share:
36,746
leopik
Author by

leopik

Updated on March 14, 2020

Comments

  • leopik
    leopik about 4 years

    The title states my problem quite exactly. If I try to gather all 400+ items from a list using sharepoint's REST API, I only get first 100.

    I have read http://msdn.microsoft.com/en-us/library/office/dn292552(v=office.15).aspx and in the "Working with list items by using REST" part, they're stating that

    The following example shows how to retrieve all of a list’s items.

    url: http://site url/_api/web/lists/GetByTitle(‘Test')/items

    method: GET

    headers: ...

    I have highlighted word all, because that's not what I'm getting ...

    Am I missing something? Is there some option I should disable/enable to gett truly all items?

    Thanks

  • leopik
    leopik over 9 years
    For now I don't have more records than 500 so this should do. Thanks for your help ^^!
  • leopik
    leopik over 9 years
    ... though, just out of curiosity, how would I retrieve 100 items in batches (so that I could have control over which batch number I want to get next)?
  • Christophe
    Christophe over 9 years
    it's not easy... Maybe start here msdn.microsoft.com/en-us/library/office/… then browse blogs and forums to find out what actually works
  • leopik
    leopik over 9 years
    Thanks again. I'll have a look at it.
  • vapcguy
    vapcguy about 5 years
    Totally awesome example. Tests out beautifully.
  • JoseCarlosPB
    JoseCarlosPB about 5 years
    I'm having a problem that the url is encoded and decode it doesn't work, is there a fix for that?
  • Jilo
    Jilo over 2 years
    Does this have a limitation of 5000 items aswell?