If you are working on a project in Jira and want to add a watcher to an issue, you can use the Jira Python library to accomplish this task quickly and efficiently.
There are several benefits to using watchers in Jira:
- Improved visibility: By adding watchers to an issue, you can ensure that all relevant stakeholders are kept informed about its progress. This can help prevent misunderstandings and improve communication among team members.
- Enhanced collaboration: Watchers can facilitate collaboration by allowing multiple people to stay updated on an issue. This can be especially useful for large projects with many team members.
- Better accountability: When multiple people are watching an issue, it can create a sense of responsibility and encourage team members to stay on track and meet their deadlines.
- Enhanced transparency: By allowing anyone to see who is watching an issue, Jira helps promote transparency within an organization. This can help build trust and foster a culture of healthy collaboration and teamwork.
First, you need to have the Jira Python library installed on your system. You can install it using the following command:
pip install jira
Once the library is installed, import it into the Python script and create a Jira client instance using the following code:
from jira import JIRA
jira_connection = JIRA(
basic_auth=('workspace_email', 'api_token'),
server="https://<server_name>.atlassian.net"
)
Replace “https://<server_name>.atlassian.net” with the URL of your Jira instance, and “workspace_email” and “api_token” with your workspace email and API token respectively.
Next, retrieve the issue want to add a watcher.
issue = jira_connection.issue("PROJECT-123")
Replace “PROJECT-123” with the key of the issue to add a watcher.
If the Jira project is new with no Jira tickets, learn how to create a Jira ticket with python.
With the issue object, use the add_watcher
method to add a watcher. The method takes the userID to be added as a watcher. See the section below on how to retrieve a user ID.
Here is an example:
jira_connection.add_watcher(issue, "userID")
How to get Jira user ID to add a watcher?
Jira put out a notice to deprecate usernames and userKeys:
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.
Therefore to add a watcher, we have to fetch the userIDs using user emails.
Read more about how to retrieve the accountId of a Jira user.
Code snippet to fetch user ID:
from jira.resources import User
params = {
'query': '[email protected]',
'includeActive': True,
'includeInactive': False
}
list_search = jira_connection._fetch_pages(
User, None, 'user/search', params=params
)
jira_user_id = list_search[0].accountId # get first user,since email is unique
Replace [email protected]
with the correct user email.
That’s it!
A watcher has been added to an issue in Jira using Python!
Below is the complete code snippet to add a watcher to an issue, use this code snippet as a starting point, and modify it to fit your needs and requirements.
from jira import JIRA
from jira.resources import User
jira_connection = JIRA(
basic_auth=('workspace_email', 'api_token'),
server="https://<server_name>.atlassian.net"
)
issue = jira_connection.issue("PROJECT-123")
params = {
'query': '[email protected]',
'includeActive': True,
'includeInactive': False
}
list_search = jira_connection._fetch_pages(
User, None, 'user/search', params=params
)
jira_user_id = list_search[0].accountId # get first user,since email is unique
jira_connection.add_watcher(issue, watcher=jira_user_id)

In conclusion, adding watchers to a Jira ticket is a useful way to keep track of the progress of a Jira issue and ensure that all stakeholders are kept informed.
By using the “Add Watchers” feature, users or groups can be added to follow the ticket and receive notifications whenever there are any updates.
Overall, adding watchers is a simple but powerful way to improve the efficiency and effectiveness of the Jira workflow.
Happy coding!