Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

M S April 23, 2019

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

2 votes
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 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)

1 vote
Thomas Fozzi
Contributor
December 18, 2019

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

Judith Bryham Campos
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 16, 2020

did you find the answer? 

0 votes
Kurt Klinner
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.
April 23, 2019

@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

M S April 23, 2019 edited

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)

Kurt Klinner
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.
April 24, 2019

@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

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, atlassian government cloud, fedramp, webinar, register for webinar, atlassian cloud webinar, fedramp moderate offering, work faster with cloud

Unlocking the future with Atlassian Government Cloud ☁️

Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.

Register Now
AUG Leaders

Upcoming Jira Events