How to get page history via REST API

Is it possible to get all content versions using REST API? Today we have a Confluence page with the below versions:

IMG_10012018_165423_0.png

I would like to know whether I can get the above data using REST API. Currently we are using Confluence 5.9.10.

Thanks.

 

1 answer

0 votes

Well, one way to do it would be to call https://<host>/rest/api/content/<pageID>?expand=version%2Chistory.previousVersion and then after getting the previous version number calling https://<host>/rest/api/content/<pageID>?expand=version%2Chistory.previousVersion&version=<versionNumber>. However, you would have to do this for every version number.

It's not guaranteed to be in your version of Confluence, but you may have https://<host>/rest/experimental/content/<pageId>/version which can get every single version in one call, similar to the way it is displayed on the versions page.

Stephen Deutsch Community Champion Jan 11, 2018

It's a good idea to install the free REST API Browser to be able to see what REST calls are available on your instance (and makes it easier to test).

Thanks for your reply. The first call works fine here. However, the second one returns the below message:

{ "statusCode": 501 }

Considering your example and a page with 6 versions, this is the URL that I'm calling on my side: https://<HOST>/rest/api/content/104021180?expand=version,history.previousVersion&version=1. 

Do you think I'm doing something wrong here?

Thanks.

Stephen Deutsch Community Champion Jan 11, 2018

Hi Lucas,

It's possible that you are getting a 501 because you are trying to call a previous version on version #1 (which wouldn't have a previous version. You would need to read the version number from the first response (5 in your example), and then run it with that version - 1 (so https://<HOST>/rest/api/content/104021180?expand=version,history.previousVersion&version=4), until you get to 2, which would be the last one, as it would display version 1 as the previous version.

Alternatively, there's also a nextVersion parameter, so you could use the URL https://<HOST>/rest/api/content/104021180?expand=version,history.nextVersion&version=1 and count up instead of counting down.

Hi Stephen,

It's still not working. Please check below the previousVersion node of the content.

IMG_11012018_083805_0.pngI'm getting a 501 when I call https://<HOST>/rest/api/content/104021180?expand=version,history.previousVersion&version=4 and https://<HOST>/rest/api/content/104021180?expand=version,history.nextVersion&version=1. 

Just to confirm, the pageID is the ID of the current page, right? I'm not a Confluence expert, but looks like the older versions of a page have differents pageID. 

Thanks. 

Stephen Deutsch Community Champion Jan 11, 2018

Hi Lucas,

I apologize, even though it is there in the documentation and the REST API browser, the version parameter does not appear to be implemented (that's what the 501 refers to), so that's why it doesn't work, not that the pageID changes between versions (the pageID does stay the same for earlier versions).

It seems then that the only options are this https://<host>/rest/experimental/content/<pageId>/version call or https://kb.zanox.com/rpc/json-rpc/confluenceservice-v2/getPageHistory, but the second one has to be called with a POST request, so it's not possible to do it directly from the URL bar in the browser.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in New to Confluence

How to use Confluence Cloud for stakeholder management

Most of us don’t need much convincing that stakeholder management is important. It just makes sense that keeping everyone in-the-know on projects and assigning clearly defined roles is key to having ...

1,050 views 0 5
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you