Going Stellar

Home/Atlassian REST API reference

Jira and Confluence Cloud REST API

Get the current user with GET /rest/api/3/myself in Jira

GET /rest/api/3/myself is the cheapest check that a credential works and the way to learn the accountId of the caller. It answers with the full user record. Without credentials it answers 401 with a plain-text message and a Www-Authenticate header, not a JSON error object.

Endpoints

MethodPathWhat it does
GET/rest/api/3/myselfReturns the user the request is authenticated as.

Examples

GET /rest/api/3/myself

Reads the caller. groups and applicationRoles are present but collapsed.

curl

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

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "accountType": "atlassian",
 "displayName": "<display name>",
 "active": true,
 "timeZone": "Europe/Bucharest",
 "locale": "en_US",
 "groups": {
  "size": 6,
  "items": []
 },
 "applicationRoles": {
  "size": 1,
  "items": []
 },
 "expand": "groups,applicationRoles"
}

Response headers

X-Ratelimit-Limit: 350

Sent to Atlassian Cloud on .

GET /rest/api/2/myself

The same call on v2. The record has the same fields.

curl

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

Python (requests)

import os
import requests

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

Response: HTTP 200

{
 "accountType": "atlassian",
 "displayName": "<display name>",
 "active": true,
 "timeZone": "Europe/Bucharest",
 "locale": "en_US"
}

Sent to Atlassian Cloud on .

GET /rest/api/3/myself

No credentials. The body is a sentence, not JSON.

curl

curl \
  -H 'Accept: application/json' \
  'https://your-domain.atlassian.net/rest/api/3/myself'

Python (requests)

import requests

r = requests.get(
    'https://your-domain.atlassian.net/rest/api/3/myself',
    headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)

Response: HTTP 401

Client must be authenticated to access this resource.

Response headers

Www-Authenticate: OAuth realm="https%3A%2F%2Fyour-domain.atlassian.net"

Sent to Atlassian Cloud on .

GET https://api.atlassian.com/ex/jira/{cloudId}/rest/api/3/myself

The call through the api.atlassian.com gateway with the cloud id in the path instead of the site host.

curl

curl \
  -u "you@example.com:$ATLASSIAN_API_TOKEN" \
  -H 'Accept: application/json' \
  'https://api.atlassian.com/ex/jira/{cloudId}/rest/api/3/myself'

Python (requests)

import os
import requests

EMAIL = "you@example.com"
r = requests.get(
    'https://api.atlassian.com/ex/jira/{cloudId}/rest/api/3/myself',
    auth=(EMAIL, os.environ["ATLASSIAN_API_TOKEN"]),
    headers={'Accept': 'application/json'},
)
print(r.status_code, r.text)

Response: HTTP 200

{
 "accountType": "atlassian",
 "displayName": "<display name>",
 "active": true,
 "timeZone": "Europe/Bucharest"
}

Sent to Atlassian Cloud on .

How it behaves

  • The record includes accountId, accountType (atlassian), emailAddress, avatarUrls, displayName, active, timeZone and locale.
  • groups and applicationRoles were returned as {"size": n, "items": []}: the counts are there and the items are empty. The expand field names what can be added.
  • Without credentials the status was 401 and the body the text "Client must be authenticated to access this resource." with a Www-Authenticate header naming an OAuth realm.
  • The gateway URL on api.atlassian.com answered 200 with the same kind of user object as the site URL.

Pitfalls

  • Do not parse the 401 body as JSON. It is plain text, so a client that always calls .json() raises its own error.
  • emailAddress can be empty or absent for other accounts because of profile privacy settings, even when the caller's own record shows it.
  • Store accountId, not the email address. Every user parameter in the current API takes accountId.

Questions and answers

What is the quickest way to test a Jira API token?

Call GET /rest/api/3/myself. A 200 with your accountId means the credentials work; a 401 means they do not.

Sources

  1. The Jira Cloud platform REST API v3 (Atlassian Developer)
  2. Get current user (Jira REST API v3)

Markdown version · All REST API pages