Jira Rest API 2/3 returning always 401 Unauthroized error

Suresh Babu April 25, 2019

my last test was on 29th Mar 2019 and it was worked well and good at that time.

when I tried to used same queries today getting 401 error and remining all queries too, then used CURL command  getting same response, now nothing is working

 

curl -D- -u <email>:<password> -X GET -H "Content-Type: application/json" http://<domain>.atlassian.net/rest/api/2/search?jql=project=<projectname>&fields=id,key&startAt=1&maxResults=1

curl --request GET --url 'https://<domain>.atlassian.net/rest/api/2/search?jql=project=<projectname>&fields=id,key&startAt=1&maxResults=1' --header 'Authorization: Basic <auth token>' --header 'Accept: application/json'

 

please advice what is wrong here

1 answer

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 29, 2019

Hi Suresh,

Atlassian's Jira Cloud has deprecated the use of plaintext passwords for basic auth type REST API requests.  More details are in https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/

In place of using a clear text password, you can still use basic auth, but you will need to create an API Token for your account and use this instead.  Follow the instructions here to generate an API token.  That Token is not a direct replacement for the password, but there are steps you need to follow to do this in https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/

From that page:

Supplying basic auth headers

If you need to, you may construct and send basic auth headers yourself. To do this you need to perform the following steps:

  1. Generate an API token for Jira using your Atlassian Account: https://id.atlassian.com/manage/api-tokens.
  2. Build a string of the form useremail:api_token.
  3. BASE64 encode the string.
  4. Supply an Authorization header with content Basic followed by the encoded string. For example, the string fred:fred encodes to ZnJlZDpmcmVk in base64, so you would make the request as follows:
1
2
3
4
5
curl -D- \
   -X GET \
   -H "Authorization: Basic ZnJlZDpmcmVk" \
   -H "Content-Type: application/json" \
   "https://your-domain.atlassian.net/rest/api/2/issue/QA-31"

Instead of using the -u switch, you would need to use the -H and encode your useremail:api_token into a base64 string, and then use that string as the example above explains.

 

I hope this helps.

Andy

Suggest an answer

Log in or Sign up to answer