Going Stellar

Home/Atlassian REST API reference

Jira and Confluence Cloud REST API

Find a Confluence page by title with the REST API

v2 filters GET /wiki/api/v2/pages by title and space-id. v1 filters GET /wiki/rest/api/content by title and spaceKey. CQL gives a third route. Titles are unique per space, so an exact title and a space return at most one page.

Endpoints

MethodPathWhat it does
GET/wiki/api/v2/pagesv2: lists pages; title and space-id narrow the result.
GET/wiki/rest/api/searchv1: CQL search.
GET/wiki/rest/api/content/searchv1: CQL search returning content objects.

Examples

GET /wiki/api/v2/pages

v2 lookup by exact title inside one space id.

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": [
  {
   "spaceId": "655364",
   "version": {
    "number": 4
   },
   "id": "33653083",
   "status": "current",
   "title": "Example page"
  }
 ]
}

Sent to Atlassian Cloud on .

GET /wiki/rest/api/content

v1 lookup by title and space key, asking for the version.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'spaceKey=SD' \
  --data-urlencode 'title=Example page' \
  --data-urlencode 'expand=version' \
  'https://your-domain.atlassian.net/wiki/rest/api/content'

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "results": [
  {
   "id": "33653083",
   "type": "page",
   "title": "Example page",
   "version": {
    "number": 4
   }
  }
 ],
 "start": 0,
 "limit": 25,
 "size": 1
}

Sent to Atlassian Cloud on .

CQL search for the title inside a space.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'cql=space = SD AND title = "Example page"' \
  --data-urlencode 'limit=1' \
  'https://your-domain.atlassian.net/wiki/rest/api/search'

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "results": [
  {
   "content": {
    "id": "33653083",
    "type": "page",
    "title": "Example page"
   },
   "title": "Example page",
   "url": "/spaces/SD/pages/33653083/Example+page"
  }
 ],
 "totalSize": 1
}

Sent to Atlassian Cloud on .

POST /wiki/api/v2/pages

The uniqueness rule from the create side.

curl

curl -X POST \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '{
  "spaceId": "{spaceId}",
  "status": "current",
  "title": "Example child page",
  "body": {
    "representation": "storage",
    "value": "<p>Dup.</p>"
  }
}' \
  'https://your-domain.atlassian.net/wiki/api/v2/pages'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.post(
    'https://your-domain.atlassian.net/wiki/api/v2/pages',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
    json={'spaceId': '{spaceId}',
          'status': 'current',
          'title': 'Example child page',
          'body': {'representation': 'storage', 'value': '<p>Dup.</p>'}},
)
print(r.status_code, r.text)

Response: HTTP 400

{
 "errors": [
  {
   "status": 400,
   "code": "BAD_REQUEST",
   "title": "A page with this title already exists: A page already exists with the same TITLE in this space",
   "detail": null
  }
 ]
}

Sent to Atlassian Cloud on .

How it behaves

  • The v2 lookup returned one result with the same id as the page created earlier (conf-pages-by-title).
  • The v1 lookup returned size 1 and a default limit of 25 (conf-content-by-title-v1).
  • The CQL search returned totalSize 1 and echoed the query in cqlQuery (conf-cql-search).
  • Creating a second page with an existing title in the same space fails with 400, so one space never holds two pages with the same title (conf-page-create-duplicate-title).

Pitfalls

  • Without space-id (or spaceKey) a title can match pages in several spaces.
  • The v2 status filter defaults to current and archived per the spec, so a trashed page is not found by default.
  • title in CQL with = is an exact match. The ~ operator is a text match and can return several pages.

Questions and answers

Does the title match ignore case?

Not tested. Use the exact title and check the result.

Sources

  1. Get pages (Confluence REST API v2)
  2. Search content by CQL (Confluence REST API v1)
  3. The Confluence Cloud REST API v2 (Atlassian Developer)

Markdown version · All REST API pages