looking for SharePoint REST API end point to get list view items

462 Views Asked by At

we are trying to get SP list view items, means whatever the fields that are enabled in that specific view, those fields(columns) and items. so what SP REST API end point is helpful ex:...

to get SP lists: _api/web/lists

to get SP list view: _api/web/getlistbytitle('sampleList')/views

etc... we need SP list view items Please assist me on how to get list view items.

1

There are 1 best solutions below

0
Rob Windsor On

You need to get the ViewQuery for the view and use it to execute a CAML query on the list.

This post on SharePoint StackExchange has details: How to get all items in a view using REST API.

Here's the relevant code snippet from that post:

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(
         function(data){         
             var viewQuery = data.d.ViewQuery;
             return getListItems(webUrl,listTitle,viewQuery); 
         });
}