When working with Jira, there are multiple cases where a user ID (accountId) of a Jira user is needed.
For instance:
Jira put out a notice to deprecate usernames and userKeys in accordance with the Atlassian GDPR privacy principles.
The deprecation period for these changes began on 01 October 2018.
By 29 April 2019, we will remove personal data from the API that is used to identify users, such as
username
anduserKey
, and instead use the Atlassian account ID (accountId
). Additionally, will be restricting the visibility of other personal data, such as email, in conjunction with a user’s profile privacy settings.
Getting the user ID of a Jira user using Python is not a straightforward process and this blog aims to make it simple for anyone to follow.
To get started, install the Jira Python library This library is a Python wrapper around the Jira REST API, which allows you to easily interact with Jira from your Python code.
Install the library using pip:
pip install jira
With the library installed, import it into the Python script and create a Jira connection object using the basic_auth protocol.
Read more about how to create a Jira connection object.
from jira import JIRA
jira_connection = JIRA(
basic_auth=('[email protected]', 'api_token'),
server="https://server_name.atlassian.net"
)
Next, you’ll need to search for the user you want to get the ID for.
You can do this using the _fetch_pages
method of Jira library.
This method takes some arguments and returns a list of users that match the query.
Arguments needed to query for user IDs:
- Item_type: We pass the User object imported from
jira.resources
since we want to search for Jira Users. -
items_key: Path to the items in JSON returned from the server.
- Set it to None, if the response is an array and not a JSON object.
- Request_path: The path in the request URL
- Params: The parameters to use in the search query.
For example, to search for a user with the email “[email protected]“, you can use the following code snippet:
params = {
'query': '[email protected]',
'includeActive': True,
'includeInactive': False
}
list_search = jira_connection._fetch_pages(
item_type=User,
items_key=None,
request_path='user/search',
params=params
)
The above code snippet returns a list of Jira user objects, which contain information about the user, including their accountId which is the user ID we are looking for.
Sample response:
JIRA_BASE_URL: '{server}/rest/{rest_path}/{rest_api_version}/{path}'
accountId: '1234:345-678-90'
accountType: 'atlassian'
active: True
displayName: 'John Doe'
emailAddress: '[email protected]'
locale: 'en_US'
Complete code snippet:
from jira import JIRA
from jira.resources import User
jira_connection = JIRA(
basic_auth=('workspace_email', 'api_token'),
server="https://server_name.atlassian.net"
)
params = {
'query': '[email protected]',
'includeActive': True,
'includeInactive': False
}
list_search = jira_connection._fetch_pages(
item_type=User,
items_key=None,
request_path='user/search',
params=params
)
jira_user_id = list_search[0].accountId # get first user,since email is unique
See the code in action:

And that’s it! You now have the user ID of the Jira user you were searching for. You can use this ID to perform various actions on the user, such as assigning them an issue or adding them as watchers to relevant tickets e.t.c.
I hope this blog has made it easier to get the user ID of a Jira user using Python. If you have any questions or need further assistance, don’t hesitate to comment below.
Happy automating!