Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do I create a Sub-Task Issue through Rest Apis

Devi Foskett January 28, 2019

I am trying to create a subtask issue creator extension. This extension should use javascript and json to create an issue when the user has clicked the button "scYes" and to just simply add labels when "scNo" is chosen.

 

Javascript

 

window.onload = function(){
document.getElementById('scYes').onclick = function() {
var project = "TENX-409"
var xhr = new XMLHttpRequest(),
method = "POST",
url = "https://jira2dev.cerner.com/rest/api/2/issue/";
var json;
xhr.open(method, url, true);
xhr.setRequestHeader("Content-Type","application/javascript");
json = JSON.parse(' {"fields": { "project": { "key": "TENX" }, "parent": { "key": "' + project + '" }, "summary": "Sub-task of TENX-409 TEST Extension", "description": "TEST", "issuetype": { "id": "5"} } } ');
console.log(json);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
console.log(xhr.responseText);

}

xhr.send();
};
}

document.getElementById('scNo').onclick = function(){
var test = ' "labels" :["Reviewed", "Technical"] ';
var myObj = JSON.parse(test);
};
}

1 answer

1 accepted

2 votes
Answer accepted
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 28, 2019

Hi @Devi Foskett

You seem to be missing the json that tells it what issue type it is

 "issuetype": {"name": "Sub-task"}

or whatever type you use as a sub-task

Suggest an answer

Log in or Sign up to answer