Going Stellar

Home/Atlassian REST API reference

Jira and Confluence Cloud REST API

Confluence v2 cursor pagination with Link and _links.next

Confluence v2 collections take limit and cursor. A response with more results carries the next page as a relative URL, both in the Link header with rel next and in _links.next in the body. Follow that URL as given, prefixed with the site host, and do not build cursors by hand.

Endpoints

MethodPathWhat it does
GET/wiki/api/v2/spaces/{id}/pagesPages the pages of a space.
GET/wiki/api/v2/pagesPages all pages the caller can see.

Examples

GET /wiki/api/v2/spaces/{spaceId}/pages

First page with limit 1: the next URL is in _links.next and in the Link header.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'limit=1' \
  'https://your-domain.atlassian.net/wiki/api/v2/spaces/{spaceId}/pages'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/wiki/api/v2/spaces/{spaceId}/pages',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'limit': '1'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "results": [
  {
   "status": "current",
   "title": "Software Development",
   "id": "655541"
  }
 ],
 "_links": {
  "next": "/wiki/api/v2/spaces/655364/pages?limit=1&cursor=eyJpZCI6IjY1NTU0MSIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU0MX0=",
  "base": "https://your-domain.atlassian.net/wiki"
 }
}

Response headers

Link: </wiki/api/v2/spaces/655364/pages?limit=1&cursor=eyJpZCI6IjY1NTU0MSIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU0MX0=>; rel="next", <https://your-domain.atlassian.net/wiki>; rel="base"

Sent to Atlassian Cloud on .

GET /wiki/api/v2/spaces/{spaceId}/pages

Adding sort=id gave the same first page and the same cursor as the default.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'limit=1' \
  --data-urlencode 'sort=id' \
  'https://your-domain.atlassian.net/wiki/api/v2/spaces/{spaceId}/pages'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/wiki/api/v2/spaces/{spaceId}/pages',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'limit': '1', 'sort': 'id'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "results": [
  {
   "title": "Software Development",
   "id": "655541"
  }
 ],
 "_links": {
  "next": "/wiki/api/v2/spaces/655364/pages?limit=1&cursor=eyJpZCI6IjY1NTU0MSIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU0MX0="
 }
}

Sent to Atlassian Cloud on .

GET {_links.next}

Follows the value of _links.next from the previous response as the request path.

curl

curl \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  'https://your-domain.atlassian.net{_links.next}'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net{_links.next}',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "results": [
  {
   "id": "655577",
   "status": "current",
   "title": "Template - Product requirements"
  }
 ],
 "_links": {
  "next": "/wiki/api/v2/spaces/655364/pages?cursor=eyJpZCI6IjY1NTU3NyIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU3N30=&limit=1"
 }
}

Response headers

Link: </wiki/api/v2/spaces/655364/pages?cursor=eyJpZCI6IjY1NTU3NyIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU3N30=&limit=1>; rel="next", <https://your-domain.atlassian.net/wiki>; rel="base"

Sent to Atlassian Cloud on .

GET /wiki/api/v2/pages

A small result needs no cursor: the Link header holds only the base entry.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'title=Example page' \
  --data-urlencode 'space-id={spaceId}' \
  'https://your-domain.atlassian.net/wiki/api/v2/pages'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://your-domain.atlassian.net/wiki/api/v2/pages',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    params={'title': 'Example page', 'space-id': '{spaceId}'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "results": [
  {
   "id": "33653083",
   "title": "Example page"
  }
 ],
 "_links": {
  "base": "https://your-domain.atlassian.net/wiki"
 }
}

Response headers

Link: <https://your-domain.atlassian.net/wiki>; rel="base"

Sent to Atlassian Cloud on .

How it behaves

  • The first page with limit=1 returned one page, _links.next as a path starting with /wiki/api/v2/spaces/{id}/pages and a cursor parameter.
  • The Link header held the same relative URL with rel next, followed by the site base URL with rel base.
  • The next URL repeats limit and puts cursor in the query string, and its parameter order differed between the first and second page.
  • The follow-up call used the _links.next value as its path and answered 200 with the next page.
  • A request with no further pages (by title) had a Link header with rel base only and no next entry in _links.

Pitfalls

  • The next URL is relative to the site root and already includes /wiki. Join it to the host, not to another path.
  • Do not parse the cursor. It is opaque and the order of query parameters can change between pages.
  • limit defaults to 25 with a maximum of 250 per the v2 pages reference, and some endpoints have different limits.

Questions and answers

Header or body for the next link?

Both carry it. The v2 guide says the relative URL in the Link header is also available under _links.next of the response.

Is there a total count?

None of the v2 pages above includes one. Count by walking the pages.

Sources

  1. The Confluence Cloud REST API v2 (Atlassian Developer)
  2. Get pages (Confluence REST API v2)

Markdown version · All REST API pages