If you are a user of Jira, you are probably aware of the assignee function, which allows you to set the assignee to specific users within your team.
Setting assignees is a great way to keep track of who is responsible for a task and ensure that tasks are completed on time.
But how can this process be automated using Python?
Fortunately, Jira provides a Python library called Jira-Python that allows you to easily interact with the Jira API and perform multiple actions, including setting an assignee on a task.
This blog post will go over the steps involved in setting an assignee on a Jira ticket using Python. A working code snippet shall be provided as a starting point for all your automation needs.
First, install the Jira library using pip; pip is the easiest way to install python libraries.
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, retrieve the issue that you want to assign to a user by using the issue()
method and providing the issue key:
issue = jira_connection.issue("PROJ-123")
After retrieving the issue, use the update()
method to set the assignee by providing the User ID of the user to assign the ticket.
Read more about how to retrieve the accountId of a Jira user.
fields = {"assignee": {"accountId": jira_user_id}}
issue.update(assignee=fields["assignee"])
The Jira task will now be assigned to the specified user.
Below is a complete code snippet that shows how to set an assignee on a Jira task using Python:
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("PJH-1")
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
fields = {"assignee": {"accountId": jira_user_id}}
issue.update(assignee=fields["assignee"])

Often, one can run into the error: python jira field assignee cannot be set
Ensure that you are using the accountId property and not a username or an email since these credentials can no longer be used to manipulate Jira tickets.
{"accountId": jira_user_id}
We hope that this blog post has provided some valuable and practical information on how to set an assignee on a Jira task using Python.
With the Jira-Python library, you can easily automate this entire process and save time and effort in managing your Jira tasks.
Happy automating!