I'm trying to post data to a JIRA REST API but I get a blank response back. The code sits in two files. Here's the code located on the jira.json file:
{
"fields": {
"project":
{
"id": "19600"
},
"summary": "REST ye merry gentlemen.",
"description": "Creating of an issue using project keys and issue type names using the REST API",
"issuetype": {
"name": "Task"
}
}
}
and the php code:
<?php
$jsondata = file_get_contents("jira.json");
$json = json_decode($jsondata,true);
//print_r($json);
$url_send ="http://jira.greentea.co.za:8091/rest/api/2/issue/";
$str_data = json_encode($json);
//print_r($str_data);
function sendPostData($url, $post){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
if($result)
{
return 1;
}
else{
return 0;
}
}
$time = sendPostData($url_send, $str_data);
var_dump($time);
?>
I get a zero int(0) meaning that the result variable returned a blank result. This is the the cURL Command that I converted to php. data will be replaced by the json array:
curl -D- -u fred:fred -X POST --data {see below} -H "Content-Type: application/json" http://localhost:8090/rest/api/2/issue/
curl_getinfo()to get the HTTP code, which might give you an idea as to what's wrong.