JIRA Rest API API error. Unidentified token creating a problem

Unable to add issue via AJAX and REST API. I can get it to work with Postmen, unfortunately, cannot get it with an Ajax request.

The JSON that I create is OK, and the submit request. The issuetype type is what I created myself, using Bug gives the same problem. See JSON object created, my error and my code: JSON object (this is a fragment from console.log):

snippet from the console. (I do console.log (jira)

Error

0: "Unrecognized token" fils5poet5 ": expected" null "," true "," false "or NaN↡ in [Source: org.apache.catalina.connector.CoyoteInputStream@7b958ed2 ; line 1, column: 21]"

jira = { fields : { project : { key : "CIC" }, summary : "test", description: "test", issuetype : { name : "Sandbox item" } } }; console.log(jira); //Also see image at top of this post. // Submit to Jira api $.ajax({ type : "POST", dataType : "JSON", url : configuration.api_url, beforeSend: function (xhr) { xhr.setRequestHeader ("Authorization", "Basic ItsAWrap!(itworks...)"), xhr.setRequestHeader ("Content-Type", "application/json"); }, data : jira, success : (function(response) { //Do something }}) 
+5
source share
2 answers

You can try something like this:

 jira = { "fields": { "project": { "key": "CIC" }, "summary": data["story.name"], "description": data["story.notes"], "issuetype": { "name": "Sandbox item" } } }; //THIS BADASS FUNCTION!!! jira = JSON.stringify(jira); $.ajax({ type : "POST", url : configuration.api_url, dataType : "JSON", async : false, headers: { "Authorization": "Basic YeahSomethingInAWrap", "Content-Type": "application/json", "Accept": "application/json", "Cache-Control": "no-cache" }, data : jira, success : (function(response) { // Hide loader l.removeClass("show"); // Alert Success Message alert("Melding succesvol ontvangen, bedankt!"); // Close dialog $(".chrome-extension-dialog a.close").trigger("click"); }) }); 
+2
source

You need JSON.stringify your jira variable before submitting.

+4
source

Source: https://habr.com/ru/post/1210538/


All Articles