"You are not authenticated. Authentication required to perform this operation."

Omantha Prasad June 21, 2019

I am using API v3 to get users via pythn script, I am getting following error when I run the

Python code 

import requests, json

# Jira URL url = "https://server.atlassian.net/rest/api/3/user"
headers = { "Accept": "application/json" "Bearer": "xxxxx"
}
response = requests.request( "GET", url, headers=headers)
#Print request outputprint(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

Error message

{
"errorMessages": [
"You are not authenticated. Authentication required to perform this operation."
],
"errors": {}

2 answers

0 votes
Srikanth Ganipisetty
Contributor
November 29, 2023

@Dario B / @Shannon S - I am getting Time out error in the Postman when I hit any request for our new Jira Cloud Instance. I got this proxy error at first and then I followed some online articles to disable it and now I am receiving the time out errors. I tried to increase the Timeout in ms but that didn't helped to pull the data using REST API Call. 

Please look into this. Error: 


GET https://XXXX.atlassian.net/rest/api/3/issue/ST-1: {
"Error": "ETIMEDOUT",
"Request Headers": {
"authorization": "Basic c2c2ODA1NUBjaXRpZGV2Lm5ldDpBVEFUVDN4RmZHRjBLSWpFWHR5aUdOZWtmTTNDbkJXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX,
"user-agent": "PostmanRuntime/7.29.0",
"accept": "*/*",
"postman-token": "5cd3e03b-162e-4349-XXXX-03eb2acab8501",
"host": "XXXXX.atlassian.net",
"accept-encoding": "gzip, deflate, br",
"connection": "keep-alive"
}
}


System Proxy_Disabled.PNGPostman_TimeOut_Error.PNG

Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 29, 2023

@Srikanth Ganipisetty ,

Please notice you are adding a reply to a thread from almost 5 years ago about something totally different.

The issue you are reporting does not seem to have anything to do with Jira but looks related to the proxy you have configured on your machine and you may want to check this with your IT team. 

Srikanth Ganipisetty
Contributor
November 29, 2023

Got it, thanks @Dario B  Please suggest if you want me to start a new thread instead. I thought the above relates to my issue and take your expertise to run the 1st call on our Jira Cloud POC app.

1. I have turned off the proxy as per the Stack Overflow suggestions and then the time-out is occurring. Do you know any way that I can trouble-shoot myself before I reach to the IT Team since it's related to Time -out now. 

2. When I ran the script in Script runner to do in the other way for the same rest call (creating a user), It is asking me to authenticate first on JIRA Cloud, where as it didn't asked me to authenticate for creating a Story in a project using the same POST Method. and as you see it failed for GET call too in the 1st comment

Thanks,

Srikanth Ganipisetty 

0 votes
Shannon S
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 24, 2019

Omantha,

Welcome to Atlassian Community. It's great to have you!

Could you let me know how you are authenticating to the API? In Cloud, you need to have generated a token:

Basic authentication with a password will not work in Cloud. This is a change within the last few months, so if your API call was working before, this might be the reason why it's no longer working.

Regards,

Shannon

Omantha Prasad June 24, 2019

I have passed the API key which I generated from my JIRA cloud account, what would be the alternative option to if this no longer works on the cloud. 

 

According to API v3 document above code should work if not how can I use API for cloud JIRA account.

https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-user-get

What authentication is supported?

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

Hi @Omantha Prasad ,

 

Can you kindly confirm that with "API key" you mean the API Token you generate from https://id.atlassian.com/manage/api-tokens ?

 

If this  is the case, then your request is failing because you are using Bearer authentication in your script instead of Basic authentication with API Token.

For example, if you are using an API Token to authenticate your calls, in your code you should use:

headers = { "Accept""application/json" "Authorization""Basic xxxxx"}

Where xxxxx is the string email-address:api-token encoded in base64. For further details on this and for examples please review:

 

Finally: 

  1. The provided code snippet looks like it is not going to work in any case since the header should be: "Authorization""Bearer xxxxx" and not "Bearer" : "xxxxx"
  2. if you don't use the API Token but anything else in order to authenticate your REST API requests please provide more details

 

I hope this helps.

 

 

Cheers,
Dario

Omantha Prasad June 25, 2019

Hi Dario,

Now I am able to pass, but I am getting Unauthorized (401) when its printing with the code.

import requests import json


url = "https://xxxxxx.atlassian.net/rest/api/3/user"
headers = { "Accept": "application/json" , "Authorization": "Basic xxxxxx" } response = requests.request( "GET", url, headers=headers )

print(json.dumps(json.loads(response), sort_keys=True, indent=4, separators=(",", ": ")))

 

Thank you,

Omantha

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

Hi @Omantha Prasad ,

Before going any further, you may want to have a look at the sample code in the following thread that shows how to authenticate REST API calls using API token in a python script:

 

Then, in case above thread does not help, I have to ask for more details since I am not sure I understand below statement:

Now I am able to pass, but I am getting Unauthorized (401) when its printing with the code.

Specifically:

  1. What do you mean with "I am able to pass"?
  2. Are you still getting status code 401 or not?
  3. Can you copy-paste the error message in here?

 

Also, it would be a good idea to double check you are using the right credentials by authenticating the same REST API call in e.g. POSTMAN and compare the authorization header in there:

1) Enter the credentials and the url in postman:

POSTMAN-credentials.jpg

2) Execute the request (click on "Send").

3) Once getting the response switch to the "Headers" Section and compare the authentication header generated by Postman with the one you use in your code:

POSTMAN-headers.jpg

 

 

Cheers,
Dario

Like Lisa Segura likes this
Omantha Prasad June 25, 2019

I am still getting same error message when I tried through Postman as well.

Error message: <html>

<head>
<title>Unauthorized (401)</title>
a

API error.jpg

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

@Omantha Prasad 

Then it can either be that you are using the  wrong credentials (you can try to generate a new API Token for the Atlassian Account you are using to authenticate the requests) or, as written at the bottom of the Basic auth for REST APIs documentation page:

CAPTCHA

A CAPTCHA is 'triggered' after several consecutive failed log in attempts, after which the user is required to interpret a distorted picture of a word and type that word into a text field with each subsequent log in attempt. If CAPTCHA has been triggered, you cannot use Jira's REST API to authenticate with the Jira site.

You can check this in the error response from Jira -- If there is an X-Seraph-LoginReason header with a a value of AUTHENTICATION_DENIED, this means the application rejected the login without even checking the password. This is the most common indication that Jira's CAPTCHA feature has been triggered.

Omantha Prasad July 1, 2019

Hi Dario,

 

Thank you for the reply. I am still not able to retrieve information. Do you have any API guide which support Jira Cloud tanets?

 

Not authenticating even a curl command,

curl --request GET \ --url '/rest/api/2/user/bulk' \ --header 'Authorization: Bearer ' \ --header 'Accept: application/json'

 

Thanks,

Omantha

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

The above curl command cannot possibly work: there are no credentials, no instance url and it is still setting the header for bearer authentication that we do not support.

Can you kindly try the below one replacing <email_address> and <api_token> with the correct values for your Atlassian Account and <hostname> with your instance hostname (e.g. something.atlassian.net):

curl -D- -u <email_address>:<api_token> -X GET https://<hostname>/rest/api/2/project

If everything goes fine the above call will return the list of all the projects the Atlassian Account you used to authenticate the REST API call has access to (plus, the -D- option will print the full response header).

Please execute above call and, in case it does not work, paste the output in your reply (masking the sensitive data).

Omantha Prasad July 3, 2019

Hi Dario,

 

With the curl command I get Response 200, seems authentication is correct, also do you have working python script to get all users from Jira account?

 

Thanks,

Omantha

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

Hi @Omantha Prasad ,

You may want to search the community for existing code snippets provided by other users like the already provided: How to use API token for REST calls in Python.

In case of no success, you may also want to ask this question in the developers' community at: https://community.developer.atlassian.com

 

Cheers,
Dario

Omantha Prasad July 3, 2019

Hi Dario,

 

I have tried acording to the API v3 document, now the error code is difference than earlier.

 

Earlier I got 401, 404, now I am getting 500 error. Internal Server error.

Error:

<Response [500]>
{
"errorMessages": [
"Internal server error"
],
"errors": {}

 

Code I tried --
https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-users-search-get

Thanks,

Omantha

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

@Omantha Prasad In above post I don't have enough information to be possible able to help you. 

Is this working using curl or you get the same error in there as well? 

Omantha Prasad July 3, 2019

@Dario B Using curl command I am able to get the user details. 

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

@Omantha Prasad then the problem is with your code and, as already mentioned, you may want to ask for help in the developers community:

Omantha Prasad July 3, 2019

Thanks Dario, I have created a topic in  https://community.developer.atlassian.com

 

Regards,

Omantha

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

You are very welcome @Omantha Prasad ! :) 

Also, just FYI, I have created the below request to have the examples in the REST API documentation fixed since they may cause confusion between Basic Authentication  and Oauth :

Have a nice day.

 

Cheers,
Dario

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

@Omantha Prasad  quick check, have you actually changed your code to use Basic auth instead of Bearer authentication? 

Looking at the originally provided code the issue might be there.

For the rest, in the below post are listed all the resources you can contact in order to get help on development related questions:

 

Cheers,
Dario

Omantha Prasad July 4, 2019

Thanks Dario,

I manage to get the content using following code. 

 

response = requests.get("https://domain.atlassian.net/rest/api/3/users/search", auth=('username', 'API xxxxxx'))

 

Bear token does not work.

 

Regards,
Omantha

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

Hi @Omantha Prasad ,

Happy to know this is solved. Also, you can find the explanation on why the Bearer authentication header does not work in the below documentation request I have created:

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events