How to delete an unpublished draft via Connect API?

Hello,

I am attempting to delete an unpublished page via the Connect API using the DELETE /wiki/rest/api/content/{id} endpoint. This returns the error No content found with id : 123456789 and status [current, archived].

The documentation on this endpoint is of no help; it doesn’t address content in a draft status at all. Has anyone had any luck deleting unpublished drafts via API? Thanks!

Hello @billy_p

What happens if you first change the status of the content to current or trashed, then try deleting it? As per the Delete content endpoint documentation:

Delete content

DELETE /wiki/rest/api/content/{id}. Moves a piece of content to the space’s trash or purges it from the trash, depending on the content’s type and status:

  • If the content’s type is page or blogpost and its status is current, it will be trashed.
  • If the content’s type is page or blogpost and its status is trashed, the content will be purged from the trash and deleted permanently. Note, you must also set the status query parameter to trashed in your request

Alternatively, try using the status=draft parameter via the Update content endpoint with no new content body. The old Confluence Server REST API documentation says:

If the content you’re updating has a draft, specifying status=draft will delete that draft and the body of the content will be replaced with the body specified in the request.
Request example to delete a draft:
PUT: http://localhost:9096/confluence/rest/api/content/2149384202?status=draft

Hi @sunnyape,

Thanks for the response! It appears that updating the unpublished draft’s status to trashed does the trick. I’m not 100% sure what “trashed” status means, but the page doesn’t appear in calls to GET wiki/rest/api/content?spaceKey=...&status=draft in any case. So, it doesn’t seem like a subsequence call to DELETE /wiki/rest/api/content/{id} is necessary. Thanks again.

but the page doesn’t appear in calls to GET wiki/rest/api/content?spaceKey=...&status=draft in any case

Yep, but if you did GET wiki/rest/api/content?spaceKey=...&status=trashed it would be found.

‘Trashed’ is the intermediate state before ‘Deleted’:

  • Trashed content can be recovered from the site / global trash.
  • Deleted content is gone forever and can’t be recovered.