How to retrieve all previous versions of content using the REST API

Still need help?

The Atlassian Community is here for you.

Ask the community


Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

    

This document includes an internal API that also references an experimental endpoint and this information is provided as-is, we're unable to directly assist unless there is a bug or documentation error. However, we can definitely support you if a public REST API call isn't working as expected. See Atlassian Support Offerings for additional information.

Summary

The Confluence Server REST API endpoint for retrieving content history /rest/api/content/{id}/history only returns limited results including current, previousVersion,nextVersion,lastUpdated.

This is especially useful when developing your own apps or updating Confluence with scripts via the REST API or for any other purpose such as auditing or retrieving details from a specific page version.

In Confluence Cloud there is an endpoint that already provides this functionality and returns all versions: /wiki/rest/api/content/{id}/version


Diagnosis

A GET request to /rest/api/content/{id}/history will only return details of the latest version, previous version and last updated.

Default JSON response with limited version or history details...
{
    "previousVersion": {
        "by": {
            "type": "known",
            "username": "<USERNAME>",
            "userKey": "abc1234",
...
...
        "_links": {
            "self": "<baseURL>/rest/experimental/content/{id}/version/{number01}"
        },
        "_expandable": {
            "content": "/rest/api/content/{id}?status=historical&version=2"
        }
    },
    "lastUpdated": {
        "by": {
            "type": "known",
            "username": "<USERNAME>",
            "userKey": "abc1234",
	},
            "_expandable": {
                "status": ""
            }
        },
        "when": "2021-02-22T08:28:25.000+01:00",
        "message": "",
        "number": 3,
        "minorEdit": false,
        "hidden": false,
        "_links": {
            "self": "<baseURL>/rest/experimental/content/{id}/version/{number02}"
        },
        "_expandable": {
            "content": "/rest/api/content/{id}"
        }
    },
    "latest": true,
    "createdBy": {
        "type": "known",
        "username": "<USERNAME>",
        "userKey": "abc1234",
        "profilePicture": {
            "path": "/<contextPath>/images/icons/profilepics/default.svg",
            "width": 48,
            "height": 48,
            "isDefault": true
        },
        "displayName": "<USERNAME>",
        "_links": {
            "self": "<baseURL>/rest/api/user?key=abc1234"
        },
        "_expandable": {
            "status": ""
        }
    },
    "createdDate": "2021-01-29T11:14:40.302+01:00",
    "_links": {
        "base": "<baseURL>",
        "context": "/<contextPath>",
        "self": "<baseURL>/rest/api/content/{id}/history"
    },
    "_expandable": {
        "contributors": ""
    }
}


But within that response there is another endpoint that is exposed, it is expermiental so is not directly supported and cannot be guaranteed to be included in future updates but will provide details on all versions of a page.

        "_links": {
            "self": "<baseURL>/rest/experimental/content/{id}/version/{number}"


Solution

As described only the latest, previous and last updated details are returned. However, it turns out it's possible to manipulate the endpoint exposed below and by removing the version/{number} the request will return all versions of a page.

Notice the version number has been removed from the endpoint. Instead of /rest/experimental/content/{id}/version/{number}, if you make a GET /rest/experimental/content/{id}/version/ you will receive all content versions.

<baseURL>/rest/experimental/content/{id}/version
Experimental JSON response with all previous versions included...
{
    "results": [
        {
            "by": {
                "type": "known",
                "username": "<USERNAME>",
                "userKey": "abc123",
                "profilePicture": {
                    "path": "/<contextPath>/images/icons/profilepics/default.svg",
                    "width": 48,
                    "height": 48,
                    "isDefault": true
                },
                "displayName": "<USERNAME>",
                "_links": {
                    "self": "<baseURL>/rest/api/user?key=abc123"
                },
                "_expandable": {
                    "status": ""
                }
            },
            "when": "2021-02-22T08:28:25.000+01:00",
            "message": "",
            "number": 3,
            "minorEdit": false,
            "hidden": false,
            "_links": {
                "self": "<baseURL>/rest/experimental/content/{id}/version/3"
            },
            "_expandable": {
                "content": "/rest/api/content/{id}"
            }
        },
        {
            "by": {
                "type": "known",
                "username": "<USERNAME>",
                "userKey": "abc123",
                "profilePicture": {
                    "path": "/<contextPath>/images/icons/profilepics/default.svg",
                    "width": 48,
                    "height": 48,
                    "isDefault": true
                },
                "displayName": "<USERNAME>",
                "_links": {
                    "self": "<baseURL>/rest/api/user?key=abc123"
                },
                "_expandable": {
                    "status": ""
                }
            },
            "when": "2021-02-22T08:28:13.844+01:00",
            "message": "",
            "number": 2,
            "minorEdit": false,
            "hidden": false,
            "_links": {
                "self": "<baseURL>/rest/experimental/content/{id}/version/2"
            },
            "_expandable": {
                "content": "/rest/api/content/{id}?status=historical&version=2"
            }
        },
        {
            "by": {
                "type": "known",
                "username": "<USERNAME>",
                "userKey": "abc123",
                "profilePicture": {
                    "path": "/<contextPath>/images/icons/profilepics/default.svg",
                    "width": 48,
                    "height": 48,
                    "isDefault": true
                },
                "displayName": "<USERNAME>",
                "_links": {
                    "self": "<baseURL>/rest/api/user?key=abc123"
                },
                "_expandable": {
                    "status": ""
                }
            },
            "when": "2021-01-29T11:14:58.827+01:00",
            "message": "",
            "number": 1,
            "minorEdit": false,
            "hidden": false,
            "_links": {
                "self": "<baseURL>/rest/experimental/content/{id}/version/1"
            },
            "_expandable": {
                "content": "/rest/api/content/{id}?status=historical&version=1"
            }
        }
    ],
    "start": 0,
    "limit": 200,
    "size": 3,
    "_links": {
        "self": "<baseURL>/rest/experimental/content/{id}/version/",
        "base": "<baseURL>",
        "context": "/<contextPath>"
    }
}

Last modified on Feb 22, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.