How to Authenticate for Get user account with REST API

serge calderara
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.
March 11, 2021

Dear all,

I am trying to get information about a user account from a UserPicker custom field

For that I have a custom field User Account available and I am able to retrive its information as seen below :

{self=https://host.atlassian.net/rest/api/2/user?accountId=5c0f8b8c3acad8551c338a8f, accountId=5c0f8b8c3acad8551c338a8f, avatarUrls={48x48=https://secure.gravatar.com/avatar/2a8975f9d7252b7640b127c1e6846f2f?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FSC-6.png, 24x24=https://secure.gravatar.com/avatar/2a8975f9d7252b7640b127c1e6846f2f?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FSC-6.png, 16x16=https://secure.gravatar.com/avatar/2a8975f9d7252b7640b127c1e6846f2f?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FSC-6.png, 32x32=https://secure.gravatar.com/avatar/2a8975f9d7252b7640b127c1e6846f2f?d=https%3A%2F%2Favatar-management--avatars.us-west-2.prod.public.atl-paas.net%2Finitials%2FSC-6.png}, displayName=Tom smith, active=true, timeZone=Europe/Zurich, accountType=atlassian}"

when I am running the first call inside Script runner console, I am running is as Current user which is my Admin account

Then from that account information, I need to retrive the user email. For that I was using the following code below :

String userAccountId=issuefields[customFieldObject.id].accountId

def user = get('/rest/api/2/user?accountId=$userAccountId')
.header('Content-Type', 'application/json')
.asObject(Map).body
// return issuefields
return user

Please note that the variable userAccountId is containing correct account value 5c0f8b8c3acad8551c338a8f

When I am executing this request, I get the following error :

{errorMessages=[Specified user does not exist or you do not have required permissions], errors={}}"

 

Any idea what I am doing wrong as the account is existing and the script is executing as current user which as Admin write.

Do I need to authenticate differenly for that user endpoint ?

Thanks for help

regards

0 answers

Suggest an answer

Log in or Sign up to answer