I've been trying to get the email of a Jira user other than my own with the Python3 Jira library, but couldn't do it. It either gives me an error, saying I don't have enough permissions to get it, or only returns me simple information, like display names. Here's my code:
from jira import JIRA
conn = JIRA(
options={"server": "https://example.atlassian.net"},
basic_auth=("[email protected]", TOKEN),
)
conn.user(id='my_id').emailAddress # Returns my email and more information
conn.user(id='another_user_id').emailAddress # Doesn't return his email
How could I get someone's email? And what kind of permissions could I need?
To access another user's email in Jira, you'll need to have the "View User" permission in Jira. You can check this by navigating to the Jira administration page, clicking on Users, and checking the permissions for the user you want to access. If you do not have the "View User" permission, you will not be able to retrieve the email address of another user.
If you do have the "View User" permission, but still cannot retrieve the email address, you could try the following code:
from jira import JIRA
conn = JIRA(
options={"server": "https://example.atlassian.net"},
basic_auth=("[email protected]", TOKEN),
)
user = conn.user(id='another_user_id')
email = user.emailAddress
print(email)
Note that the emailAddress property is only available in Jira versions 7.3 and later. If you're using an earlier version of Jira, you may need to upgrade to access this property.