Skip to content

Deleting and undeleting an Item

Quadrollopo edited this page Oct 5, 2020 · 4 revisions

Deleting

Request:

DELETE /v2/items/CODE

Not that items that contain other items cannot be deleted and there's not API endpoint for recursive deletion, you'll have to delete their content or move it elsewhere. If you try to delete them, you'll get this 400 response:

{
  "status": "fail",
  "data": {
    "*": "Cannot delete an item while contains other items"
  }
}

Response codes:
204 - Item deleted successfully
400 - Invalid code item code (this will become a 404 some day)
400 - Items contains other items
401 - User not authenticated or session expired
403 - User not authorized to delete items
404 - Item doesn't exist or already deleted

Checking if it has been deleted

Items can be only soft-deleted: that is, they are removed from the item tree and any attempt to get them will return a 404, but they still retain all their features and can be recovered.

You can check if an item has been soft deleted and thus can be recovered with

GET /v2/deleted/R420

This means it has been deleted but can be recovered:

{
  "status": "success",
  "data": "2018-11-16T23:28:01+00:00"
}

The data is the deletion time and date.

A 404 response on the other hand means that it still exists and hasn't been deleted, or it never existed, or it has been permanently deleted and cannot be recovered.

Response codes:
200 - Item has been soft-deleted and can be recovered
401 - User not authenticated or session expired
404 - Item is not in the trash can (not deleted or not existing)

Recovering items

It has been deleted but you still need it? Good, there's a way to recover it!

Do a

PUT /v2/deleted/CODE/parent

the request body must be a JSON string (delimited by "") that is the item code of the parent item where the recovered item will be placed.

That is, to place R420 into computer 94, the request will look like this:

PUT /v2/deleted/R420/parent HTTP/1.1
Host: 127.0.0.1:8080
content-type: application/json
Cookie: ...

"94"

If the operation succeeds, you'll get a 201 response with no body.

If it doesn't, you may get this kind of responses:

{
  "status": "fail",
  "data": {
    "*": "Parent item doesn't exist"
  }
}
{
  "status": "fail",
  "data": {
    "*": "Request body should be a string"
  }
}

Response codes:
201 - Item has been restored
400 - Malformed request or parent item doesn't exist
401 - User not authenticated or session expired
403 - User not authorized to move items around
404 - Item is not in the trash can (not deleted or not existing)