by using rest api

I get items like this


I get the view like this and naturally in it I have the GUID


Now how can I get all items under this certain view

3 Answers 3


Using REST you can't get items from a view. For that you have two options

  1. Get the view fields and form a query
  2. Create a CAML query and use it to get the items.



The following example demonstrates how to retrieve list items for a View using SharePoint REST:

function getListItems(webUrl,listTitle, queryText) 
    var viewXml = '<View><Query>' + queryText + '</Query></View>';
    var url = webUrl + "/_api/web/lists/getbytitle('" + listTitle + "')/getitems"; 
    var queryPayload = {  
               'query' : {
                      '__metadata': { 'type': 'SP.CamlQuery' }, 
                      'ViewXml' : viewXml  
    return executeJson(url,"POST",null,queryPayload);

function getListViewItems(webUrl,listTitle,viewTitle)
     var url = webUrl + "/_api/web/lists/getByTitle('" + listTitle + "')/Views/getbytitle('" + viewTitle + "')/ViewQuery";
     return executeJson(url).then(
             var viewQuery = data.d.ViewQuery;
             return getListItems(webUrl,listTitle,viewQuery); 


function executeJson(url,method,headers,payload) 
    method = method || 'GET';
    headers = headers || {};
    headers["Accept"] = "application/json;odata=verbose";
    if(method == "POST") {
        headers["X-RequestDigest"] = $("#__REQUESTDIGEST").val();
    var ajaxOptions = 
       url: url,   
       type: method,  
       contentType: "application/json;odata=verbose",
       headers: headers
    if (typeof payload != 'undefined') {
      ajaxOptions.data = JSON.stringify(payload);
    return $.ajax(ajaxOptions);


getListViewItems(_spPageContextInfo.webAbsoluteUrl,'Tasks','All Tasks')
     var items = data.d.results;
     for(var i = 0; i < items.length;i++) {
  • 5
    Thax Vadim Gremyachev, your code is solid :)
    – user44680
    Commented Jul 30, 2015 at 7:39
  • 1
    Really nice code! I'm using it to format some view data with D3. thanks, Stephan Onisick
    – user10711
    Commented Mar 30, 2017 at 15:08
  • @Vadim, but in this you are explicitly writing column name as items[i].Title. But is it possible to only get selected fields in that view?
    – Mihir
    Commented Jul 23, 2018 at 17:21
  • 1
    Hello Vadim, I am getting 403 forbidden error for above code? Is there any solution for that?
    – P S
    Commented May 31, 2019 at 8:51

I usually use this approach when querying a list:

_api/web/lists(guid'D38E6516-FB4F-4FCF-9E29-4FEC9CE06D2B')/GetItems(query=@v1)?@v1={"ViewXml":"<View><Query><Where><Eq><FieldRef Name='Your field here'><Value Type='The field type'>The value you want to look for</Value></Eq></Where></Query><ViewFields><FieldRef Name='Id' /></ViewFields></View>"}

The guid being the guid of the list (This saves you some headache if the list name ever changes).

This needs to be called as a POST call, not a GET call (Like your normal browser request).

Also when constructing the CAML part you can help yourself a lot by using a CAML builder like U2U or similar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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