It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

JIRA API - Basic authentication not work

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

curl -u myusername:mypassword
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

8 votes
Answer accepted
Alek Atlassian Team Aug 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: 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

what is &amp in your code?

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

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.

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.

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

^--- this guy saved my life

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.

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

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?

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

308 views 1 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you