Going Stellar

Home/Atlassian REST API reference

Jira and Confluence Cloud REST API

Add, list and remove Confluence page labels

Labels are added with the v1 POST /wiki/rest/api/content/{id}/label, which takes an array, and read with the v2 GET /wiki/api/v2/pages/{id}/labels. A label is removed by name with DELETE on the label path.

Endpoints

MethodPathWhat it does
POST/wiki/rest/api/content/{id}/labelv1: adds labels to a piece of content; existing labels stay.
GET/wiki/api/v2/pages/{id}/labelsv2: lists the labels of a page.
DELETE/wiki/rest/api/content/{id}/label/{label}v1: removes one label by name.

Examples

POST /wiki/rest/api/content/{pageId}/label

Adds a global label. The body is an array of label objects.

curl

curl -X POST \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  --data '[
  {
    "prefix": "global",
    "name": "api-example"
  }
]' \
  'https://your-domain.atlassian.net/wiki/rest/api/content/{pageId}/label'

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "results": [
  {
   "prefix": "global",
   "name": "api-example",
   "id": "33456401",
   "label": "api-example"
  }
 ],
 "start": 0,
 "limit": 200,
 "size": 1
}

Sent to Atlassian Cloud on .

GET /wiki/api/v2/pages/{pageId}/labels

Reads the labels of the page with v2.

curl

curl \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  'https://your-domain.atlassian.net/wiki/api/v2/pages/{pageId}/labels'

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "results": [
  {
   "prefix": "global",
   "name": "api-example",
   "id": "33456401"
  }
 ]
}

Sent to Atlassian Cloud on .

DELETE /wiki/rest/api/content/{pageId}/label/api-example

Removes the label by name.

curl

curl -X DELETE \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  'https://your-domain.atlassian.net/wiki/rest/api/content/{pageId}/label/api-example'

Python (requests)

import os
import requests

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

Response: HTTP 204

No response body.

Sent to Atlassian Cloud on .

How it behaves

  • The add call answers 200 with a results array in which each label has prefix, name, id and label (conf-label-add).
  • The v2 list returns prefix, name and id for each label, with no label field (conf-labels-get).
  • The remove call answers 204 with no body (conf-label-remove).

Pitfalls

  • The add body is an array even for one label. An object is not what the call takes.
  • The path form of the delete does not accept a slash in the name, per the spec. Use the query-parameter form for such names.
  • The v1 add call does not replace labels. The spec says an update of the content does.

Questions and answers

What is the prefix?

The runs used global. The label then is a normal label of the page.

Sources

  1. Add labels to content (Confluence REST API v1)
  2. Get labels for page (Confluence REST API v2)
  3. The Confluence Cloud REST API v1 (Atlassian Developer)

Markdown version · All REST API pages