REST API - Deleting old version issue
Asked by Sukhjinder Bhullar:

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](https://leapdev.atlassian.net/wiki/rest/api/content/1151139901/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


Answers:
author: Dario B
body: Hello [@Sukhjinder Bhullar](/t5/user/viewprofilepage/user-id/3720849) ,

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](https://developer.atlassian.com/cloud/confluence/rest/?_ga=2.124855498.1583853162.1585655643-1080961822.1564054573#api-api-content-id-version-get) (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](https://developer.atlassian.com/cloud/confluence/rest/?_ga=2.124855498.1583853162.1585655643-1080961822.1564054573#api-api-content-id-version-versionNumber-delete) 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

comments: author: Dean Holmes
body: 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


Tags: confluence-cloud

atl-adm