Monday 7 December 2015

SharePoint Hosted App:- post data to External Webservice

This blog will explain how to post data to an external web-service from SharePoint Online(Office 365) site using SharePoint Hosted Apps.

Here I am gonna use Napa tool to create SharePoint Hosted Apps.
Brief introduction on NAPA tools- it is a browser enabled light weighted tool introduced in SharePoint 2013 to create SharePoint Hosted Apps. Reason why i said it is light weighted because this itself is an App which can be added to site and can be used to create an App.
In my site I have already added NAPA tools and it can be seen under Site Contents

Just click on NAPA which will redirect you to the similar screen like below to create an APP.

give a meaningful name(here I had given- CallExternalWebService) and click on Create. 
Once it is created you will see the entire project structure like below



Now open App.js and replace the code with the below code.

//start app.js snippet  
 'use strict';  
 var context = SP.ClientContext.get_current();  
 var user = context.get_web().get_currentUser();  
 (function () {  
   // This code runs when the DOM is ready and creates a context object which is  
   // needed to use the SharePoint object model  
   $(document).ready(function () {  
     getUserName();  
     CallExternalWebServiceDemo();  
   });  
   // This function prepares, loads, and then executes a SharePoint query to get  
   // the current users information  
   function getUserName() {  
     context.load(user);  
     context.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);  
   }  
   // This function is executed if the above call is successful  
   // It replaces the contents of the 'message' element with the user name  
   function onGetUserNameSuccess() {  
     $('#message').text('Hello ' + user.get_title());  
   }  
   // This function is executed if the above call fails  
   function onGetUserNameFail(sender, args) {  
     alert('Failed to get user name. Error:' + args.get_message());  
   }  
   function CallExternalWebServiceDemo() {  
     //url of the webservice  
     var webserviceURL = "http://xyz.com/api/postsomething";  
     $.ajax({  
       url: "../_api/SP.WebProxy.invoke",  
       type: "POST",  
       data: JSON.stringify(  
         {  
           "requestInfo": {  
             "__metadata": { "type": "SP.WebRequestInfo" },  
             "Url": webserviceURL,  
             "Method": "POST",  
             "Headers": {  
               "results": [{  
                 "__metadata": { "type": "SP.KeyValue" },  
                 "Key": "Accept",  
                 "Value": "application/json",  
                 "ValueType": "Edm.String"  
               }, {  
                 "__metadata": { "type": "SP.KeyValue" },  
                 "Key": "Content-Type",  
                 "Value": "application/json",  
                 "ValueType": "Edm.String"  
               }]  
             },  
             "Body": "in json format"  
           }  
         }),  
       headers: {  
         "Accept": "application/json;odata=verbose",  
         "Content-Type": "application/json;odata=verbose",  
         "X-RequestDigest": $("#__REQUESTDIGEST").val()  
       },  
       success: function (data) {  
         alert("Sucess");  
       },  
       error: function (jqxr, errorCode, errorThrown) {  
         alert(jqxr.responseText);  
       }  
     });  
   }  
 })();  
 ////end app.js snippet

Now open settings by clicking on it as shown below


clicking on setting will open screen as shown below

now add your end point and click on apply/
If you are creating SharePoint Hosted App using Visual Studio then "Remote Endpoints" are available in AppManifest.xml.

Now run the app which will automatically deploy and will add it in your site.

Thanks.

Thursday 3 December 2015

Read current user profile properties from UserProfileService using REST API

This blog will showcase how to read current user(Logged In User) profile properties using Rest API in SharePoint.

var uspURL= _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties";  
     $.ajax({  
       url: uspURL,  
       method: "GET",  
       headers: {  
         "Accept": "application/json; odata=verbose",  
         "content-type": "application/json; odata=verbose"  
       },  
       success: function (data) {  
         var userProfileDetails = data;  
         var propertyKey="XYZ";  
         var PropertyValuePair = $.grep(userProfileDetails.d.UserProfileProperties.results, function (v) {  
           return v.Key === propertyKey;  
         });  
         var propertyValue = PropertyValuePair[0].Value  
       },  
       error: function (jqxr, errorCode, errorThrown) {  
         alert(jqxr.responseText);  
       }  
     });  

_spPageContextInfo SharePoint developer's best friend

_spPageContextInfo is always used by me whenever I am writing any SharePoint Client Site Code. It has a very useful properties which i will put it down in tabular format for better understanding and hence i call it as a SharePoint Developer's best friend.




Working with page layouts in SharePoint 2013

Design Manager:- my friend in SharePoint 2013 to work with Page Layouts and Master Page.
Certain new and interesting stuffs are introduced in SharePoint 2013 to work with page layouts using Design Manager.

First thing on which we should focus is that now every page layout will have two component i.e. first .aspx which is used by SharePoint and second is .html which is used to edit the pagelayout in any html designer. Basically this concept was introduced for the ease of designing.

Lets start with creating new page layout. Every page layout is associated with some Page content type and hence I have a habit of creating my own content type while creating new page layouts for several reasons like ease of searching, modification etc.
Here I have created new content type from Article Page content type which is inherited from Page Layout Content Type.

First goto DesignManager which is available in Publishing Site.


Clicking on publishing site will navigate to the below page.

Here we can create our own page layout. Creating new page layout will ask for layout name, master page and which content type to be used.


Now it’s time to customize the Page layout. Download the page layout into your filesystem and start playing with it. Downloading from DesignManager will download the HTML file.
In HTML we can see two important divs which are mentioned below:-
1) <div data-name="EditModePanelShowInEdit">:- Content of this div is visible only when it is Edit Mode.
2)  <div data-name="EditModePanelShowInRead">:- Content of this div is visible only when it is Read Mode. In short this is the div where actually end user will be interacting.

In my case end user will only read news and will be able to navigate to the archived contents.
Hence in ShowInRead I have created the blank skeleton i.e the approved UI for end user. Rest everything I did it using javascript and jquery.
Reference of javascript files has to given in "PlaceHolderAdditionalPageHead".

Wednesday 2 December 2015

Read selected Metadata tagging across SharePoint SiteCollection

Couple of months back I was asked to generate the report of one Metadata Field present in SharePoint Online site i.e where and all that column is used along with the tagged value, item url, list name and blah blah blah..
Initially I thought of using SharePoint Search API but due to following drawbacks i stepped back:-

  • If any List or Library are selected not display records in search, then i wont be able to get it
  • Item level permission.
Hence i decided to write a CSOM code, as report has to be submitted in couple of hours. Code is quite simple and easy to understand, it would have become reusable if I would have made it recursive. But in may case it was not required as there wasn't any sub site under any site ;)


static void Main(string[] args)  
     {  
       Console.WriteLine("Enter Online Site URL");  
       string siteUrl = Console.ReadLine();  
       Console.WriteLine("Enter User Name");  
       string userName = Console.ReadLine();  
       Console.WriteLine("Enter Password");  
       string password = Console.ReadLine();  
       Console.WriteLine("Enter Metadata Column's Internal Name");  
       string column = Console.ReadLine();  
       SecureString securePass = new SecureString();  
       foreach (char c in password)  
       {  
         securePass.AppendChar(c);  
       }  
       StringBuilder strBldr = new StringBuilder();  
       strBldr.AppendLine("SiteName,ItemUrl,Tags");  
       using (ClientContext ctx = new ClientContext(siteUrl))  
       {  
         ctx.Credentials = new SharePointOnlineCredentials(userName,  
           securePass);  
         Web oweb = ctx.Site.RootWeb;  
         ctx.Load(oweb);  
         ctx.Load(oweb.Webs);  
         ctx.Load(oweb.Lists);  
         ctx.ExecuteQuery();  
         #region Read root level lists  
         //This can be made recursive also  
         foreach (List olist in oweb.Lists)  
         {  
           ctx.Load(olist);  
           ctx.Load(olist, l => l.DefaultViewUrl);  
           if (olist.ContainsField(column))  
           {  
             ListItemCollection ocoll = olist.GetItems(CamlQuery.CreateAllItemsQuery());  
             ctx.Load(ocoll);  
             ctx.ExecuteQuery();  
             foreach (ListItem oitem in ocoll)  
             {  
               TaxonomyFieldValueCollection taxFieldValueColl = oitem[column] as TaxonomyFieldValueCollection;  
               string tags = string.Empty;  
               // Loop through all the taxonomy field values  
               foreach (TaxonomyFieldValue taxFieldValue in taxFieldValueColl)  
               {  
                 // Display the taxonomy field value  
                 Console.WriteLine(taxFieldValue.Label);  
                 tags += RemoveComma(taxFieldValue.Label, "-") + ";";  
               }  
               if (!string.IsNullOrEmpty(tags))  
               {  
                 strBldr.AppendLine(RemoveComma(oweb.Title, "-") +  
                   "," + RemoveComma(Convert.ToString(oitem.FieldValues["FileRef"]), "%2C") + "," + tags);  
               }  
             }  
             Console.WriteLine("Site Title - " + oweb.Title + ", List Title - " + olist.Title + " Item Count - " + olist.ItemCount);  
           }  
         }  
         #endregion  
         Console.WriteLine("Root Web Title - " + oweb.Title);  
         //read each site and list  
         foreach (Web web in oweb.Webs)  
         {  
           ctx.Load(web);  
           ctx.Load(web.Lists);  
           ctx.ExecuteQuery();  
           foreach (List lis in web.Lists)  
           {  
             ctx.Load(lis);  
             ctx.Load(lis, k => k.DefaultViewUrl);  
             if (lis.ContainsField(column))  
             {  
               Console.WriteLine("Site Title " + web.Title + ", List Title - " + lis.Title + " Item Count - " + lis.ItemCount);  
               ListItemCollection ocoll = lis.GetItems(CamlQuery.CreateAllItemsQuery());  
               ctx.Load(ocoll);  
               ctx.ExecuteQuery();  
               foreach (ListItem oitem in ocoll)  
               {  
                 TaxonomyFieldValueCollection taxFieldValueColl = oitem[column] as TaxonomyFieldValueCollection;  
                 string tags = string.Empty;  
                 // Loop through all the taxonomy field values  
                 foreach (TaxonomyFieldValue taxFieldValue in taxFieldValueColl)  
                 {  
                   // Display the taxonomy field value  
                   Console.WriteLine(taxFieldValue.Label);  
                   tags += RemoveComma(taxFieldValue.Label, "-") + ";";  
                 }  
                 if (!string.IsNullOrEmpty(tags))  
                 {  
                   strBldr.AppendLine(RemoveComma(web.Title, "-") +  
                     "," + RemoveComma(Convert.ToString(oitem.FieldValues["FileRef"]), "%2C") + "," + tags);  
                 }  
               }  
             }  
           }  
         }  
         System.IO.File.WriteAllText(@"D:\" + column + ".csv", strBldr.ToString());  
       }  
     }  
     /// <summary>  
     /// This method will replace comma in the given string with given charcter  
     /// </summary>  
     /// <param name="inputValue"></param>  
     /// <param name="replace"></param>  
     /// <returns></returns>  
     private static string RemoveComma(string inputValue, string replace)  
     {  
       string tempInputValue = inputValue.Replace(",", replace);  
       return tempInputValue;  
     } 

Tuesday 17 November 2015

Create folder in SharePoint List using JSOM

There is always a need to create folder in SharePoint list using client side script and hence I thought of posting the code.
Below code will create folder in SharePoint List using JSOM and function will be fired from SharePoint Hosted Apps and hence this will cover how to get AppContext and how to create folder.



 function AddFolderToSPList(folderName) {  
     var oWebsite;  
     var oList, oListItem;  
     var itemCreateInfo;  
     var clientContext = new SP.ClientContext('appWebUrl');  
     var appContextSite = new SP.AppContextSite(clientContext, 'targetSiteUrl');  
     oWebsite = appContextSite.get_web();  
     oList = oWebsite.get_lists().getByTitle('ListName');  
     itemCreateInfo = new SP.ListItemCreationInformation();  
     itemCreateInfo.set_underlyingObjectType(SP.FileSystemObjectType.folder);  
     itemCreateInfo.set_folderUrl(targetSiteUrl + "/Lists/" + "ListName");  
     //if you want to add subfolder then add folder url like below commented line  
     //itemCreateInfo.set_folderUrl(targetSiteUrl + "/Lists/" + "ListName"+"/parentfolder");  
     oListItem = oList.addItem(itemCreateInfo);  
     oListItem.set_item('Title', folderName);  
     oListItem.update();  
     clientContext.load(oListItem);  
     clientContext.executeQueryAsync(  
       Function.createDelegate(this, successHandler()),  
       Function.createDelegate(this, errorHandler)  
     );  
   }  
   function successHandler() {  
     alert('success');  
   }  
   function errorHandler() {  
     alert("Request failed: message = " + arguments[1].get_message());  
   }  

Saturday 7 November 2015

SharePoint People Picker using “clientpeoplepicker.js” or client side scripting


 <script src="/_layouts/15/SP.RequestExecutor.js"></script>  
 <script src="/_layouts/15/clienttemplates.js"></script>  
 <script src="/_layouts/15/clientforms.js"></script>  
 <script src="/_layouts/15/clientpeoplepicker.js"></script>  
 <script src="/_layouts/15/autofill.js"></script>  
 <script src="/_layouts/15/js"></script>  
 <script src="/_layouts/15/runtime.js"></script>  
 <script src="/_layouts/15/sp.core.js"></script>  
 <script type="text/javascript">  
   $(document).ready(function () {  
     // Specify the unique ID of the DOM element where the  
     // picker will render.  
     initializePeoplePicker('peoplePickerDiv');  
   });  
   // Render and initialize the client-side People Picker.  
   function initializePeoplePicker(peoplePickerElementId) {  
     // Create a schema to store picker properties, and set the properties.  
     var schema = {};  
     schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';  
     schema['SearchPrincipalSource'] = 15;  
     schema['ResolvePrincipalSource'] = 15;  
     schema['AllowMultipleValues'] = false;  
     schema['MaximumEntitySuggestions'] = 50;  
     schema['Width'] = '280px';  
     // Render and initialize the picker.  
     // Pass the ID of the DOM element that contains the picker, an array of initial  
     // PickerEntity objects to set the picker value, and a schema that defines  
     // picker properties.  
     this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);  
     alert('init end')  
   }  
   // Query the picker for user information.  
   function getUserInfo() {  
     // Get the people picker object from the page.  
     var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.peoplePickerDiv_TopSpan;  
     // Get information about all users.  
     var users = peoplePicker.GetAllUserInfo();  
     var userInfo = '';  
     for (var i = 0; i < users.length; i++) {  
       var user = users[i];  
       for (var userProperty in user) {  
         userInfo += userProperty + ': ' + user[userProperty] + '<br>';  
       }  
     }  
     $('#resolvedUsers').html(userInfo);  
     // Get user keys.  
     var keys = peoplePicker.GetAllUserKeys();  
     $('#userKeys').html(keys);  
     // Get the first user's ID by using the login name.  
     getUserId(users[0].Key);  
   }  
   // Get the user ID.  
   function getUserId(loginName) {  
     var context = new SP.ClientContext.get_current();  
     this.user = context.get_web().ensureUser(loginName);  
     context.load(this.user);  
     context.executeQueryAsync(  
        Function.createDelegate(null, ensureUserSuccess),  
        Function.createDelegate(null, onFail)  
     );  
   }  
   function ensureUserSuccess() {  
     $('#userId').html(this.user.get_id());  
   }  
   function onFail(sender, args) {  
     alert('Query failed. Error: ' + args.get_message());  
   }  
 </script>  
 <div id="peoplePickerDiv"></div>  
 <div>  
   <br />  
   <input type="button" value="Get User Info" onclick="getUserInfo()" />  
   <br />  
   <h1>User info:</h1>  
   <p id="resolvedUsers"></p>  
   <h1>User keys:</h1>  
   <p id="userKeys"></p>  
   <h1>User ID:</h1>  
   <p id="userId"></p>  
 </div>  

Create Dynamic Array from SharePoint List Items to Draw Google Pie Chart

This blog will focus on how to create dynamic array which can easily understood by google chart 's api.
This one I did for one of project approximate 17-18 months back but now I am posting this ;)
Requirement was to show the PIE Chart of the clients data based on their status. For this we need to have Status Column and of type Choice which may hold the value like “Completed, In Progress, Completed” or Whatever status we want.
Then this site Column will be added to the actual list where the content will reside and based.
So let’s start with the actual coding for which I am always excited. Below file can be a .txt file or html file and later on will be added to content editor webpart to display the pie chart.


 <script type="text/javascript" src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization',  
     'version':'1','packages':['corechart']}]}"></script>  
 <style>  
   table th {  
     background-color: #73d1f2;  
     height: 34px;  
     text-align: left;  
     padding-left: 2%;  
     font: bold 13px Arial, Helvetica, sans-serif !important;  
     color: #777 !important;  
   }  
   .ms-listviewtable a:hover {  
     color: #777 !important;  
   }  
 </style>  
 <script type="text/javascript">  
   var siteUrl;  
   var arrBarChart = new Array();  
   $(document).ready(function () {  
     siteUrl = _spPageContextInfo.webAbsoluteUrl;  
     GetStatusColumn();  
   });  
   /// This method will read the Status Site Column  
   function GetStatusColumn() {  
     $.ajax({  
       url: siteUrl + "/_api/web/fields?$filter=Title eq'StatusColumnName'",  
       method: "GET",  
       headers: {  
         "Accept": "application/json; odata=verbose",  
         "content-type": "application/json; odata=verbose"  
       },  
       success: function (data) {  
         /// here i am checking whether it has some data or not  
         if (data.d.results[0].Choices.results.length > 0) {  
           // here i will pass siteurl and values from the site column  
           GetListHoldingDate(siteUrl, data.d.results[0].Choices.results);  
         }  
         else {  
           $("#lblError").text("Status Site Column do not exists or do not have values in it, please contact Administrator");  
         }  
       },  
       error: function (jqxr, errorCode, errorThrown) {  
       }  
     });  
   }  
   // this method will read the actual list content and will array required for pie chart  
   function GetListHoldingDate(siteUrl, columnData) {  
     var uspURL = siteUrl + "/_api/web/lists/getbytitle('ListHoldingData')/items"  
     $.ajax({  
       url: uspURL,  
       method: "GET",  
       headers: {  
         "Accept": "application/json; odata=verbose",  
         "content-type": "application/json; odata=verbose"  
       },  
       success: function (data) {  
         //alert(data.body);  
         var rowsStatus = "";  
         var itemCount = data.d.results.length;  
         for (var i = 0; i < columnData.length; i++) {  
           //below code will filter the data from all items based on status  
           var arr = $.grep(data.d.results, function (a) {  
             return a.StatusColumnName == columnData[i];  
           })  
           var perc = (arr.length / itemCount) * 100;  
           perc = Math.round(perc * 100) / 100  
           arrBarChart.push([columnData[i], parseInt(perc)]);  
         }  
         drawChart();  
       },  
       error: function (jqxr, errorCode, errorThrown) {  
         if (jqxr.status == "404") {  
           $("#lblError").text("List holding content not found, Please contact administrator");  
         }  
         else {  
           $("#lblError").text(jqxr.responseText);  
         }  
       }  
     });  
   }  
   //this method will create pie chart using google api  
   function drawChart() {  
     var data = new google.visualization.DataTable();  
     data.addColumn('string', 'Status');  
     data.addColumn('number', 'Percentage');  
     data.addRows(arrBarChart);  
     // Set chart options  
     var options = {  
       'title': 'Status',  
       'width': 300,  
       'height': 300  
     };  
     // Instantiate and draw our chart, passing in some options.  
     var chart = new google.visualization.PieChart(document.getElementById('chart_div'));  
     chart.draw(data, options);  
   }  
 </script>  
 <table style="width: 100%!important">  
   <tr>  
     <td style="vertical-align: top">  
       <div id="chart_div"></div>  
     </td>  
   </tr>  
 </table>  
 <br />  
 <label id="lblError" style="color: red; font-weight: bold; font-size: small"></label>  

Friday 6 November 2015

SharePoint 2013 Crud Operations using REST API

Perform Crud Operations in SharePoint 2013 using REST API.
REST API - I must say one should really use it when it comes on performance factor in SharePoint 2013. This technology is really light-weighed and off-course easy to use. Every technology has its own merits and demerits and hence it is our/developers choice based on requirement/condition what to use and when to use.
If someone asks when we should use REST API, I will say use REST to perform all most every read operations. We can do Insert, Update and Delete Operations but one I have encountered an issue which i will write it in another blog.

here are some examples on REST API Crud Operations.

Below operations are done by me approximate 15 months back and its a humble request to readers to update me if some new methods or best approaches are available other than this.

1)     Read/Get:-


var uspURL = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items";  
 $.ajax({  
   url: uspURL,  
   type: "GET",  
   contentType: "application/json;odata=verbose",  
   headers: {  
     "Accept": "application/json;odata=verbose"  
   },  
   success: function (data) {  
     var oresults = data.d.results;  
   },  
   error: function (jqxr, errorCode, errorThrown) {  
     alert(jqxr.responseText);  
   }  
 });  

Some of the useful tips for get are mentioned below.
Description
URL
To filter Title column
spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items?$filter=Title eq’XYZ’";
To get Item by ItemID. In this case I assume that ItemID is ‘1’
spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items(1)";
or
spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items?$filter=ID eq’1’";
To filter on multiple column
spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items?$filter=(([Title] eq 'ABC') and ([SubTitle] eq 'XYZ'))";
To read site columns. Here Site column name is SiteColumn1
spPageContextInfo.webAbsoluteUrl + "_api/web/fields?$filter=Title eq'SiteColumn1'";
To filter Date Column. Here date column is CreatedDate and operator used is greaterthan
spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items?$filter=CreatedDate ge datetime'2014-01-01T00:00:00Z'";


2)     Insert/Add List Items:-
This insert operation will also add special field value like DateTime Field, Choice Column and HyperLink Column.


  var itemType = "SP.Data.ListNameListItem";  
   var arrChoiceColumn = [];  
   arrChoiceColumn.push('Choice1');  
   arrChoiceColumn.push('Choice2');  
   var vardata = {  
     '__metadata': { 'type': itemType },  
     'Title': 'TestTitle', 'ChoiceColumName': {  
       "__metadata": { "type": "Collection(Edm.String)" },  
       "results": arrChoiceColumn  
     },  
     'DateColumnName': new Date().toISOString(),  
     'HyperLinkColumnName': {  
       '__metadata': { 'type': 'SP.FieldUrlValue' },  
       'Description': 'Azam Khan', 'Url': 'http://khanaazam.blogspot.ae/'  
     }  
   };  
   var uspURL = webURL + "/_api/web/lists/getbytitle('ListName')/items";  
   $.ajax({  
     url: uspURL, type: "POST",  
     contentType: "application/json;odata=verbose",  
     data: JSON.stringify(vardata),  
     headers: {  
       "Accept": "application/json;odata=verbose",  
       "X-RequestDigest": $("#__REQUESTDIGEST").val()  
     }, success: function (data) {  
       // here add alert message        
     },  
     error: function (jqxr, errorCode, errorThrown) {  
       alert(jqxr.responseText);  
     }  
   });  


3)     Update List Items:-
     While updating any records using REST in SharePoint 2013 it is same as Add Operation with some changes which are mentioned below:-
a)     Since we are updating list item it is basic that first we need to get that item so for that I will use get Item By Id method and hence the URL will be


var url = spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items(1)";

b)     Second change will be in header of Ajax Call


headers:  
   {  
     "Accept": "application/json;odata=verbose",  
     "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
     "X-HTTP-Method": "MERGE","If-Match": "*"    
   }  

c)     In Data we will pass the Column Name along with their value the way how we have passed in the Add Operation.


3)     Delete List Items:-
     For Delete operation we can use the everything similar to Update Query with the only difference in headers


headers:  
   {  
     "Accept": "application/json; odata=verbose",  
     "content-type": "application/json; odata=verbose",  
     "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
     "IF-MATCH": "*","X-HTTP-Method": "DELETE"  
   }