REST API Tokens

 

General information

A primary use case for API tokens is to allow scripts to access REST APIs for Confluence applications using HTTP basic authentication.

If you define a token for a user, only that user can use it. If you do not specify a user, any user will be able to use this token.

If an external system is compromised, you can revoke the token instead of changing the password and consequently changing it in all scripts and integrations.

For security reasons we recommend generating token for specific user.

Editing the token after creation is not possible, create a new token if necessary.

You should treat API tokens as securely as any other password.

Supported endpoints

  • CONFLUENCE_URL/rest/*

or if you turn on option Restrict tokens only for Extender endpoints in configuration

  • CONFLUENCE_URL/rest/extender/*

Additionally, you can trace who and when used the token in the audit log

 

How does it work

Depending on the details of the HTTP library you use, simply replace your password with the token. For example, when using curl, you could do something like this:

 

1 curl -v https://my-confluence.com --user USER:TOKEN

Note that:

  • USER here is the email address or user name.

  • TOKEN here is token generated in REST API Tokens page

CURL Example

GET Example

1 curl -s -u admin:token1234567890 CONFLUENCE_URL/rest/extender/1.0/user/getUserDetails/admin
1 curl -s -u ansible@confluence.pl:token0987654321 CONFLUENCE_URL/rest/extender/1.0/user/getUserDetails/admin

Postman Example

Note that :

  • Basic Auth use this type in Authorization type

  • Username here is the email address or user name.

  • Passwordhere is token generated in REST API Tokens page

 

Specify supported URLs/methods for tokens

You can limit the token to specific urls and methods. Provide endpoint url with regular expression, add (or not) method restriction.

You can define any number of token restrictions, each of which should be on a new line.

Examples:

  • Restriction to set property endpoint on space with key EXTENDER (only POST method)

1 [post].*/rest/api/space/EXTENDER/property.*
  • Restriction to all space endpoints (for all methods)

1 .*/rest/api/space.*

 

REST API

Available ONLY for Confluence administrators

Get all Tokens

Method type: GET

URL: {CONFLUENCE_URL}/rest/extender/1.0/tokenTools/get

Respons format: JSON

Example response:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 { "tokens": [ { "label": "Token name", "user": "admin", "token": "ip9ul19f8jenb92tji8lo34qt7tb1meo", "limitTo": "[post].*/rest/api/space/EXTENDER/property.*<br>.*/rest/api/space.*", "ip": "", "validUntil": 1630476718964, "dateCreated": 1622700718964, "counter": 100 }, { "label": "Token name two", "user": "jankowalski", "token": "okf8a73basc74nasc9n32", "limitTo": "", "ip": "192.168.1.1", "validUntil": 1630476718964, "dateCreated": 1622700718964, "counter": 123456 } ], "status": "ok" }

 


Create Token

Method type: POST

URL: {CONFLUENCE_URL}/rest/extender/1.0/tokenTools/set

Request format: JSON

Example request:

1 2 3 4 5 6 7 { "label": "Token name", "daysUntilExpiry": 90 "userName": "admin", "limitTo": "[post].*/rest/api/space/EXTENDER/property.*\n.*/rest/api/space.*" "token": "ip9ul19f8jenb92tji8lo34qt7tb1meo" }
1 2 3 4 5 { "label": "Token name", "daysUntilExpiry": 0 "token": "ip9ul19f8jenb92tji8lo34qt7tb1meo" }
1 2 3 4 { "label": "Token name", "userName": "admin" }

label - required - token name

daysUntilExpiry - optional - for security reasons, you can set this token to automatically expire. You can't change the expiry date once the token is created.

userName - optional - a user who will be able to use token, leave this field empty so that anyone can use the token.

limitTo - optional - you can limit the token to specific urls and methods, you can add new line sign using \n, \\n or <br>

token - optional - token, leave this field empty and the system will generate a random string


Delete Token

Method type: DELETE

URL: {CONFLUENCE_URL}/rest/extender/1.0/tokenTools/delete

Request format: JSON

Example request:

1 2 3 { "token": "ip9ul19f8jenb92tji8lo34qt7tb1meo" }

 

Changes

REST API Tokens is available since v. 2.6.*

Since v. 2.10.*

  • changes in supported endpoint URLs - CONFLUENCE_URL/rest/*

  • added tokens expiration functionality

  • added the ability to specify token restrictions for URLs/methods

Since v. 2.16.*

  • added public API for administrators