JIRA Rest API authentication always returns 401 unauthorized

v-amaver
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 18, 2019

Hi Team,

From Yesterday I'm facing authentication issue for rest api which was working well from last one year. I've used basic authentication with base64Credentials and when my program reaching on given line( HttpWebResponse response = request.GetResponse() as HttpWebResponse; ) throwing error for 401 unauthorized. Please help me regarding this issue. If its related to permission then where can make changes to see the result or if any other issue like any updates in rest API then mention it too.

4 answers

1 accepted

5 votes
Answer accepted
Aleksandr Zuevich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 18, 2019

Basic authentication with passwords and cookie-based authentication are now deprecated and disabled. 

"The deprecation period for this functionality has ended. From June 3rd, 2019, we will be progressively disabling the usage of this authentication method" - https://developer.atlassian.com/cloud/jira/platform/deprecation-notice-basic-auth-and-cookie-based-auth/

You can use Basic Authentication with tokens instead of credentials.

trupti bhatt June 19, 2019

I am using tokens only. 

Generated access token of Username:Password with following URL with basic method

https://www.base64encode.net/

Like Brad Miele likes this
Aleksandr Zuevich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2019

It's insecure and disabled now. You have to create API token for your user as described here: https://confluence.atlassian.com/cloud/api-tokens-938839638.html.

Like 이종화 likes this
trupti bhatt June 19, 2019

I have created the api key then encoded it using base64 . Passed emailid:apikey.

 

Authorization : Basic <generated key>

Content-Type : application/json 

 

Then also it is not working. Am i missing any steps

Aleksandr Zuevich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2019

You should create API token and encode to base64 the whole String email:your-api-token.

Like # people like this
trupti bhatt June 19, 2019

Yes, i encoded the whole string only to base64 "myemailid:generatedapi" token and then only passing it

trupti bhatt June 19, 2019

Method :GET

https://apttusdev.atlassian.net/rest/agile/1.0/board/245/sprint?state=active

 

Authorization : Basic  <newly generated api token>
Content-Type: application/json"


Parameters : state :active

OUtput:

<status>
<status-code>401</status-code>
<message>Client must be authenticated to access this resource.</message>
</status>

Aleksandr Zuevich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2019

I've just tried at my cloud instance and it works. Please double check that email is the same as for account during generating API token. Because, for example, I have few accounts and it often confuses me.

trupti bhatt June 19, 2019

Sure. Let me check with it. 

trupti bhatt June 19, 2019

Hey Aleksandr,

 

The issue is resolved. Thanks a lot.

Aleksandr Zuevich
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 19, 2019

Great! You're welcome!

Sowndarya.R July 17, 2019

Hi Trupti, How did you resolve it ?

Like Johannes Millan likes this
Dibyendu Mondal
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 11, 2022

Hello everyone , i am facing while retriving the session key through post man , please find the details 

JIRA details: https://testinjjirademo.atlassian.net/jira/software/c/projects/QD/boards/1

URI in post man : https://testinjjirademo.atlassian.net/rest/auth/1/session

POST call

Payload body :

{"username":"my jira email","password":"my pwd"}
Response :
{
    "errorMessages": [
        "Login failed"
    ],
    "errors": {}
}

Can anyone please help me if I am doing wrong.

1 vote
Neeti Singh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 28, 2019

I also faced same problem , its resolved by simply changing the password to token : 

public static JiraRestClient getClient(){
if (instance == null){
synchronized (JiraClientNg.class) {
if (instance == null){
instance = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(URI.create("https://abcd.atlassian.net"),
"username", "API_Token_Value");
}
}
}
return instance;
}
0 votes
rafael_lopes February 12, 2020

Hi everyone,


Hi have 3 questions, because the webservice is return the error "
Basic auth with password is not allowed on this instance":


 1) The api key must be created by the user that suppose invoke the webservice?
 2) The api label must be equal to login that suppose use it?
 3) After generate the api key, we must encode in base64  the set "login:api key" and use it as header webservice attribute:
  Authorization: previous encode base64 string


  
Thanks.

Pallavi Swamy
Contributor
August 20, 2020

generating the API key is not possible in server version. can you confirm? looks like the above solution is applicable only for cloud. 

Like # people like this
Lin, Lijun August 2, 2023

I met the same error ,we useing Jira Data Center and try to call Jira API,I have tried the above solutions but doesn't work ,and turn out it doesn't aplicable to Jira Data Center. Please try to use 

`Basic ${Buffer.from('username:password').toString('base64')}` instead of 
`Basic ${Buffer.from('name@company.com:token').toString('base64')}`.
0 votes
İlhan Pamuk
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 18, 2019

we have the same problem since yesterday

trupti bhatt June 19, 2019

We also face it from yesterday.

Suggest an answer

Log in or Sign up to answer