I need to delete all the Items in a Sharepoint List using REST API.
How can I achieve this?
I can delete a single Item using:
"/_api/web/lists/getByTitle('MyList')/items('ID')"
I tried to remove the ID but it did not work.
10 Answers. Show activity on this post. if you have list with more than 500 items, and you don't want to chose coding path, and don't want to delete list as well, than you go to "Manage Content and Structure" view, it allows you to view 1000 items at once and than select all delete all.
This is another way we can delete all items from a list using JavaScript object model (jsom) in SharePoint Online Office 365. The same code we can use to delete all items from SharePoint 2016 and SharePoint 2013 list. Here in the CAML query, we are passing the RowLimit as 100, you can provide as per the requirement.
You can try this
function deleteItem(url) {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + url,
type: "DELETE",
headers: {
"accept": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
"If-Match": "*"
},
success: function (data) {
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('MyList')/items",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
var items = data.d.results;
for(var item in items){
var url = "/_api/Web/Lists/getByTitle('MyList')/getItemById(item.ID)"
deleteItem(url);
}
},
error: function (error) {
alert(JSON.stringify(error));
}
});
You have to make one delete call for each item in the list, using a URI like you showed above, passing in each ID in succession. If there are LOTS of items in the list, it would likely be cheaper and faster to delete then recreate the list itself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With