Getting response error (400) when contacting REST API through JIRA API TOKEN

Bruno Mayol Giannoti May 12, 2020

Trying to make a GET request to the REST API using Jira API token. Works on the browser through google extensions using the SAME token. I literally copied the request to make sure I was not messing something up. Yet, it doesn't work still.

 

My request:

 

Method: GET,

URL: https://jiracloud.COMPANY.com.br//rest/api/2/search?fields=fields,key&jql=worklogAuthor=currentUser(),
Headers: {

   "content-type": "application/json",

   "cache-control": "no-cache",

    "app_token": "myToken"
}

 

Through the browser and/or Google Extensions that makes this same request I receive:


Status: 200

 

Through Postman or any code OUTSIDE the browser:

Status: 400,

Error: "Field 'worklogAuthor' does not exist or this field cannot be viewed by anonymous users."

 

I tried everything I could think of, don't know what else to do. Tried even using the the same "User-Agent" and Cookies as the browser uses to make the request...What am I missing? It must be something really obvious. 

Thanks

2 answers

1 accepted

0 votes
Answer accepted
Neil
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 12, 2020

The reason that you're able to make API calls from your browser is because of the session data stored in cookies. Replicating the exact cookie jar and request details coming from your browser in a REST API client like Postman isn't an exact science.

The recommendation would be to use basic authorization for making REST API calls in Postman.

If you're running Jira Server (on-prem): https://developer.atlassian.com/server/jira/platform/basic-authentication/ 

If you're making a call against Jira Cloud, you'd use basic auth but with an API token:
https://developer.atlassian.com/cloud/jira/software/basic-auth-for-rest-apis/

0 votes
Bruno Mayol Giannoti May 15, 2020

Thank you. If possible can you give me a hint on how can I find out if I'm dealing with Jira server or Jira Cloud? From the url of my company it seems like I'm dealing with cloud, since it's `jiracloud.mycompany.com`. Am I correct or there's another way to find this out?

Neil
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 18, 2020

@Bruno Mayol Giannoti sure.. just hit the /rest/api/2/serverInfo endpoint, and if you see deploymentType: "Cloud" then it's a cloud instance.

For example: https://ecosystem.atlassian.net/rest/api/2/serverInfo

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events