Going Stellar

Home/Atlassian REST API reference

Jira and Confluence Cloud REST API

Search Confluence with CQL through the REST API

Two v1 calls accept a cql parameter. /wiki/rest/api/search returns search results with an excerpt and a totalSize. /wiki/rest/api/content/search returns plain content objects and a cursor-based next link. A broken query gives 400 with the parser message.

Endpoints

MethodPathWhat it does
GET/wiki/rest/api/searchSearch with CQL; returns results with excerpt and totalSize.
GET/wiki/rest/api/content/searchSearch with CQL; returns content objects.

Examples

Searches for a title inside a space and limits the result to one.

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",
   "excerpt": "Written as wiki markup\n Edited through the API",
   "url": "/spaces/SD/pages/33653083/Example+page",
   "entityType": "content"
  }
 ],
 "start": 0,
 "limit": 1,
 "size": 1,
 "totalSize": 1,
 "cqlQuery": "space = SD AND title = \"Example page\""
}

Sent to Atlassian Cloud on .

Searches for pages whose title contains a word and asks for two.

curl

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

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "results": [
  {
   "id": "33784019",
   "type": "page",
   "status": "current",
   "title": "Example page created with v1"
  },
  {
   "id": "33653083",
   "type": "page",
   "status": "current",
   "title": "Example page"
  }
 ],
 "start": 0,
 "limit": 2,
 "size": 2,
 "_links": {
  "next": "/rest/api/content/search?next=true&cursor=_t_WyJcdDMzNjUzMDgzIEM/XiZsbD1FNzJaTCdjdSlOZVtCIGNwIl0%3D_h_W10%3D&limit=2&start=2&cql=space+%3D+SD+AND+type+%3D+page+AND+title+~+%22Example%22"
 }
}

Sent to Atlassian Cloud on .

GET /wiki/rest/api/search

Sends a query that stops after the operator.

curl

curl -G \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  --data-urlencode 'cql=space = ' \
  '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 = '},
)
print(r.status_code, r.text)

Response: HTTP 400

{
 "statusCode": 400,
 "data": {
  "authorized": true,
  "valid": true,
  "errors": [],
  "successful": true
 },
 "message": "com.atlassian.confluence.api.service.exceptions.api.BadRequestException: Expecting a value for operator '=' after field 'space'"
}

Sent to Atlassian Cloud on .

How it behaves

  • The search call echoes the query in cqlQuery and reports totalSize and searchDuration (conf-cql-search).
  • The content/search call returned two results with limit=2 and a next link that carries a cursor and the original cql (conf-cql-content-search).
  • A bad query gives 400 with statusCode 400 and a message such as "Expecting a value for operator '=' after field 'space'" (conf-cql-bad).

Pitfalls

  • The search endpoint no longer accepts user fields such as user or user.accountid, per the spec text.
  • The error body of the search calls is not an errors array. It has statusCode, data and message.
  • The next link of content/search starts with /rest/api, without /wiki, so add the prefix yourself.

Questions and answers

Where is the CQL syntax?

The CQL reference covers the syntax; this page covers the HTTP side only.

Sources

  1. Search content (Confluence REST API v1)
  2. Search content by CQL (Confluence REST API v1)
  3. Using the REST API, Confluence (Atlassian Developer)

Markdown version · All REST API pages