Soft and hard drive item delete in the Graph API

Soft delete

For a long time the Graph API supported only soft delete. The soft delete moves the items to the recycle bin instead of permanently deleting the item.

Let's say I have the file called Plan.xlsx with the id 01JI7S3EPJHM5UNWBWBFC2WJRT7K5AMPMB.

I can access the file

GET /me/drive/items/01JI7S3EPJHM5UNWBWBFC2WJRT7K5AMPMB

And move the file to the recycle bin

DELETE /me/drive/items/01JI7S3EPJHM5UNWBWBFC2WJRT7K5AMPMB

The call returns a 204 No Content response to indicate that the resource was moved to the recycle bin.

If I check the recycle bin, the file is here

Restore item

The Graph API supports restoring of the item only on OneDrive Personal (sending POST /me/drive/items/{item_id}/restore).

Access recycle bin

Unfortunately, you can't access the recycle bin with the Graph API, so there is no way to list items in the recycle bin.

Hard delete

Recently, the Graph API introduced a new feature - permanent file delete.

To permanently delete a driveItem, send the POST request

POST /me/drive/items/{drive_item_id}/permanentDelete

If you delete items using this method, they will be permanently removed and won't be sent to the recycle bin. Therefore, they cannot be restored afterward.

Conclusion

Great to see that the Graph API finally supports soft and hard delete of the drive items.

  • Soft delete - DELETE /me/drive/items/{drive_item_id}
  • Permanent delete - POST /me/drive/items/{drive_item_id}/permanentDelete
0
Buy Me a Coffee at ko-fi.com
An error has occurred. This application may no longer respond until reloaded. Reload x