You can delete a SharePoint List item using REST API with Spfx in modern or Content/Script Editor in classic development with HTML and jQuery.
This post assumes you have a SharePoint list named "List1" and want to delete List Item with ID 11 (use ID to refer to the item as ID filed is always unique).
If you are connecting to the List from outside of SharePoint like Java, .Net or Python code, you need to use a Bearer token (Client ID and Client Secret) to access the REST url.
Steps to generate Client ID and Secret - Register SharePoint App
✔️ Delete SharePoint List Item using HTML, jQuery, Ajax
We will use DELETE method to delte the SharePoint record. Assumptions,List Name = List1
List Item ID = 11
var webURL = _spPageContextInfo.webAbsoluteUrl;
$.ajax({
url: webURL + "/_api/web/lists/GetByTitle('List1')/items(11)",
type: "POST",
async: false,
headers: {
"Accept": "application/json;odata=verbose",
"X-Http-Method": "DELETE",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"If-Match": "*"
},
success: function(data) {
//Perform further activity upon success, like displaying a notification
},
error: function(data) {
//Log error and perform further activity upon error/exception
}
});✔️ Delete SharePoint List Item using Postman
For testing SharePoint REST API with Postman, you need to use the Client ID, Client Secret, Tenant ID, to generate a Bearer token.Steps to generate SharePoint Bearer token - How to test SharePoint REST API from Postman
Once you have generated the access token, follow below steps
- Initiate a DELETE method request.
- Apply Header configuration parameters as below.
- Enter request url in below format
- Click Send.
- You should get a 200 OK response.
- Validate the changes form SharePoint.
| Key | Value |
| Accept | application/json;odata=verbose |
| Content-Type | application/json |
| Authorization | Bearer <<oken> |
| If-Match | * |
https://c2c.sharepoint.com/sites/SPDev/_api/web/lists/GetByTitle('List1')/items(11)
If you get a 412 Precondition Failed error with message "The request ETag value does not match the object's ETag value", add Header parameter key "If-Match" and set its value as *.
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!