How to add labels and assign ticket which creating the jira ticket using python
I tried with other fields and I was able to add it, but labels and assigning of the ticket is not working...
Hi,
I see that you are looking to add labels to an issue in Jira, but I am unclear on a couple of details that might affect the answer here. You mentioned using python here, are you using python to make a REST API call to Jira? Could you also let me know if this is a Jira Cloud or Jira Server site?
The labels field is different from most other fields in Jira. The reason being that this field can simultaneously hold multiple values. This requires that field to hold it's values in an arrary instead. You can see this in the example curl of the Jira Cloud REST API PUT /rest/api/2/issue/{issueIdOrKey} endpoint. From the python example there:
"labels": [ { "add": "triaged" }, { "remove": "blocker" } ]
This example is adding the triaged label, while also removing the blocker label from that issue.
As for assigning issues, this is something that has become trickier to do in Jira Cloud via REST. This is because you can no longer assign issues with just the username/email address of the user account. Instead you first need to know the accountId of that user and use that value. This requirement is noted in the Assign issue endpoint of PUT /rest/api/2/issue/{issueIdOrKey}/assignee (although you could potentially assign the issue via the other endpoint above. If you don't know the accountId, I would recommend using the Find users and groups as a means to look this up. It let's you make a REST API query and submit the user's name or email and in turn it can return to you that accountId.
If you're not using Jira Cloud, but Jira Server, you should still be able to assign the issue just using the username of that account.
Let me know if you run into any problems with this.
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.