0

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

1 Answer 1

1

@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!

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the reply, but its still not working for me.Can you please give any other suggestions?
Try with just the issuetype and by removing priority and assignee for the time being - for testing purposes!
i have tried by removing priority and assignee as well but its still not working and it's not giving any response
You were missing a space after Basic, updated my answer with this point - Please check @KavithaYeleti!
tried by giving space there as well but still it's not working
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.