Confluence REST API Lacks DELETE Method for Attachments
Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.
Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Symptoms
Upon reviewing the Confluence REST API Documentation for Attachments, you will note that the documentation states that the /rest/api/content/{id}/child/attachment methods are for "CRUD operations for Attachments on Content". CRUD operations implies that this should cover Copy, Read, Update and Delete in order to be truly CRUD operations-complete, however, there is no method for attachment deletion on this resource as of this writing. If you try to use a DELETE command, no return will be forthcoming using the REST API.
Cause
The cause is that the DELETE command is not available and exposed on the /rest/api/content/{id}/child/attachment/{attachmentid} resource.
Workaround
In the REST API, attachments are content. You can use the DELETE command for the attachment id on the /rest/api/content/{id} resource to delete all versions of the given attachment.
Another workaround to allow programmatic deletion of attachments is to use a third-party tool, the Confluence CLI which provides methods to removeAttachment, removeAttachmentVersion and removeAttachmentVersions and is a supported Add-on for Confluence.
Resolution
This is a known issue; it has been resolved in Confluence v9.0.1 and newer: CONFSERVER-36015 - REST API Needs ability to remove specific versions of an attachment.