5

I have an array with multiple SP list-item URLs. I want to get all data from every list-item . I solved the problem with a loop that does a Rest API Request for every single URL. I don't like this solution, because it is really slow to do a request for every item. Is it possible to get this done with a single Rest API request to get a better performance?

  • 1
    why you are not just sending that whole array of list Url to server side instead of for loop for every item in an array and get items from the lists in an array from the backside.in this way, you can get all items in one shot! – Ekta Dobaria May 2 '17 at 13:11
3

What @Ekta said:

Just get all the items, then in javascript you can parse out the array by id. Let's say you had an array of all the listitem ids named itemidarray such as

var itemidarray = [1, 5, 10, 4, 29, 40];

$.ajax({
    url: url + "/_api/web/lists/getbytitle('" + listname + "')/items",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: function (data) {
        if(itemidarray.indexOf(data.d.results.Id) > -1){
            //do something with the item
        }
    },
    error: function (data) {
        alert(data);
    }
});

This is pseudocode, so I haven't tested the syntax of it.

  • this does only work if all items are within the same List, right ? – ElBiasto May 3 '17 at 6:54
  • correct. If you wanted multiple items from multiple lists, you may have to look into CSOM batching. – Mike May 3 '17 at 22:20
3

There are 2 different approaches to read items from List using REST API

  1. If you are reading items from single list with different conditions matches your results then use filter operation as shown in below example

    $filter=(Id eq 1) or startsWith(Title,'abc') or (Department eq 'XYZ')

  2. If you want to read items from multiple lists or in any scenario to read items from single lists then you can also use batch operation. You can refer the sample below link https://msdn.microsoft.com/en-us/library/office/dn903506.aspx

1

Combining filters: $filter=((ZIP eq 12345) or (ZIP eq 22222))
you can make huge strings of combined filters I experienced

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.