Hello all,
Based on my research so far, I see that there is a way to append one label at a time to an existing issue, or you can also update multiple labels on an existing ticket, but that will then remove any existing labels the issue had originally. I'm looking for a way to append multiple labels to an existing issue, without removing any labels that already exist. I'm looking to do this within one API request. Any ideas if this is possible?
What I'm working with:
Appreciate any insight!
@Carlye Petoff Here is the latest REST API documentation so you know how to properly form your edit call. https://developer.atlassian.com/cloud/jira/platform/rest/v3/api-group-issues/#api-rest-api-3-issue-issueidorkey-put You will need to use the labels ADD to not remove any of the existing labels.
Hi @Carlye Petoff ,
Both, @Brant Schroeder and @Nicolas Grossi , are correct and there answers point to the right direction.
But I just could not pass up the opportunity to help in a label-related topic and write some Python code for fun. So, here you go, a quick example written by someone who hasn't done Python in ages:
import requests
from requests.auth import HTTPBasicAuth
def addLabels(baseUrl, user, apiKey, issueKey, labels):
"Add multiple labels to an issue"
auth = HTTPBasicAuth(user, apiKey)
url = baseUrl + "/rest/api/3/issue/" + issueKey
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = """{
"update": {
"labels": [
"""
for label in labels:
payload = payload + "{\"add\": \""+ label+ "\"},"
payload = payload[:-1] + "]}}"
response = requests.request(
"PUT",
url,
data=payload,
headers=headers,
auth=auth
)
return response.status_code
print(addLabels("https://YOURCOMPANY.atlassian.net", "YOUR_EMAIL", "API_TOKEN", "ISSUE-58", ["label_1", "label_2", "label_3"]))
Hope that helps,
Oliver
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks all. I appreciate the responses. I figured out what I was doing wrong with the syntax:
If you want to add multiple labels without removing any of the existing labels, you should format like this:
payload = json.dumps({ "update": {"labels": [{"add": "label1"}, {"add":"label2"}, {"add":"label3"}, {"add":"label4"}]}})
Originally I was doing this, which is incorrect:
payload = json.dumps({ "update": { "labels" : [{"add":"label1", "label2", "label3"}] }})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.