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


 

 

1 answer

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]

Suggest an answer

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

Atlassian Community Events