“request sent by the client was syntactically incorrect” when making REST call to JIRA

I’m using HTML macros in confluence to automate some tasks in JIRA. I tried the following REST call in the code below to add a comment to a ticket and I get the error: 400: Bad Request. The request sent by the client was syntactically incorrect.

I can’t see any issues with my JSON or code. This pretty much fails for other operations I’ve tried such as creating/updating tickets. I want to do this specifically using JS and not curl or other languages.

xmlhttp = new XMLHttpRequest();
var url = "http://<CONFLUENCEURL>.com:8090/plugins/servlet/applinks/proxy?appId=<APPID>&path=http://<JIRAURL>:8080/rest/api/2/issue/TEST-3/comment";
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/json");
xmlhttp.setRequestHeader("Accept", "application/json");
xmlhttp.onreadystatechange = function () { 
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var parameters = {
    "body" : "Hello world!"

function addComment() {

I’m thinking that maybe the query string parameter values need to be encoded.

Did you manage to solve this issue?

For me the ‘GET’ calls are working as you described,

url: ‘/plugins/servlet/applinks/proxy?appId=<APP_ID>&path=<JIRA_URL_ENCODED>%2Frest%2Fapi%2F2%2Fissue%2FISSUE-123’,
type: ‘get’,
contentType: ‘application/json’,
success: function (resp) { },

but the ‘POST’ requests always fail with HTTP 400 Bad request: “The request sent by the client was syntactically incorrect”

var jiraData = {“fields”: {“project”: { “key”: “PRJ” },“summary”: “dummy”,“description”: “test”,“issuetype”: { “name”: “Task” }}}

url: ‘/plugins/servlet/applinks/proxy?appId=<APP_ID>&path=<JIRA_URL_ENCODED>%2Frest%2Fapi%2F2%2Fissue’,
type: ‘post’,
contentType: ‘application/json’,
data: JSON.stringify( jiraData ),
success: function (resp) { },

I am thinking that the JSON should be formatted/escaped somehow… any clue?
I use: JIRA v7.2.7, Confluence 6.4.3