Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using $skip with the SharePoint 2013 REST API

Forgive me, I'm very new to using REST.

Currently I'm using SP2013 Odata (_api/web/lists/getbytitle('<list_name>')/items?) to get the contents of a list. The list has 199 items in it so I need to call it twice and each time ask for a different set of items. I figured I could do this by calling:

_api/web/lists/getbytitle('<list_name>')/items?$skip=100&$top=100

each time changing however many I need to skip. The problem is this only ever returns the first 100 items. Is there something I'm doing wrong or is $skip broken in the OData service?

Is there a better way to iterate through REST calls, assuming this way doesn't work or isn't practical?

I'm using the JSon protocol with the Accept Header equaling application/json;odata=verbose

I suppose the $top=100 isn't really necessary

Edit: I've looked it up more and, I'm not entirely sure of the terms here, but using $skip works fine if you're using the method introduced with SharePoint 2010, i.e., _vti_bin/ListData.svc/<list_name>?$skip=100

Actually, funny enough, the old way doesn't set a 100 item limit on returns. So skip isn't even necessary. But, if you'd like to only return a certain segment of data, you'd have to do something like:

_vti_bin/ListData.svc/<list_name>?$skip=x&$top=(x+y)

where each time through the loop you would have something like x+=y

You can either use the old method which I described above, or check out my answer below for an explanation of how to do this using SP2013 OData

like image 628
Bill Keller Avatar asked Sep 23 '13 17:09

Bill Keller


People also ask

How do I use REST API in SharePoint?

To use the REST capabilities that are built into SharePoint, you construct a RESTful HTTP request by using the OData standard, which corresponds to the client object model API you want to use. The client. svc web service handles the HTTP request and serves the appropriate response in either Atom or JSON format.

Does SharePoint support REST API?

REST API provides a flexible, lightweight way of interacting with SharePoint remotely by using any technology that supports REST protocol. With SharePoint API, you can easily perform basic Create, Read, Update, and Delete (also known as CRUD) operations.

What is the preferred URL for REST API in SharePoint?

However, using _api is the preferred convention. URLs have a 256 character limit, so using _api shortens the base URI, leaving more characters for use in constructing the rest of the URL.

Is there an API for SharePoint?

SharePoint offers a rich set of APIs that can be consumed in various ways. This article outlines what options you have, how they work and what their advantages and disadvantages are.


1 Answers

Don't forget that in order to use __next you need to have a

$skiptoken=Paged=TRUE 

in the url as well.

like image 191
Nick Avatar answered Sep 22 '22 01:09

Nick