-1

How can we get data from multiple list by using sharepoint REST API in one call . I: want to get data and also want to use multiple list for searching data too. Is it possible to do this in one call if "YES" then how and if "NO" then what are the best solutions for getting data??

Thanks in advance..

3 Answers3

1

First of all, SharePoint REST does not support request batching like CSOM does. That makes it impossible to make multiple REST calls in a single round trip to the service.

The good news that according to Office 365 business roadmap the feature:

CSOM Batching for Apps for SharePoint

This feature allows support for $batch requests in SharePoint's OData REST services. This allows apps to make multiple REST calls in a single round trip to the service.

is already in Development state. Hurray! Thanks to the Office Developer Platform UserVoice for that and specifically to Andrew Connell for creating a feature request


From another hand, Search Query API could be used for querying multiple lists, for example the following search query:

contentclass:STS_ListItem AND ContentType:Task

will return all Task items.

JavaScript Example

The following example demonstrates how to utilize Search API using REST endpoint:

function searchTaskItems(webUrl,success, failure) {
    var url = webUrl + "/_api/search/query?querytext='contentclass:STS_ListItem AND ContentType:Task'";
    $.ajax({
        url: url,
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            success(data.d.query);
        },
        error: function (data) {
            failure(data);
        }
    });
}


//print tasks
searchTaskItems(_spPageContextInfo.webAbsoluteUrl,
  function(query){
      var resultsCount = query.PrimaryQueryResult.RelevantResults.RowCount;
      for(var i = 0; i < resultsCount;i++) {
          var row = query.PrimaryQueryResult.RelevantResults.Table.Rows.results[i];
          var taskName = row.Cells.results[3].Value;
          console.log(taskName);
      }   
  },
  function(error){
    console.log(JSON.stringify(error));
  }
);
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
0

no, you will need multiple REST calls to achieve that. You can use CSOM as well, to decrease number of round trips to the server. You can load your entire query client side and only execute one query to the server to join all the lists.

Boland
  • 1,531
  • 1
  • 14
  • 42
0

You can retrive data from multiple list using REST. All you could is to retrieve data from multiple list if there's any Lookup column that will link data between/among the lists. In such scenario, you will need to use the $expand clause. Search in google for expand sharepoint Rest call, that may work for you.

Alberto S.
  • 1,805
  • 23
  • 39