JIRA Rest API authentication always returns 401 unauthorized

Pierre-Louis Gottfrois September 15, 2015

I have been trying for hours the following simple CURL command described in the documentation without any success. It always returns me a 401 unauthorized.

curl -D- -u "email:password" -X GET -H "Content-Type: application/json" https://textmaster.jira.com/rest/api/2/issue/TM-3450

I have checked that my confluence config has the "allow remote api calls" set to true. What should I do to make this work?

 

Note: I'm able to access the rest API from the browser directly, while logged in with my user account.

Note: It's a linked google account with a password set.

6 answers

1 accepted

17 votes
Answer accepted
Taha Khanzada
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.
September 15, 2015

Hi Pierre-Louis,

Silly question but your email is your username? if not then your command should be replaced with JIRA username. Also since your connection is https but -k at the end of the URL  and try again

curl -D- -u "username:password" -X GET -H "Content-Type: application/json" https://textmaster.jira.com/rest/api/2/issue/TM-3450 -k 

Also if that is not the case then you can try other authentication technique like Oauth.

Taha

Nate Brustein October 1, 2015

I just wanted to add a comment because I skipped by this answer and then kept looking for a while before realizing this was the correct answer. Even though I login to confluence with `nate@mydomain.com`, that is not the username to user when authenticating against the api. Against the api, I have to use `nate` as the username.

Like Deleted user likes this
Jonathan Sullivan December 30, 2015

This can't be stated enough. The API docs aren't clear and make it sound like the website authentication is exactly the same as the rest API authentication. The website works with both username and email as the "username" while the rest API only works with username. You can see your "username" by viewing your profile in JIRA.

Like Rabbit Stoddard likes this
georgy kagan February 25, 2016

Jesus... I spent hours trying to figure out why, are we supposed to be mind readers? You have to emphasize this fact in your documentation, since it's almost ubiquitous that both email and username can be used to authenticate.

Like # people like this
Martin Hill October 26, 2016

Thank goodness; yes this solved it.

To complicate matters, the REST API was accepting with the email address as the login ID for the first minute or so after the first login with a new account, so it was working for a while ... and then not.

John Nguyen February 22, 2018

@ Jonathan Sullivan

My username is also my email address but Jira won't allow me to change the username to a new username.  So what can I do to make my authentication API work?

  Let say my email address is "nguyen7744@yahoo.com", can I send my authentication as: 

curl -D- -u "nguyen7744:password1234" -X GET -H "Content-Type: application/json" https://textmaster.jira.com/rest/api/2/issue/TM-3450

 

If that won't work then how can I change my current username (nguyen7744@yahoo.com) to a new username? Or I need to contact JIra's support?

Thanks

John Nguyen



Like Mark Hostetler likes this
David Gacías Lacruz January 23, 2019

So i was struggling with this for about 2 days, and none of those answers worked for me.

I was able to query the api using my personal username:password but not the account that will be used in the automations, as it returned every time authentication_failed with a 401.

We use google accounts, but i found that i was able to log in using my username instead of my email, but the automation account was not able to, so that's why basic auth was failing every time.

In the end what i did to solve it was to login with the user in jira, check it had the correct permissions to what i wanted, then create an api token in the user profile.

Then i was finally able to query the api using curl with -u email:apitoken endpoint

I post it here just in case anyone else is having this same problem.

Like # people like this
Kritish Pahi April 17, 2019

This helped. 
Thanks

Adam Knee April 30, 2019

David Gacías Lacruz This helped, thank you!

YMS005-Nguyen Trung Dung May 21, 2019

It works like a charm.

PK_Krishnamoorthy May 21, 2020

Awesome ! It works 

PK_Krishnamoorthy May 21, 2020

It works with curl command, when i use Python library and similar token with authentication username : Email Id and password "API Token", it does not work.

 

Using jira-python library.

41 votes
Sharoon Thomas June 12, 2018

Faced the same issue and found the solution (as of June 2018).

The username IS the full email.

The password is NOT your password to login, but an API token. To generate an API token, go to https://id.atlassian.com/manage/api-tokens# and create a new one.

 

So the username is the full email and the password is the API token from above step for using basic auth with Jira API.

Safwan Ghamrawi June 27, 2018

Thanks it works for me

Like # people like this
Santosh Satyan July 5, 2018

I am still facing the issue. This is what I have configured in Jenkins (Jira Issue Updater 1.18):

https://companyname.atlassian.net/rest/api/2

Username: {Email} (also set as the username)

Password: {Token}

Am I missing any step? Appreciate your response.

Thanks!

Jesper den Boer July 25, 2018

Thanks for the tip!

Santosh Satyan July 25, 2018

@Jesper den Boer - I am still not able to get it to work with the configuration posted above. Did you do anything different?

Jesper den Boer July 25, 2018

Use your Google email as the username and the generated API token as the password.

Like # people like this
Shubh Dasgupta October 9, 2018

Thanks, this helped.

George Wright October 30, 2018

Using email as username and API Token for password worked for me, thanks!

Harry Hu February 12, 2019

Working, guess this is the right answer for new JIRA

Anant Kumar Sinha March 27, 2019

Thanks Jesper it works.

Michael Kröll April 14, 2019

omg, it really works, thanks!

Kz April 15, 2019

thanks. you saved me a day---

Umang Savaliya May 7, 2019

thanks!

amd_rikus May 8, 2019

This worked for me. Thanks a lot!

Abdul Moeed May 22, 2019

Bravo, finally i am able to run my code. It was working fine with the password but not now. 

Elvin Kennedy Latayan June 10, 2019

Brilliant :) Thank you :)

Max Goldfarb June 13, 2019

Finally a solution that works. Thank you so much!

Thanks. It worked for us.

Aizaz Toppa June 20, 2019

Thank you!

Danny June 30, 2019

Thanks mate. it worked for me :)

Abhishek_Pattanaik October 1, 2019

Thanks a lot.. You saved me :)

Joshua White October 29, 2019

Thanks!

SamuelToh November 18, 2019

Thanks for the helpful tips.

Now, this is a very very bad change decision by Atlassian I must say.

Token !== Password 

never...

Natalie February 14, 2020

Thanks! Thanks! Thanks!

Manish Makwana November 11, 2020

Just confirming this still works in Nov 2020 with Jira Cloud Next Gen, using atlassian-python-api. Username as my full email, password as API token. :D

Massimo del Vecchio June 19, 2021

Great. That worked 

3 votes
Joakim Söderberg February 6, 2017

Note that if you are logging in via a sync Google account, it is NOT the google password you are supposed to use. Also it is not the email.

Instead you should go to your user profile and look up your username and set a password.

https://confluence.atlassian.com/cloud/manage-your-profile-and-password-744721602.html

For site admin functions, RSS feeds, REST API access, or WebDAV uploads you'll need to have an Atlassian Cloud password (separate to your Google Apps password. If you haven't set an Atlassian Cloud password, go to the login page and choose Unable to access your account? in the Atlassian Cloud login section.

Of course it makes no sense that this information is not available on the REST API documentation page, since it is quite crucial to get it working.

Adam Zadikoff January 30, 2018

Is there a way to do this in the new JIRA experience? I can't seem to find any information and the link you provided is now dead.

Sean McConkey February 5, 2018

Having the same issue.

Xiaobo Zhang August 13, 2019

Amazing!!!

It works for me using API token to repalce the password. Thanks!

Safaa OUM January 28, 2020

@Joakim Söderberg:  The link you provided is now is dead. what username should we use please ? (at the jira interface we do use the email (gmail account) and the password to get in) , but using basic auth, when we send email and the token provided by jira, but it doesnt work

whet username should we use? where can we find it?

Like Kellen_Kincaid likes this
0 votes
Jean-Marcel Belmont October 28, 2019

I also faced this issue like others. I was able to successfully use my email with the rest api and then I created a new api token in https://id.atlassian.com/manage/api-tokens I used the openssl command like this:

 

printf myusername@domain.net:mypassword | openssl base64
bXl1c2VybmFtZUBkb21haW4ubmV0Om15cGFzc3dvcmQ=

For basic authentication to work you can't have a newline character so that is why I used printf to basic 64 encode, then you can make a rest call like this:

 

GET /rest/api/2/user?username=myusername HTTP/1.1
Host: somedomain.net
Authorization: Basic bXl1c2VybmFtZUBkb21haW4ubmV0Om15cGFzc3dvcmQ=
Accept: application/json 
0 votes
Spencer Loveridge July 15, 2019

Just in case any Gmail users gets to here and is still facing issues, make sure you use the exact email that is associated with your account:

so thats @gmail.com vs @googlemail.com

Lost a day or two on that one.

Gmail accepts both, most websites dont.

0 votes
Aalok Bhatwal April 18, 2019

I was facing a similar issue too. In case if someone trying to access the data using HttpWebRequest instead of curl, remember to base64 the credentials.

string Token = email + ":" + apiToken;

Token =  Convert.ToBase64String(UTF8.GetBytes(Token));

req.Headers.Add("Authorization", "Basic " + Token);

Verita June 21, 2019

It works, Thanks you

Suggest an answer

Log in or Sign up to answer