The behavior of the V2 api in regards to the pagination of includes is so strange that it might as well be a bug in my opinion.
Let’s look at Get page by id
https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-id-get, which allows to include include-versions
.
For testing I created a page 20709385
with 131
revisions since versions are numbered, so it’s easy to keep track of the results:
The initial ordering within the included versions is descending but then we get next links and cursor in ascending direction which means we go ‘downwards’ for one more request and then back up, never seeing all versions.
The initial request /api/v2/pages/20709385?include-versions=true
returns:
{
// ... other attributes
"versions": {
"results": [
// ... THE RESULTS 131 down to 82, ordering from the highest num descending
],
"meta": {
"hasMore": true,
"cursor": "eyJpZCI6IjIxMDA0NTQ1IiwiY29udGVudE9yZGVyIjoiLW1vZGlmaWVkLWRhdGUiLCJjb250ZW50T3JkZXJWYWx1ZSI6MTcxNDYzNDc5OTk0M30="
},
"_links": {
"self": "/api/v2/pages/20709385/versions"
}
},
"title": "Page title",
"status": "current",
// ... other stuff
}
Now I use the cursor
together with the _links.self
link to fetch the next page /wiki/api/v2/pages/20709385/versions?cursor=eyJpZCI6IjIxMDA0NTQ1IiwiY29udGVudE9yZGVyIjoiLW1vZGlmaWVkLWRhdGUiLCJjb250ZW50T3JkZXJWYWx1ZSI6MTcxNDYzNDc5OTk0M30=
:
{
"results": [
// results 81 down to 57, ordering descending again
],
"_links": {
"next": "/wiki/api/v2/pages/20709385/versions?cursor=eyJpZCI6IjIwOTcxNzMyIiwiY29udGVudE9yZGVyIjoibW9kaWZpZWQtZGF0ZSIsImNvbnRlbnRPcmRlclZhbHVlIjoxNzE0NjM0Nzg2NzQxfQ==",
"base": "https://pseeger-dev.atlassian.net/wiki"
}
}
Getting the next url here is easier, since there’s a _links.next
link this time, so I make that request to /wiki/api/v2/pages/20709385/versions?cursor=eyJpZCI6IjIwOTcxNzMyIiwiY29udGVudE9yZGVyIjoibW9kaWZpZWQtZGF0ZSIsImNvbnRlbnRPcmRlclZhbHVlIjoxNzE0NjM0Nzg2NzQxfQ==
:
{
"results": [
// contains results 58 UP TO 82!! Ordering now ASCENDING!
],
"_links": {
"next": "/wiki/api/v2/pages/20709385/versions?cursor=eyJpZCI6IjIxMDA0NTQ1IiwiY29udGVudE9yZGVyIjoibW9kaWZpZWQtZGF0ZSIsImNvbnRlbnRPcmRlclZhbHVlIjoxNzE0NjM0Nzk5OTQzfQ==",
"base": "https://pseeger-dev.atlassian.net/wiki"
}
}
The next link then gives me 83 to 107
, then 108 to 131
where there’s no more next link.
That means we never see results below 57 here, the first requests return pages in descending order, then it switches to the ascending order and I don’t see all results :facepalm: