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?
3 Answers
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.
There are 2 different approaches to read items from List using REST API
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')
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
Combining filters: $filter=((ZIP eq 12345) or (ZIP eq 22222))
you can make huge strings of combined filters I experienced