How to delete the current version o page from a Confluence using the REST API
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
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
Summary
Using the REST API might be helpful to automate some operations on Confluence.
A Confluence user or the administrator may need to delete a page in Confluence without using the GUI or using the database for it , but going through the User Interface (UI) could be rather impractical depending on the situation (for example the page is not accessible via browser).
This document provides a step-by-step procedure on how to use the Confluence REST API to delete the current version of a page, provided you have the pageid.
The suggested solution is provided as a set of bash commands using curl to run the REST API call. You may use this as an example to create an automation tool in your preferred coding language.
This suggestion is for Confluence Server and Data Center.
Solution
The suggested solution will permanently delete the current version of the page.
It is recommended you test this in a lower environment to understand the consequences of it before applying your solution in a production environment.
Also, is very recommended that you have a backup of your system.
Set up environment variables as suggested below.
USER_NAME=<username> ### You must be either a Space Administrator or a Confluence Administrator since we will purge the trash USER_PASSWORD=<user password> CONFLUENCE_BASEURL=<Confluence Base URL> ### FQDN and context path without the trailing slash CONTENT_ID=<page ID>
Send the page to the Space Trash.
TheDELETE
operation will change the page status fromCURRENT
toTRASHED
.
The expected HTTP status for this request is 204.
This operation can be reverted from the UI by accessing the Space Trash.curl -u ${USER_NAME}:${USER_PASSWORD} -H 'Content-Type: application/json' -H 'Accept: application/json' -X DELETE ${CONFLUENCE_BASEURL}'/rest/api/content/'${CONTENT_ID}'?status=current'
Purge the page from the trash.
This is the operation that will delete the page metadata from the Confluence database and the actual file(s) from the file system.
The expected HTTP status for this request is 204.
This operation cannot be reverted.curl -v -u ${USER_NAME}:${USER_PASSWORD} -H 'Content-Type: application/json' -H 'Accept: application/json' -X DELETE ${CONFLUENCE_BASEURL}'/rest/api/content/'${CONTENT_ID}'?status=trashed' >/dev/null
With the steps above we provided an example of how to completely delete the current version of a page.
With this, you may be able to create a script in your preferred coding language to delete a set of pages.
See Also
Confluence REST API Documentation