Reputation: 2473
I know that I can delete a single row using this method:
DELETE https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/workbook/tables/AccountRegister/rows/$/ItemAt(index={n})
(For the benefit of others this documentation is wrong).
Is there an endpoint to delete all rows (or a range of rows)?
Upvotes: 1
Views: 2087
Reputation: 31
You can use the DataBodyRange to delete all rows.
HTTP
POST /me/drive/items/{id}/workbook/tables/{id|name}/DataBodyRange/delete
Content-type: application/json
{
"shift": "Up"
}
C#
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
await graphClient.Drives["{drive-id}"]
.Items["{driveItem-id}"]
.Workbook
.Tables["{table-id}"]
.DataBodyRange()
.Delete("Up")
.Request()
.PostAsync();
Upvotes: 3
Reputation: 13
I was struggling with the same challenge and here is the approach I am now using to do this:
Upvotes: 1
Reputation: 21
You can delete them in a batch using a POST call. Reference: https://learn.microsoft.com/en-us/graph/json-batching
Example json body to post
{
"requests": [
{
"id": "1",
"method": "DELETE",
"url": "/drives/{drive-id}/items/{item-id}/workbook/tables/AccountRegister/rows/$/ItemAt(index={0}"
},
{
"id": "2",
"method": "DELETE",
"url": "/drives/{drive-id}/items/{item-id}/workbook/tables/AccountRegister/rows/$/ItemAt(index={1}"
}
}
This would delete rows 1 and 2 of the table. Headers are excluded from the index.
FYI. There are limitations: Currently no more than 20 calls in a batch. https://learn.microsoft.com/en-us/graph/known-issues#json-batching
Upvotes: 2