Heads up! On March 5, starting at 4:30 PM Central Time, our community will be undergoing scheduled maintenance for a few hours. During this time, you will find the site temporarily inaccessible. Thanks for your patience. Read more.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

401 When POST to get Personal Access token (PAT)

Andrew
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 3, 2022

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?

2 answers

1 accepted

0 votes
Answer accepted
Kurt Klinner
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 3, 2022

@Andrew 

 

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

Andrew
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 3, 2022

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.

Roma Bubyakin _Wombats Corp_
Contributor
July 31, 2024

Or you can create a token upfront from the WebUI and use it there (which is better practice)

0 votes
Ben Steinwand January 6, 2023

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. 

Suggest an answer

Log in or Sign up to answer