How to get page history via REST API
Asked by Lucas Graebin:

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](/t5/image/serverpage/image-id/12345i77484DEE4EE191BA/image-size/large?v=v2&px=999 "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.


Answers:
author: Stephen Deutsch
body: 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.

comments: author: Stephen Deutsch
body: It's a good idea to install the free [REST API Browser](https://marketplace.atlassian.com/plugins/com.atlassian.labs.rest-api-browser/server/overview) to be able to see what REST calls are available on your instance (and makes it easier to test).


author: Lucas Graebin
body: 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.


author: Stephen Deutsch
body: 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.


author: Lucas Graebin
body: Hi Stephen,

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

![IMG_11012018_083805_0.png](https://community.atlassian.com/t5/image/serverpage/image-id/12413iCACBF30CC7B8EF37/image-size/large?v=v2&px=999 "IMG_11012018_083805_0.png")I'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.


author: Stephen Deutsch
body: 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.