I'm trying to create a Personal Access token (PAT) using the REST API by sending a POST request with the following body:
{
"name": "tokenName",
"expirationDuration": 90
}
to
{{baseUrlOfYourInstance}}/rest/pat/latest/tokens
but I keep getting a 401 Unauthorized error back. The documentation here doesn't specify how to authenticate initially when trying to obtain a personal access token via the REST API. It just states to do what I am doing and you should get a personal access token back.
Do you need to use basic auth first in order to get the PAT and then future requests can just use the PAT for authentication?
Hi Andrew
welcome to the Atlassian community
To get the token you need first to send an authenticated request, so instead of using for example
curl https://YOURJIRAURL//rest/pat/latest/tokens
use
curl -u 'USERNAME:PASSWORD' \
--request POST \
-H "Content-Type: application/json" \
https://YOURJIRAURL//rest/pat/latest/tokens \
-d '{ "name": "tokenName", "expirationDuration": 90}'
You should get a response similar to
{"id":1,"name":"tokenName","createdAt":"2022-10-03T17:08:47.573+00:00","expiringAt":"2023-01-01T17:08:47.573+00:00","rawToken":"XXXXXXXXXXXXXXXXX/IJ3l0/7QfoCzA96KDX7PkN"}⏎
Hope that helps
Cheers
Kurt
Thanks for the answer.
It looks like I will still need to use Basic Authentication in order to get the PAT and then from there I can just use the PAT for future requests.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Greetings,
If the user authenticates to JIRA/Confluence with a public SSO like 'sign in with google' what parameters should be used for:
'USERNAME:PASSWORD'
The email address and password for my associated Google account does not seem to work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Spend the day sharpening your skills in Atlassian Cloud Organization Admin or Jira Administration, then take the exam onsite. Already ready? Take one - or more - of 12 different certification exams while you’re in Anaheim at Team' 25.
Learn more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.