SharePoint REST API – for lists.getAll Items() limited to 100 rows

The limit is due to server-driven paging. It protects against developers inadvertently making a request that returns large result sets.

You can use $top if you really want a large result set to be returned.

This can be worked out using below

/_api/web/lists/GetByTitle('ListName')/items?$top=1000

But the above is useful when you just want the counts from a list.

Lets take a scenario where you would want to iterate through the results without putting burden on the list service by checking __next. If it has a value, it contains the address that will return the next set of items. If it’s null, you’ve hit the end of the result set. Now based on that your function should be modified as Recursive function.

function callToHostWeb() {
    var message = jQuery("#message");
    message.text("");

    var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
    var appUrl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));

    var scriptbase = hostUrl + "/_layouts/15/";
    var url = appUrl + "/_api/SP.AppContextSite(@target)/Web/Lists/getByTitle('Order Details')/Items?$select=Title&@target='" + hostUrl + "'";
    jQuery.getScript(scriptbase + "SP.RequestExecutor.js", getOrderDetails);

    function getOrderDetails() {
        var executor = new SP.RequestExecutor(appUrl);
        executor.executeAsync(
            {
                url: url,
                method: "GET",
                dataType: "json",
                headers: {
                    Accept: "application/json;odata=verbose"
                },
                success: function (data) {
                    var response = JSON.parse(data.body);
                    message.append(String.format("Retrieved {0} items", response.d.results.length));
                    message.append("<br/>");

                    if (response.d.__next) {
                        url = response.d.__next;
                        getOrderDetails();
                    }
                },
                error: function (data, errorCode, errorMessage) {
                    alert(errorMessage);
                }
            }
        );
    }

    function getQueryStringParameter(paramToRetrieve) {
        var params =
            document.URL.split("?")[1].split("&");
        var strParams = "";
        for (var i = 0; i < params.length; i = i + 1) {
            var singleParam = params[i].split("=");
            if (singleParam[0] == paramToRetrieve)
                return singleParam[1];
        }
    }
}

Thanks to below article

https://sharepoint.stackexchange.com/questions/74777/list-api-get-all-items-limited-to-100-rows/75124

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s