"You are not authenticated. Authentication required to perform this operation."
Asked by Omantha Prasad:

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": {}


Answers:
author: Srikanth Ganipisetty
body: [@Dario B](/t5/user/viewprofilepage/user-id/502402) / [@Shannon S](/t5/user/viewprofilepage/user-id/510046) - 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.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/294397iBE7D09BA89E42EBD/image-size/large?v=v2&px=999 "System Proxy_Disabled.PNG")![Postman_TimeOut_Error.PNG](https://community.atlassian.com/t5/image/serverpage/image-id/294396i3890F978234A9E5E/image-size/large?v=v2&px=999 "Postman_TimeOut_Error.PNG")

comments: author: Dario B
body: [@Srikanth Ganipisetty](/t5/user/viewprofilepage/user-id/5275507) ,

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.


author: Srikanth Ganipisetty
body: Got it, thanks [@Dario B](/t5/user/viewprofilepage/user-id/502402) 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


author: Shannon S
body: 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:

* [API Tokens](https://confluence.atlassian.com/cloud/api-tokens-938839638.html)

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

comments: author: Omantha Prasad
body: 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?


author: Dario B
body: Hi [@Omantha Prasad](/t5/user/viewprofilepage/user-id/3378595) ,

Can you kindly confirm that with "API key" you mean the [API Token](https://confluence.atlassian.com/cloud/api-tokens-938839638.html) 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](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization).

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:

* <https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/>

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


author: Omantha Prasad
body: Hi Dario,

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

import requests import json

<br />

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


author: Dario B
body: Hi [@Omantha Prasad](/t5/user/viewprofilepage/user-id/3378595) ,

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](https://confluence.atlassian.com/cloud/api-tokens-938839638.html) in a python script:

* <https://community.atlassian.com/t5/Jira-questions/How-to-use-API-token-for-REST-calls-in-Python/qaq-p/760940>

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](https://community.atlassian.com/t5/image/serverpage/image-id/58689i0E464EB4E1543B00/image-dimensions/321x130?v=v2 "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](https://community.atlassian.com/t5/image/serverpage/image-id/58692i2D2DB962D6F66673/image-dimensions/385x132?v=v2 "POSTMAN-headers.jpg")

Cheers,  
Dario


author: Omantha Prasad
body: 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](https://community.atlassian.com/t5/image/serverpage/image-id/58719iE842AC0BEF6A90CF/image-size/large?v=v2&px=999 "API error.jpg")


author: Dario B
body: [@Omantha Prasad](/t5/user/viewprofilepage/user-id/3378595)

Then it can either be that you are using the wrong credentials (you can try to generate a new [API Token](https://confluence.atlassian.com/cloud/api-tokens-938839638.html) for the Atlassian Account you are using to authenticate the requests) or, as written at the bottom of the [Basic auth for REST APIs](https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/) documentation page:
>
> #### CAPTCHA {#toc-hId--714292808}
>
> 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.


author: Omantha Prasad
body: 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


author: Dario B
body: 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).


author: Omantha Prasad
body: 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


author: Dario B
body: Hi [@Omantha Prasad](/t5/user/viewprofilepage/user-id/3378595) ,

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.](https://community.atlassian.com/t5/Jira-questions/How-to-use-API-token-for-REST-calls-in-Python/qaq-p/760940)

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


author: Omantha Prasad
body: 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


author: Dario B
body: [@Omantha Prasad](/t5/user/viewprofilepage/user-id/3378595) 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?


author: Omantha Prasad
body: [@Dario B](/t5/user/viewprofilepage/user-id/502402) Using curl command I am able to get the user details.


author: Dario B
body: [@Omantha Prasad](/t5/user/viewprofilepage/user-id/3378595) then the problem is with your code and, as already mentioned, you may want to ask for help in the developers community:

* <https://community.developer.atlassian.com>


author: Omantha Prasad
body: Thanks Dario, I have created a topic in <https://community.developer.atlassian.com>

Regards,

Omantha


author: Dario B
body: You are very welcome [@Omantha Prasad](/t5/user/viewprofilepage/user-id/3378595) ! :)

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](https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-basic-authentication/) and [Oauth](https://developer.atlassian.com/cloud/jira/platform/jira-rest-api-oauth-authentication/) :

* [JRACLOUD-72405: The examples in the REST API v2 and v3 documentation pages can cause confusion](https://jira.atlassian.com/browse/JRACLOUD-72405)

Have a nice day.

Cheers,  
Dario


author: Dario B
body: [@Omantha Prasad](/t5/user/viewprofilepage/user-id/3378595) 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:

* <https://community.developer.atlassian.com/t/helpful-resources-for-developers-building-atlassian-apps/20134>

Cheers,  
Dario


author: Omantha Prasad
body: 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


author: Dario B
body: Hi [@Omantha Prasad](/t5/user/viewprofilepage/user-id/3378595) ,

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:

* [JRACLOUD-72405: The examples in the REST API v2 and v3 documentation pages can cause confusion](https://jira.atlassian.com/browse/JRACLOUD-72405)


Tags: atl-adm

cloud

confluence-cloud