Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get page history via REST API

Lucas Graebin January 10, 2018

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
Stephen Deutsch
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.
January 11, 2018

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
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.
January 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).

Lucas Graebin January 11, 2018

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
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.
January 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.

Lucas Graebin January 11, 2018

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
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.
January 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
TAGS
AUG Leaders

Atlassian Community Events