REST API - Deleting old version issue

Sukhjinder Bhullar March 26, 2020

Hi, 

I have a automation which publish 10s of pages on confluence everyday. Right now i am checking page existence, if page exists delete it and create it again with new content. 

Instead of delete -> create , I am thinking to update if page exists. I think update will work all fine but issue I have is as i have 10s of pages and if i update the page  it will have versions with every page and eventually after a month, i will end up 1000s of revisions. 

So solution i was looking here is update the page and delete the version (latest -2), this way i will always main 2 versions of page and will also not end up having 1000s of versions. 

After doing some research i found below link which stats it is possible if we get pageID of version. 

https://community.atlassian.com/t5/Answers-Developer-Questions/Confluence-REST-API-How-to-list-and-delete-old-versions-of-a/qaq-p/542714

 

But I could not find the pageID of version. For sample I am pasting my output data as below: 

https:///wiki/rest/api/content/12345/version

{"results":[{"by":{"type":"known","accountId":"xx","accountType":"atlassian","email":"dxx","publicName":"x","profilePicture":{"path":"/wiki/aa-avatar/xx","width":48,"height":48,"isDefault":false},"displayName":"x","_expandable":{"operations":"","personalSpace":""},"_links":{"self":"https://x/wiki/rest/api/user?accountId=xxx"}},"when":"2020-03-27T04:41:41.331Z","friendlyWhen":"27 minutes ago","message":"","number":2,"minorEdit":false,"syncRev":"0.confluence$content$12345","syncRevSource":"synchrony-ack","confRev":"confluence$content$12345.7","_expandable":{"collaborators":"","content":"/rest/api/content/12345"},"_links":{"self":"https:///wiki/rest/api/content/12345/version/2"}},{"by":{"type":"known","accountId":"x","accountType":"atlassian","email":"xx","publicName":"x","profilePicture":{"path":"/wiki/aa-avatar/x","width":48,"height":48,"isDefault":false},"displayName":"DevOps Confluence","_expandable":{"operations":"","personalSpace":""},"_links":{"self":"https:///wiki/rest/api/user?accountId=xx"}},"when":"2020-03-27T04:24:51.404Z","friendlyWhen":"44 minutes ago","message":"","number":1,"minorEdit":false,"syncRev":"0.confluence$content$12345","syncRevSource":"synchrony-ack","confRev":"confluence$content$123456.3","_expandable":{"collaborators":"","content":"/rest/api/content/12345?status=historical&version=1"},"_links":{"self":"https:///wiki/rest/api/content/12345/version/1"}}],"start":0,"limit":200,"size":2,"_links":{"base":"https:///wiki","context":"/wiki","self":"https:///wiki/rest/api/content/12345/version"}}

This PageID 12345 has 2 versions. Now I could use 

DELETE https://wiki/rest/api/content/12345/version/1 but i am getting 404 

Regards

Sukh

1 answer

0 votes
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 3, 2020

Hello @Sukhjinder Bhullar ,

If I understand correctly you are trying to delete a page version via REST API but this is not succeeding for you. 

I have just tested it and it worked fine for me. What I have done is the following:

 

1) Send a request to Get content versions (GET /wiki/rest/api/content/{id}/version):

curl -u <EMAIL-ADDRESS>:<API-TOKEN> "https://<SITE_NAME>.atlassian.net/wiki/rest/api/content/457801729/version"

{
"results": [
{
"by": {
"type": "known",
...
...
},
"when": "2020-03-27T10:32:39.812Z",
"friendlyWhen": "Mar 27, 2020",
"message": "",
"number": 9,
"minorEdit": false,
...
"_links": {
"self": "https://<SITE_NAME>.atlassian.net/wiki/rest/api/content/457801729/version/9"
}
...

 

2) From above results, you can see that the last version at the moment is version number 9

 

3) Send a DELETE request to remove version 4 (endpoint: /wiki/rest/api/content/<ID>/version/4). Adding the -D- flag to show the response header:

curl -D- -u <EMAIL-ADDRESS>:<API-TOKEN> -X DELETE "https://<NAME>.atlassian.net/wiki/rest/api/content/457801729/version/4"
 
HTTP/2 204 
server: AtlassianProxy/1.15.8.1
cache-control: no-cache, no-store, must-revalidate
content-type: application/json
...

 

4) Sending another request to GET the page versions like in step #1 will now show the last version for the page to be version number 8.

This is because, as written in the documentation for the Delete content version REST API endpoint (DELETE /wiki/rest/api/content/{id}/version/{versionNumber}) the changes for the deleted version are rolled-up into next-version:

Delete a historical version. This does not delete the changes made to the content in that version, rather the changes for the deleted version are rolled up into the next version. Note, you cannot delete the current version.

 

I hope this helps.

 

Cheers,
Dario

Dean Holmes
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 14, 2023

I have tried both

https://<name>.atlassian.net/wiki/api/v2/pages/3187649/versions/1
https://<name>.atlassian.net/wiki/api/content/3187649/version/1

Both come back with 405 method not allowed sending delete

TIA

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events