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

Marcelo Riveiro May 6, 2019

We were using this script to make BACKUP from linux, but about 1 month ago it fails with these error:

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

 

(PART OF SCRIPT)

COOKIE_FILE_LOCATION=jiracookie
curl --silent --cookie-jar $COOKIE_FILE_LOCATION -X POST "https://${INSTANCE}/rest/auth/1/session" -d "{\"username\": \"$USERNAME\", \"password\": \"$PASSWORD\"}" -H 'Content-Type: application/json' --output /dev/null


BKPMSG=$(curl -s --cookie $COOKIE_FILE_LOCATION -H "Accept: application/json" -H "Content-Type: application/json" https://${INSTANCE}/rest/backup/1/export/runbackup --data-binary '{"cbAttachments":"true"}' )

Can you help me?

 

 

8 answers

1 accepted

6 votes
Answer accepted
edwin
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.
May 6, 2019

Hi @Marcelo Riveiro ,

Authentication with username and password is deprecated. You'll have to create and use API tokens

Deprecation notice - Basic authentication with passwords and cookie-based authentication

Marcelo Riveiro May 8, 2019

Thanks for the response and help.

7 votes
Chintan S Soni July 15, 2019

I changed my way to call API and now i am using token instead of password. But still i am getting 401 issue "Client must be authenticated to access this resource".

4 votes
Thomas Fozzi December 18, 2019

Try like this:

1) encode the string

"username:password" 

with Base64

2) add the header

"Authorization: Basic <encoded string>" 

to your cUrl command

marcelo January 22, 2020

This works for me, thanks Thomaz.

Like Thomas Fozzi likes this
marcelo January 30, 2020

Actually works just for one account, the other account that seems to have the same permissions i get 401 again, using token also.

Thomas Fozzi January 30, 2020

Have you tried loggin to Jira on the browser with the second account, using exactly the same username and password you're using on cUrl?

Also consider that in case you change the password you must regenerate the API token.

Thomas

Like marcelo likes this
marcelo January 31, 2020

Thanks Thomas, you're right, it was my mistake changing the token id's between all accounts.

1 vote
Karl Samson November 18, 2021

Hi, we are using Tokens and Crowd to authenticate Username and password, basically semi SSO sign in, and we are getting this same error message when we try to project a Big Picture schedule Gadget on a Confluence page!? Any ideas on how to fix this would be greatly appreciated!!

1 vote
Alec Jasanovsky November 18, 2019

Also experiencing this issue - even though i'm using a token. 

1 vote
ji wenhao November 3, 2019

Just like what @Chintan S Soni said, I found the same problem when I call API by using api token without password. Please do me a favor!

0 votes
Karl Samson November 18, 2021

Moved to latest thread!

0 votes
David Witkowski November 22, 2019

Same issue here!

Marcelo Riveiro November 22, 2019

This way it is working

BKPMSG=$(curl -s -u ${USERNAME}:${API_TOKEN} -H "Accept: application/json" -H "Content-Type: application/json" --data-binary '{"cbAttachments":"true"}' -X POST https://${INSTANCE}/rest/backup/1/export/runbackup )

Suggest an answer

Log in or Sign up to answer