Going Stellar

Home/Atlassian REST API reference

Jira and Confluence Cloud REST API

Confluence spaces in the REST API

GET /wiki/api/v2/spaces filters by keys, ids, type and status, and returns the space id that later calls need. GET /wiki/api/v2/spaces/{id}/pages lists the pages in a space and pages through a cursor.

Endpoints

MethodPathWhat it does
GET/wiki/api/v2/spacesLists spaces; keys filters by space key.
GET/wiki/api/v2/spaces/{id}/pagesLists the pages of a space.

Examples

GET /wiki/api/v2/spaces

Finds a space by key and reads its id and homepage id.

curl

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

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "results": [
  {
   "homepageId": "655541",
   "status": "current",
   "name": "Software Development",
   "key": "SD",
   "id": "655364",
   "type": "onboarding"
  }
 ]
}

Sent to Atlassian Cloud on .

GET /wiki/rest/api/space/SD

The v1 lookup of the same space.

curl

curl \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  'https://your-domain.atlassian.net/wiki/rest/api/space/SD'

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "id": 655364,
 "key": "SD",
 "name": "Software Development",
 "type": "onboarding",
 "status": "current"
}

Sent to Atlassian Cloud on .

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

Lists the pages of the space, one per call, sorted by id.

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": [
  {
   "parentId": null,
   "status": "current",
   "title": "Software Development",
   "id": "655541"
  }
 ],
 "_links": {
  "next": "/wiki/api/v2/spaces/655364/pages?limit=1&cursor=eyJpZCI6IjY1NTU0MSIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU0MX0="
 }
}

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 {_links.next}

Follows the next link from the previous call as it is.

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": [
  {
   "parentId": "655541",
   "id": "655577",
   "status": "current",
   "title": "Template - Product requirements"
  }
 ],
 "_links": {
  "next": "/wiki/api/v2/spaces/655364/pages?cursor=eyJpZCI6IjY1NTU3NyIsImNvbnRlbnRPcmRlciI6ImlkIiwiY29udGVudE9yZGVyVmFsdWUiOjY1NTU3N30=&limit=1"
 }
}

Sent to Atlassian Cloud on .

How it behaves

  • The v2 space entry has id as a string and homepageId, which is the root page of the space (conf-spaces-v2).
  • With limit=1 the response holds one page, a Link header with rel="next" and _links.next in the body with the same cursor (conf-space-pages-limit1).
  • The next URL is relative and already includes the limit, so it can be requested without changes (conf-space-pages-next).

Pitfalls

  • Space calls take the numeric id, not the key. Look the key up once and store the id.
  • The next URL starts at /wiki, so it is prefixed with the site URL, not with the v2 base.
  • Stop paging when the Link header and _links.next are both absent. The v2 intro says so.

Questions and answers

How do I find a space id?

Call GET /wiki/api/v2/spaces with keys set to the space key and read id.

Sources

  1. Get spaces (Confluence REST API v2)
  2. Get pages in space (Confluence REST API v2)
  3. The Confluence Cloud REST API v2 (Atlassian Developer)

Markdown version · All REST API pages