is there any way to delete older attachment versions created in confluence

Jyotiprakash Nayak March 30, 2017
 

2 answers

0 votes
Sergio Santana Afonso May 8, 2020

You can do this via REST API:

 

DELETE <url>/rest/experimental/content/<attachmentID>/version/<versionNumber>

 

This line allow you to delete a certain attachment version so you could make, for example, a python script which would check your attachment last version and then remove remainder versions using http requests.

You could even check the "when" field at the attachment version via REST API and then only delete it if its date is under a specific day.

For example, you want to remove all the attachment version under 20-05-2019 so first you should check the attachment ID and number of versions (let's say the file is attached to a page which ID is 131400):

-----pseudocode------

var response = GET <ip>/rest/api/content/131400/child/attachment?expand=version

var attachmentID = response[id]

var attachmentVersions = response[number]

-----end-pseudocode------

Now we have our attachment ID and the number of versions this file has. The next step is to check the upload date of that file and then if it's under 20-05-2019 we will delete it (let's say our attachment ID is 220859).

-----pseudocode------

for int i = 0; i < attachmentVersions; i++{

var response2 = GET <ip>/rest/experimental/content/+"attachmentID"+/version/+"i"

    if (response2[when] < "20-05-2019"){

        DELETE <ip>/rest/experimental/content/+"attachmentID"+/version/+"i"

    }

}

-----end-pseudocode------

I think Confluence automatically refreshes the version number field when you delete a specific version of the attachment so, for example, if you remove the attachment version number 19 then the old attachment with version 20 becomes the new version 19. This should be aplied to the previous pseudocode.

Martin Podhovnik March 23, 2022

For the completeness of this good answer from @Sergio Santana Afonso :

Using the delete method on 

/rest/experimental/content/<attachmentID>/version/<versionNumber>

does indeed delete the version from the database - but, as it looks like after some tests I did, it does NOT delete the file version from the filesystem.

In contrary, a manual delete via web interface does remove the version also from file system - and does not renumber it.

There seems to be no complete REST based method of removing versions from attachments (which would absolutely be a neccessity as for instance the companion app can create hundreds of versions for one attachment).

Starting with Confluence 7.16 (and here this is valid ONLY for datacenter) you are getting retention rules, who will help out here.

For server license see also the feature suggestion CONFSERVER-36015  

0 votes
Steffi Frank March 30, 2017

First you need to check your (space) permissions: are you allowed to delete attachments? If so: open the file list attached to your page and delete the version you don't need anymore

 

Hm... sorry, not able to attache a picture here (I get the following error: Error creating temp file in folder: /opt/j2ee/domains/atlassian.com/answers-confluence/home/attachments/ver003/nonspaced/92/143/65643092/65643112)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events