Get accountID using Scriptrunner Jira Cloud

Oleksandr Melnyk April 10, 2023

Hi,

I am trying to get accountID using email.

When I use a simple REST API call with API tester - it's working fine.

But when I use scriptrunner - something goes wrong. Please help, I am new in groovy and sometimes it's hard to understand. Here is my code:

def userEmail = "oleksandr.melnyk@example.com"

def response = get('/rest/api/3/user/search?query=' + userEmail)
.header('Content-Type', 'application/json')
.asObject(Map)

logger.info('Id=' + response.body.accountId)

return response


 

 

2 answers

1 accepted

0 votes
Answer accepted
Tansu Akdeniz
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 10, 2023

Hi @Oleksandr Melnyk 

String email = "test@test.com"

def url = "https://xxxxxx.atlassian.net/rest/api/3/user/picker?query=${email}"
def response = get(url).header('Authorization', 'Basic xxxxxxx').asObject(Map)
return response.body.users.accountId[0] 
Oleksandr Melnyk April 10, 2023

Thank you! @Tansu Akdeniz 

 

String email = "test@rest.com"

def url = "/rest/api/3/user/picker?query=${email}"
def response = get(url).header('Content-Type', 'application/json').asObject(Map)
return response.body.users.accountId[0]
George Wickham
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!
July 18, 2024

Hi @Tansu Akdeniz

How would get the AccountID from a Jira Cloud single user picker custom field linked to an issue using scriptrunner or is this one for Adaptavist's Kristian Walker?

Rgds

0 votes
Amal P June 25, 2024

@Tansu Akdeniz Is there any way to get the AccountID by searching with the username instead of the email?

Suggest an answer

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

Atlassian Community Events