REST API not returning any data with API token

Serge Prud'homme February 5, 2020

Trying to fix an old script that used Basic Auth to connec to JIRA.
I see Basic Auth is no longer supported.

I read the following but although the queries return 200, they return no data.  

https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/

 

Here is the curl and output when using "-u":

curl -D- \
 -u serge.prud.homme@erxxxxxn.com:COb....64A \
 -X GET \
 -H "Content-Type: application/json" \
 https://NAME.atlassian.net/rest/api/2/search?reporter=serge.prudhomme


HTTP/2 200
server: AtlassianProxy/1.15.8.1
vary: Accept-Encoding
cache-control: no-cache, no-store, no-transform
content-type: application/json;charset=UTF-8
strict-transport-security: max-age=315360000; includeSubDomains; preload
date: Wed, 05 Feb 2020 13:22:12 GMT
atl-traceid: fbxxxxxxxxxxxxxx
x-arequestid: dfc1xxxxxxxxxxxxxxx8c3ea
x-xss-protection: 1; mode=block
timing-allow-origin: *
x-content-type-options: nosniff
set-cookie: atlassian.xsrf.token=BFK5-xxxxxxxxxxxxxxxxxxxxxxxx_lout; Path=/; Secure

{"startAt":0,"maxResults":50,"total":0,"issues":[]}


Same results if I try to create the header myself:

curl -D- \
 -X GET \
 -H "Authorization: Basic c2VyZ2UucHJ...2NSbWQ4OFF4TVAxbnJKS1AyNjRB" \
 -H "Content-Type: application/json" \
 https://NAME.atlassian.net/rest/api/2/search?reporter=serge.prudhomme


HTTP/2 200
server: AtlassianProxy/1.15.8.1
vary: Accept-Encoding
cache-control: no-cache, no-store, no-transform
content-type: application/json;charset=UTF-8
strict-transport-security: max-age=315360000; includeSubDomains; preload
date: Wed, 05 Feb 2020 13:23:37 GMT
atl-traceid: 70xxxxxxxxxxxxxx
x-arequestid: fa0a03xxxxxxxxxxxxxxxxxxx
x-xss-protection: 1; mode=block
timing-allow-origin: *
x-content-type-options: nosniff
set-cookie: atlassian.xsrf.token=BFK5xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxt; Path=/; Secure

{"startAt":0,"maxResults":50,"total":0,"issues":[]}



1 answer

1 accepted

1 vote
Answer accepted
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 11, 2020

Hi @Serge Prud'homme ,

Thanks a lot for pasting the curl output when executing the call. 

By looking at it I can see that:

  1. You are using an email address that is not present in the Jira instance you are sending the request to: the email address associated to your name in the given instance is serge.prudhomme@cxxx.xxx
  2. The syntax used to call the /rest/api/2/search endpoint is not correct, it should be: https://NAME.atlassian.net/rest/api/2/search?jql=reporter=serge.prudhomme

     

You can double check this by doing the following:

  • Send the exact same request with curl without providing any authentication credentials and see that the exact same response is returned:
    curl -D- -X GET https://NAME.atlassian.net/rest/api/2/search?reporter=serge.prudhomme
  • Send the above request but with the right syntax (adding jql= before the actual search query) will return a more meaningful error message:
    {"errorMessages":["Field 'reporter' does not exist or this field cannot be viewed by anonymous users."],"warningMessages":[]}
  • Try to log-into the Jira instance using the same email address (serge.prud.homme@exxxxxxx.xxx) and run the search from there. 

 

I hope this explains.

Also, I am going to edit your question in order to removed the sensitive data from there.

 

Cheers,
Dario 

Serge Prud'homme February 11, 2020

Thanks for pointing out this silly mistake. I was using to the wrong user (I'm using multiple user ids and got mixed up)

Like # people like this
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 12, 2020

You are very welcome @Serge Prud'homme .

To be honest this happens to everyone that has multiple accounts, included me ;) 

As a good practice, when searching via REST API fails, always try to log-into Jira as the same user and try to run the same search. This usually helps to narrow down the possible causes for the issue (wrong account, missing proper rights, etc)

 

Cheers,
Dario

Jojo Thomas September 18, 2022

@Dario B Your answer was very useful. In my case, I have only one email but I was mistyping the email address domain!

Like Dario B likes this
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 20, 2022

You are very welcome @Jojo Thomas

I am happy to know that after 2 year my answer can still be useful :) 

Like Jojo Thomas likes this

Suggest an answer

Log in or Sign up to answer