It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

how to solve "{"message":"Client must be authenticated to access this resource.","status-code":401}"

I know that it was discussed before, but I don't see any solution for this error :

{"message":"Client must be authenticated to access this resource.","status-code":401}% 

I'm not working with UI ( User Interface) and I am working from backend, I want to authenticate myself (my users) to be able to run some API call.

 

I want to run this code :

curl --request GET \
--url 'https://MYSITE.atlassian.net/rest/api/3/applicationrole' \
--header 'Accept: application/json'

or in python :

import requests
import json
url = "https://MYSITE.atlassian.net/rest/api/3/applicationrole"
headers = {
"Accept": "application/json"
}
response = requests.request(
"GET",
url,
headers=headers
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

 

But I'm getting this error :

 

{"message":"Client must be authenticated to access this resource.","status-code":401}% 

 

the question is how to authenticate it before or at same time (in same line) ?

3 answers

1 vote
Nir Haimov Community Leader Apr 23, 2019

Hi @Maziar Sojoudian ,

of course you are getting 401, there is no authentication header in your request.

I know you said username:password is not working anymore, but it does... so maybe you did something wrong.

Note that username:password need to be encoded in base64, so for example:

useradmin:passadmin = "dXNlcmFkbWluOnBhc3NhZG1pbg==" (and this is what you need to put in your authentication header).

 

You said you are working with python, so your request should be like that:

import requests

url = "https://MYSITE.atlassian.net/rest/api/latest/........."

payload = ""
headers = {
'Authorization': "Basic dXNlcmFkbWluOnBhc3NhZG1pbg=="
}

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)

@Maziar Sojoudian 

Hi Maziar

 

did you already have a look to the https://developer.atlassian.com/server/jira/platform/basic-authentication/

there is explained how to use Basic Auth etc.


curl -u username:password -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/issue/createmeta

 Cheers

Kurt

Hello Kurt,

 

Can I bind these two together ?

 

(And if you are not aware of that, (just saying) username:password is not working any more)

@Maziar Sojoudian 

 

Either you use username:password and if that does not work you can use a token based approach

https://confluence.atlassian.com/cloud/api-tokens-938839638.html

 

see also the answer from Nir

 

Cheers

Kurt

I"m using the Basic authentication, but it looks like the response depends on the URL (i.e. the resource) I'm using..

Does anybody knows if I can use the same credentials I use to access Jira Service Desk or do I need to create a special user for API access?

Do I need to provide the user with special access privileges?

Does also the "expansion" of the JSON response depends on the user privileges?

 

Cheers,

Thomas

did you find the answer? 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you