Illegal unquoted character error when using REST API example

Esther Strom March 19, 2019

I'm trying to create a new issue using the PHP example in the API docs. I've copied the code pretty much exactly; just edited a few field names. But I keep getting this error from curl:

Response from creating abc123: {"errorMessages":["Illegal unquoted character ((CTRL-CHAR, code 13)): has to be escaped using backslash to be included in string value\n at [Source: org.apache.catalina.connector.CoyoteInputStream@2173bded; line: 10, column: 42]"]}


Here's my code; can anyone help me out here? 

 

<?php
$vId = "abc123";
$body = <<<REQUESTBODY
{

"fields": {
"summary": "WhiteHat: test",
"issuetype": {
"id": "10041"
},
"customfield_10104": "$vId",
"customfield_10105": "5",
"customfield_10107": "www.mysite.com,
"customfield_10108": "www.mysite.com/register",

"project": {
"id": "10037"
},
"description": "Testing creation",
"reporter": {
"name": "Jira Monkey"
},

"environment": {
"type": "doc",
"version": 1,
"content": [
{
"type": "paragraph",
"content": [
{
"text": "environment",
"type": "text"
}
]
}
]
}
}
}
REQUESTBODY;

$ch = curl_init();
$url = "https://mysite.atlassian.net/rest/api/3/issue";


$headers = array(
"Content-Type:application/json",
"Accept:application/json",
"Authorization: Basic <my_key>"
);

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch,CURLOPT_POSTFIELDS, $body);

//execute post
$result = curl_exec($ch);
$array = json_decode($result,TRUE);
error_log("+++Response from creating $vId: " . print_r($result, 1));
curl_close($ch);

1 answer

1 accepted

0 votes
Answer accepted
Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 20, 2019

Hi @Esther Strom

in general I'd recommend you to ask these type of questions in the developer community - there's a higher chance that another developer looks at it.

Having said that, you might want to check this line:

   "customfield_10107": "www.mysite.com,

It looks like you missed a quotation mark at the end. If it still fails, I suggest to strip down your example to the bare minimum like project and summary (or other required fields you have).

Good luck,
Matthias.

Esther Strom March 20, 2019

Thanks. The missing quote was due to some stuff I stripped out to post here; it's correct in my code. I did post on the developer community site; I wasn't aware that existed.

Like Asia DevOps Team likes this

Suggest an answer

Log in or Sign up to answer