Reputation: 51
I want to create an issue in JIRA via REST API call in javaScript code.. When I executed the below code there is no error, but also no issue is created in JIRA. I have used the same JSON code to create issue in JIRA with "CURL" command. But I failed to create with this sample code below.Can anyone please help on this. Note: consider credentials and URL is correct.
<html>
<head>
<meta charset="ISO-8859-1">
<title>Create Issue</title>
<script type="text/javascript">
function createIssue() {
var xhttp = new XMLHttpRequest();
var createJson ='{ "fields": {
"project":{
"key": "LPS"
},
"summary": "creting issue",
"description": "creating issue from client isde",
"issuetype": {
"id": "10000"
},
"priority": {
"id": "2"
},
"assignee":{
"name": "abcd"
}
}
}';
xhttp.onreadystatechange = function() {
if ((xhttp.readyState==4) {
document.getElementById("demo").innerHTML =xhttp.responseText;
}
};
xhttp.open("POST", "URL",true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.setRequestHeader("X-Atlassian-Token", "nocheck");
xhttp.setRequestHeader('Authorization', 'Basic'+btoa('username:password'));
xhttp.send(createJson);
}
</script>
</head>
<body>
<h2>Create Issue</h2>
<button type="button" onclick="createIssue()">createIssue</button>
<p id="demo"> </p>
</body>
</html>
Regards, Kavitha
Upvotes: 0
Views: 710
Reputation: 4647
@Kavitha Yeleti, IMO using the name tag for the parent tags issuetype and priority should solve your problem considering your words that the credentials and URL are right.
I have tested creating an issue with the following JSON
and I'm able to successfully create an issue in JIRA
.
{
\"fields\":{
\"project\":{
\"key\": \"XYZ\"
},
\"summary\":\"Support Task\",
\"description\":\"Support Task\",
\"issuetype\":{
\"name\": \"Task\"
}
}
}
Alongside all these changes you need to give a space in the following line, after Basic:
xhttp.setRequestHeader('Authorization', 'Basic '+btoa('username:password'));
Hope this answers your question well!
Please do let me know if you face any further issues, so that I can update my answer with suggestions!
Upvotes: 1