Work with Users

With HAPI, we've made it easy for you to work with users. 

Retrieve users from Jira and use in scripts

In Jira Cloud, APIs discourage the use of personal information, so account IDs are used to reference users.

You can look up user account IDs in Jira using the user directory page, which can be found at https:<your-domain>.atlassian.net/people

groovy
def user = Users.getByAccountId('613b226ac425a20068240gpp').displayname()

Get the current user

You can work with role memberships as follows:

groovy
def user = Users.getLoggedInUser() Issues.getByKey('TEST-1').update { setAssignee(user) }

Get user email address

You can get a user's email address as follows:

groovy
def userMail = Users.getByAccountId('user_account_id').getEmailAddress()

Users must allow their email address to be visible to 3rd parties.

Work with group membership

You can work with group memberships as follows:

groovy
//get Groups where the user is a member User user = Users.getLoggedInUser() user.groups //check if a user is a member of a group Groups.getByName('org-admins').contains("613b226ac425a20068240gpp") //alternatively, you can pass a User to the check Groups.getByName('org-admins').contains(user)

Related content

On this page