How to delete SharePoint Online List Item using REST API


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
  1. Initiate a DELETE method request.
  2. Apply Header configuration parameters as below.

  3. Key Value
    Accept application/json;odata=verbose
    Content-Type application/json
    Authorization Bearer <<oken>
    If-Match *

  4. Enter request url in below format
  5. https://c2c.sharepoint.com/sites/SPDev/_api/web/lists/GetByTitle('List1')/items(11)

  6. Click Send.

  7. Delete SharePoin ListItem using REST API Postman
    Delete SharePoin ListItem using REST API Postman

  8. You should get a 200 OK response.
  9. Validate the changes form SharePoint.

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



















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap