JIRA API - Basic authentication not work

nonggiatu August 22, 2013

I try to use curl to get list of projects on my JIRA:

curl -u myusername:mypassword http://myjira.com/rest/api/2/project
and it return an empty array without error
I use Postman (a Google Chrome app) to call that request using Basic authentication, it also return an empty array
If I login into my JIRA site and use Postman to call the API again, it return a full list of 
project because it used Cookie that was generated after my login.  
So I think the Basic Authentication does not work. Can anyone please help?

7 answers

1 accepted

9 votes
Answer accepted
Aleksander Mierzwicki
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 22, 2013

Is your JIRA behind some proxy server? Proxy servers can eat the basic auth credencials.

If that's the case, then you need to initialize session using POST request to /rest/auth/1/session: https://docs.atlassian.com/jira/REST/latest/#idp1478624 After doing that you can use REST as logged in user if you pass session cookies properly.

One liner to login and get project, without basic auth:

# -c option makes curl write cookies from response to given file
# -b option makes curl send cookies from given file in request
curl -c cookiesfile http://localhost:8090/jira/rest/auth/1/session -d '{"username":"admin", "password":"admin"}' -H 'Content-Type: application/json' -X POST && echo -e "\n-----------------\n" && curl -b cookiesfile http://localhost:8090/jira/rest/api/2/project

anant.gupta@247-inc.com June 21, 2018

what is &amp in your code?

Deleted user July 19, 2018

"&" is just the '&' character. So you can just replace them with '&'.

Inder Kumar Singh May 7, 2020

If my username contains @ sign what i need to do

6 votes
Bruce Kinchin December 16, 2015

Another addition to this thread (as I've also been looking as to why basic auth was not working also), remember your email address is not the username. I've been attempting authentication (unsuccessfully) with REST api and basic auth using my email address because it is what I use to signin to JIRA and made an incorrect assumption in my haste. I'm feeling a little silly after that one, but it might be catching other people too.

emittman March 31, 2016

Bruce, you helped me to prevent a concussion from banging my head against the wall. Thank you sir.

Luuk de Waal Malefijt October 4, 2019

^--- this guy saved my life

3 votes
nonggiatu August 22, 2013

I already read that note and try to use send username and password both via -u parametter or via header using base64 encode of username:password. However, no matter what I try, it still return an empty array.

1 vote
Jason Nguyen May 12, 2014

How would you do this via Jquery/AJAX and getting around the lack of CORS support for the JIRA REST API?

cURL command works fine for me but what's the point when I need the project information I need via JavaScript.

Luc Klaassen June 5, 2014

I also have this problem. Without the availability of JSONP or CORS, the only solution left is to call the service from serverside code instead of javascript.

0 votes
nonggiatu August 22, 2013

Aleksander Mierzwicki: You are right. It is because of the proxy server. Your solution is exactly what I need. Thank you so much

I really appreciated all your help

0 votes
Pawel Skierczynski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 22, 2013

I have clean fresh JIRA instance.

To check I did exactly curl -u user:password http://localhost:8090/jira/rest/api/2/project

I've got empty array then realized I forgot to add any project...

After adding project this curl just works.

Maybe you use different version of JIRA than I do?

0 votes
Norman Abramovitz
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.
August 22, 2013

Suggest an answer

Log in or Sign up to answer