See issue between jiras

Eduard Diez
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 7, 2021

Hi community. I

 

've this code to connect My JIRA with other Jira to see issue fields: And it return 401 unauthorized when I'm SITE-ADMIN. What is the problem? Thank's

 

def issueKey = 'TUR-1'

def result = get('https://myJIRA1.atlassian.net/rest/api/2/issue/' + issueKey)
.header ("Authorization", "Basic XXXXXXXXXXX-TOKEN-BY-MY-XXXXXXXXX")
.header('Content-Type', 'application/json')
.asObject(Map)
if (result.status == 200){
return result.body.fields
} else {
return "Failed to find issue: Status: ${result.status} ${result.body}"
}

1 answer

1 accepted

0 votes
Answer accepted
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 11, 2021

Hi Eduard,

I think I see the problem here.  It looks like you are trying to just pass in the API token directly in the authorization header.  This might have worked in the past with Jira Cloud, but today there is an expectation that you will use that API token along with your email address to then create a string of

user@example.com:APItoken

And then base64 encode that string.  The result encoded string is what is expected to be in that authorization header. There is also more info over in Basic Auth for REST APIs.

If you use an incorrect authorization string, it would explain why you cannot see the details of that issue as Jira tends to restrict access based upon your user permissions to view issues.

Try that and let me know if that helps.

Andy

Eduard Diez
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 12, 2021

Hi @Andy Heinzer 

 

I try put my user and my token and it not woks, I send a photo if you can help me. Thank's

Captura100.png

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 12, 2021

Yes.  You cannot just pass the email:token. Instead you need to base64 encode that string first and pass that instead.  For example if your email address was fred@example.com and your token was freds_api_token you would have a string of

fred@example.com:freds_api_token

On a linux/unix/mac you can use a command of

echo -n fred@example.com:freds_api_token | base64

The output of which would be

ZnJlZEBleGFtcGxlLmNvbTpmcmVkc19hcGlfdG9rZW4=

You need to pass that string in the authorization header so that in this case it would look something like:

.header ("Authorization", "Basic ZnJlZEBleGFtcGxlLmNvbTpmcmVkc19hcGlfdG9rZW4=")

If you are using a Windows machine, you can also find instructions on how to encode this string over in Basic Auth for REST APIs.  Try that and let me know the results.

Andy

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events