Confluence REST API - How to list and delete old versions of a page

H Leung April 4, 2016

I'm trying to create a script and use REST API to clean up old versions of Confluence pages. My plan is to delete all old versions which are, say,  more than a month ago. I've been experimenting with the GET and DELETE methods of the /rest/content/{id} API call. While I can retrieve and delete the page using page id of the current page, it seems like it does not allow me to retrieve or delete old version of a page (404 not found).

 

For example, given the history of a page:

Current version (v.2): pageId=14811612

v.1: pageId=14811661

 

Both API calls work:

GET /rest/api/latest/content/14811612
DELETE /rest/api/latest/content/14811612

 

Both API calls fail (404):

GET /rest/api/latest/content/14811661
DELETE /rest/api/latest/content/14811661

 

Also, currently I use a SQL query on the "content" table to obtain a list of contentIds (as pageIds) of all old versions of a page directly. Is there a REST API to do the same thing?

 

I'm using Confluence 5.6.3.

 

Thanks.

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 9, 2016

Consider using removePageVersions from Confluence Command Line Interface (CLI). The CLI uses a mixture of SOAP and REST APIs to do actions. The SOAP APIs are gradually being replaced by REST APIs under the covers based on Confluence providing equivalent capabilities in the REST APIs. It is a slow process, but the Confluence team has always indicated that the SOAP APIs will continue to be there until the the REST APIs have similar capability. 

H Leung April 11, 2016

Thanks Bob, your CLI is the way to go.

 

1 vote
Adam Stechschulte September 21, 2016

I'm looking for this same functionality.  The Confluence Cloud API Documentation shows a `DELETE /rest/api/content/{id}/version/{versionId}' operation, but the same operation is not mentioned in the Confluence Server API reference.  Anyone have any ideas when that operation will make the jump from Cloud to Server?

0 votes
H Leung April 8, 2016

Atlassian indicates that the new REST API is "progressively" replacing XML-RPC and SOAP interfaces. (https://developer.atlassian.com/confdev/confluence-rest-api/confluence-xml-rpc-and-soap-apis)

I tend to believe the REST API, at present, does not support the removal of old version of a page. The older Confluence RPC/SOAP API has distinct methods to remove page - removePage() and remove page version - removePageVersionById() and removePageVersionByVersion(). REST API only has DELETE /rest/content/{id} which does not work if the id is the page id of an old version as tried.

(RPC API: https://docs.atlassian.com/atlassian-confluence/latest/index.html?com/atlassian/confluence/rpc/soap/ConfluenceSoapService.html)

0 votes
Aleks Yenin (Polontech)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 5, 2016

You can try DELETE /rest/content/{id}
https://docs.atlassian.com/confluence/REST/latest/

H Leung April 5, 2016

Thanks Aleks. I believe that's what I've been using. And it only works for the current version of a page (version 2's id is 14811612 in my original example). But when I put the id of the old version of a page (14811661) in the DELETE, it gives me a 404 error. I'm not able to delete that old version using the DELETE method.

Alin_Gabriel_Draghici May 27, 2019

If you use the GET content, there's a field for version. if you use the main page's ID and the version of the revision, you'll get the proper response (you can even see the "alternate" id of that version page, different from the main page).

 

But if you try to DELETE using the main page ID and add the "version" field, it seems to ignore it and just delete the whole page :(


I think that's the main problem, the added version field not deleting only the previous version that is mentioned; the field appears in the endpoint, but to no avail.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events