Posts

Showing posts from October, 2022

SharePoint REST API: Selecting, Filtering, Sorting Results in a SharePoint List

In this post we will see samples about  $select ,  $ orderby ,  $filter  and  $expand . 1.Simple API call: {siteUrl}/ _api/web/lists/getbytitle(' ListName ')/items 2.Select Columns: {siteUrl}/ _api/web/lists/getbytitle('Employees')/items? $select=ID,Title,Employee 3.OrderBy Columns: Ascending order:  {siteUrl}/_api/web/lists/getbytitle('Employees')/items?$select=ID,Title,Employee& $orderby= Employee asc Descending order:  {siteUrl}/_api/web/lists/getbytitle('Employees')/items?$select=ID,Title,Employee& $orderby= Employee desc 4.Filtering Columns: Filtering by Title: {siteUrl}/ _api/web/lists/getbytitle('Employees')/items? $filter= Employee eq ‘parth'   Filtering by ID: {siteUrl}/ _api/web/lists/getbytitle('Employees')/items? $filter =   ID eq 2 Filtering by Date:  {siteUrl}/ _api/web/lists/getbytitle('Employees')/items? $filter= Start_x0020_Date le datetime'2016-03-26T09:59:32Z' Title name starts with the lette

SharePoint Rest API Query more than 5000 items

SharePoint REST API by default will return only 100 items Use “$top” to retrieve more than 100 items but up to 5000 only: (we cannot get more than 5000 items) . webAbsoluteUrl + "/_api/web/lists/getbytitle('myList')/items?$top=1000 Use Recursive call to retrieve more than 5000 items:      Here  data.d.__next  contains the url to get the next set of items.  In case we don’t have more items left to fetch, it will not call  GetListItems()  function. we will concatenate all json results into a variable & we can use the variable . var url = _spPageContextInfo . webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items?$top=1000" ; var response = response || []; // this variable is used for storing list items function GetListItems (){ $ . ajax ({ url : url , method : "GET" , headers : { "Accept" : "application/json; odata=verbose&quo