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}"
}
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
I try put my user and my token and it not woks, I send a photo if you can help me. Thank's
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.