Forums

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

unable to create issue in jira through jira rest api in javaScript

Kavitha Yeleti March 8, 2018

Hi,

I want to create an issue in JIRA via REST API call with 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 and it worked succesfully. 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": {
                          "name": "Task"
             },
             "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>

 

1 answer

1 vote
Alexey Matveev
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.
March 8, 2018

What do you mean that there is no error? Do you get 200 status code? If there is no error then you should get the key of the created issue.

Kavitha Yeleti March 9, 2018

Hey, Am not getting any response from the server and the issue is not getting created in JIRA

Alexey Matveev
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.
March 9, 2018

If you make a request to a server then you must get a response. Try to use Developer Tools in your browser.

Kavitha Yeleti March 9, 2018

not sure why its not responding and i could add the comment and edit the existing fields of an issue with the same sample code but only this one(creating issue) is not working

Kavitha Yeleti March 9, 2018

It worked for me, its a syntax error. Thank you!

Karthigaipreethi karuppanan
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 30, 2021

Can you share the updated code. Am also trying to update JIRA issues using javascript.. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events