I would like to be able to add labels to a Jira using rest apis. I am using javascript currently to create an issue. I do not know the json required to create the label and need help figuring that out. I use only javascript and json for this thank you! When using postman there is a 415 error when I add "Labels":["Test"] to create a label.
Javascript:
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.setRequestHeader("Content-Type","application/json");
labels = ' {"fields": { "project": { "key": "'+ projectKey +'" }, "labels":["sd_reviewed", "ta_reviewed", "Reviewed", "Functional"]}} ';
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status == 200) {
console.log(xhr.responseText);
}
};
xhr.send(labels);
Reposting cause my edit dissapeared (?)
Endpoint: https://YourJiraInstance.com/rest/api/2/issue/issue-id-right-here
Body: {"update":{"labels":[{"add":"this-is-the-label-you're-adding"}]}}
POST method, basic AUTH
Thanks, this was very helpful!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Works with this payload, using PUT method as Warren mentions below.. Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Per REST API Doc (https://docs.atlassian.com/software/jira/docs/api/REST/8.22.4/#issue-editIssue) the syntax is:
"labels":[{"add":"triaged"},{"remove":"blocker"}]}
In your case, I believe it would be:
"labels":[{"add":"sd_reviewed", "ta_reviewed", "Reviewed", "Functional"}]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
nope...
This one works:
{ "update": { "labels": [ { "add": "lable1" }, { "add": "label2" } ] } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
PUT method.
/rest/api/3/issue/{issueIdOrKey}
{
"update": {
"labels": [
{
"add": "bump1"
},
{
"add": "no_sf_case_id"
}
]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As of now I thought the only way you can create labels is by passing the issue key and then adding a label against the issue key. If you do not use an issue the api will not work. Has anyone solved this by being able to create labels without reference to an issue key?
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.
Hi @Fadi Hawli ,
as per my understanding the label concept in JIRA is different from what you expect.
You expect labels to be an independent entity in JIRA, like components or versions.
In fact labels just exist as an attribute of an issue. When you remove a label from all the issues the label is gone and cannot be found anywhere.
That explains why it is mandatory to provide an issue key.
Hope this helps, Roman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Within the JSON, this is the format of adding a label
"labels": [
"Testing"
]
Hope this helps you
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.
@Warren I have tried the code mentioned above with no avail. If you would like to see code to better understand what I am trying to accomplish I can add it above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you trying to
What error do you get using your javascript?
Below is what my JSON looks like to create an issue and set it's label
{
"fields": {
"project": {
"key": "DS"
},
"summary": "Post Refresh work",
"issuetype": {
"name": "Task"
},
"labels": [
"Label1",
"Label2"
]
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Warren I am trying to add labels to an existing project. With the code you provided I get a status error 400.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you look at this you'll see you need to do a PUT if you're updating an existing issue. Is that what you've been using?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.