Delete Items to List using Rest API in SharePoint Online Office 365

SharePoint 2013 delete items using rest api

Here we will discuss how we can delete items from SharePoint list using Rest API in SharePoint Online Office 365. Here we will delete list item based on list item id. Here let us take a textbox where the user can put the item id in the textbox. On submit button, the item will get deleted from the list.


All the HTML code and Rest API code we will put inside a script editor web part inside a SharePoint web part page.

Here we have a list name as MyCompanyInfo which has one item and whose ID is 2.

Delete Items to List using Rest API in SharePoint Online Office 365
Delete Items to List using Rest API in SharePoint Online Office 365

Also you can read:
Add Content Type to List using Rest API in SharePoint Online Office 365

Microsoft Flow Example Save tweets that include specific hashtag to a SharePoint list

Display SharePoint list item using AngularJS REST API SharePoint online

HTML Code:

<div>

Enter ID to Delete:

<input type=”text” id=”txtId” />

</div>

<div>

<input id=”btnSubmit” type=”button” value=”Submit” />

</div>

<div id=”divResult”></div>

Rest API Code:
Here we have retrived the item id from the textbox.

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js”></script>

<script>

$(function () {

bindButtonClick();

});

function bindButtonClick() {

$(“#btnSubmit”).on(“click”, function () {

deleteListItem();

});

}

function deleteListItem() {

var id = $(“#txtId”).val();

var siteUrl = _spPageContextInfo.webAbsoluteUrl;

var fullUrl = siteUrl + “/_api/web/lists/GetByTitle(‘MyCompanyInfo’)/items(” + id + “)”;

$.ajax({

url: fullUrl,

type: “POST”,

headers: {

“accept”: “application/json;odata=verbose”,

“content-type”: “application/json;odata=verbose”,

“X-RequestDigest”: $(“#__REQUESTDIGEST”).val(),

“X-HTTP-Method”: “DELETE”,

“IF-MATCH”: “*”

},

success: onQuerySucceeded,

error: onQueryFailed

});

}

function onQuerySucceeded(sender, args) {

$(“#divResult”).html(“Item successfully deleted!”);

}

function onQueryFailed() {

alert(‘Error!’);

}

</script>

Once you Save the page, it will display like below. Once user put the item id and click on Submit button it will delete the list item and it will display the successful message.

Delete Items to List using Rest API in SharePoint Online
Delete Items to List using Rest API in SharePoint Online

Now if you will check the list, you will not find the item inside the list like below:

SharePoint 2013 delete items using rest api
SharePoint 2013 delete items using rest api

Here we have discussed how we can delete list item by id using Rest API in SharePoint Online Office 365.



Hope this will be helpful.

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →