Posts

Showing posts with the label REST API

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...

SPFx All Posts

SPFx introduction . SPFx Developer Tools Setup Evaluation of SharePoint Coding App Catalog & Work Bench Debug SPFx React webpart with Visual Studio Code SPFx with No Framework (Plain TypeScript): Create SPFx Webpart using Visual Studio code & Type script   Create SP Library as CDN (Upload SPFx webpart assets into SharePoint library) Customize SPFx webpart Properties Adding jQuery to SPFx webpart & Adding Accordion control using jQuery SPFX with React: SPFx React Basics & Life-Cycle CRUD Operations using SPFx React Webpart & Rest API (SPHttpClient) SPFX with PnPJS: PnPJS Introduction SPFx with PnPJS CRUD Operations (V3) SPFX with MS Teams: Build MS Teams Tab Using SharePoint Framework SPFX Other Important Topics: SPFx Run with elevated privileges Token type is not allowed Error While using Client Id Client Secret For more details refer this YouTube link
Solution to use Recursive call to retrieve more than 5000 items in SharePoint REST API var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('DocumentList')/items?$top=1000"; //By default REST API retrieve 100 items. By using top we can retrieve up to  5000 items     var response = response || [];  // this variable is used for storing list items     function GetListItems(){         $.ajax({             url: url,             method: "GET",             headers: {                 "Accept": "application/json; odata=verbose"             },             success: function(data){                 response = response.concat(data.d.results);           ...

SharePoint Dynamic CRUD Operations using Rest API

SharePoint Dynamic CRUD Operations using Rest API Use the below code for dynamic CRUD operations. You can create CRUD.js file using the below code & call the crud operations from different places by passing different parameters. //<<<<<<<<<<<<<<<<<<<<<<<< NOTE - Follow the below instructions to call the CURD Functions >>>>>>>>>>>>>>>>>>>>>>>>>      //-----------------createItem('ListName',['ColumnName1','ColumnName2',...],['Value1','Value2',...]);-------------          //Example: createItem('testlist',['Title','Name','Age'],['ABC','XYZ',10]);           //-----------------updateItem('ListName',itemID,['ColumnName1','ColumnName2',...],['Value1','Value2',...]);------          //Exampl...

Add content type to SharePoint List/Library using REST API

Add content type to SharePoint List/Library using REST API Use this below code to add content type to SharePoint Library using REST API. For this you need to use the content type ID. Below function will get the content type ID from content type name & we will pass the content type id to next function which will update content type to list/library. var   varContentTypeName = " Your Content Type name "; var   Listname = " Your List name where you want to add content type "; //This will get the content type ID from content type Name function  getContentTypeID() { var deferred = $.Deferred();     var  isCurrentUserIsApprover = false ; var  serverURL = _spPageContextInfo.webAbsoluteUrl; var  listURL = String.format(" {0}/_api/web/AvailableContentTypes?$select=Name,Id,StringId&$filter=Name eq '"+varContentTypeName+"' ",serverURL); $.ajax({ url: listURL, type: " GET ", async: false, headers:...