Cannot make a JIRA REST API request (returning HTML?)

Mylan Connolly April 18, 2018

Hello all,

I am trying to make some REST requests for my Jira Cloud instance and it doesn't seem to be working. Here are the steps I have taken:

  1. Created an API token
  2. Created the base64-encoded basic authentication header value (in my case, I used something like `echo username:api_token | base64` and stripped the last 4 characters to match the example given here.
  3. Make a curl request like shown below:
curl -D- -H 'Content-Type: application/json' \
-H 'Authorization: Basic [base64 value here]' \
-X GET \
https://subdomain.atlassian.net/rest/api/2/issue/[issue key]

The response I get back appears to be an HTML unauthorized request page that has a link back to the Jira home page.

Is there some sort of authorization I need to do outside of creating an API key? The user account that I'm using has access to the project and issue I'm trying to fetch.

1 answer

1 accepted

2 votes
Answer accepted
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 19, 2018

Hi @Mylan Connolly

If you have created an API Token, then please run the request as it follows:

curl -D- -u EMAIL_ADDRESS:API_TOKEN -X GET https://subdomain.atlassian.net/rest/api/2/issue/ISSUE_KEY

(you can avoid the content type since it is just a GET request and you could avoid specifying the -X GET as well but I have put it there in order to avoid confusion :) )

For further details please see:

 

I hope this helps

Mylan Connolly April 19, 2018

Thanks for the help, that seems to have done the trick.

The documentation on that page seems to contradict the documentation here, however your solution works. Thanks again!

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 19, 2018

I believe the documentation needs indeed to be fixed since in the "Simple Example" section it provides the same curl request but it is not specifying you need to use the email address instead of the username:

Mylan Connolly April 20, 2018

Yeah I think that was the confusion I ran into; this whole time I was using the username field instead of the email address. When I corrected the actual code in my program (that the curl request was emulating), all I had to do was change the configuration to use an email address instead of a username).

Thanks again!

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 20, 2018

You are very welcome, I am happy to know this helped.

Have a nice weekend!

Robert Campbell July 18, 2019

Hi @Dario B ,

Do you have a dummy step by step guide to use the access to Rest API ? I am able to setup the Token, but unable to authenticate from it :(

The below URL is not working:

https://[org name].atlassian.net/rest/api/[token]

Can someone please tell us how it should be constructed and is there really a 100 row limit on the number of items we can download ?

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 18, 2019

Hi @Robert Campbell ,

I am not sure what you are trying to achieve but that is indeed not a valid REST API endpoint.

From the URL you are providing I assume you are using Jira Cloud and the documented REST API endpoints are the ones in below pages:

 

Also, since the examples in above documentation might be misleading, please review the below documentation request for examples on how to authenticate REST API calls in Cloud:

 

If this is for Jira Server instead, then you can find some examples in the below page and youtube video:

 

The above examples might apply to Cloud as well if you use email address and API Token for basic authentication instead of username and password.

 

Please let me know if this helps. 

 

Cheers,
Dario

Suggest an answer

Log in or Sign up to answer