How to delete an item in a SharePoint List within a web part.

RiccardoBerla-8604 0 Reputation points
2026-01-26T14:49:01.1433333+00:00

I added an item to a list in a web part. Now I want to remove this item from that list.

Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Q&A Assist
    2026-01-26T14:49:12.2033333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    To delete an item from a SharePoint list, you can use the REST API or the SharePoint client object model. Here are examples of both methods:

    Using REST API

    You can send a POST request to delete the item:

    POST https://{site_url}/_api/web/lists/GetByTitle('YourListName')/items({item_id})
    Authorization: "Bearer " + accessToken
    Accept: "application/json;odata=verbose"
    Content-Type: "application/json"
    If-Match: "{etag or *}"
    X-HTTP-Method: "DELETE"
    

    Replace YourListName with the name of your list and {item_id} with the ID of the item you want to delete.

    Using Client Object Model (JavaScript)

    You can also delete an item using the SharePoint JavaScript library:

    var clientContext = new SP.ClientContext.get_current();
    var list = clientContext.get_web().get_lists().getByTitle('YourListName');
    var listItem = list.getItemById(itemId);
    listItem.deleteObject();
    clientContext.executeQueryAsync(
        function() { console.log('Item deleted successfully'); },
        function(sender, args) { console.log('Error: ' + args.get_message()); }
    );
    

    Make sure to replace YourListName and itemId with the appropriate values.

    These methods will allow you to remove an item from your SharePoint list effectively.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.