I’m attempting to interface with Jira’s REST API through PHP but I’m encountering some difficulties. My code runs without providing any error or success response.
Here’s the code I’m using:
<?php
include_once "data_loader.php";
$dataForIssue = loadJsonData("collector.json");
$jiraApiUrl = "http://jira.mycompany.com:8091/rest/api/2/issue/";
$jsonData = json_encode($dataForIssue);
$curlSession = curl_init($jiraApiUrl);
curl_setopt($curlSession, CURLOPT_HEADER, 0);
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlSession, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curlSession, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($curlSession, CURLOPT_ENCODING, "");
curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($curlSession, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curlSession, CURLOPT_URL, $jiraApiUrl);
$apiResponse = curl_exec($curlSession);
curl_close($curlSession);
$responseArray = json_decode($apiResponse, TRUE);
print_r($responseArray);
My JSON data is structured as follows:
{
"fields": {
"project": {
"key": "PROJ"
},
"summary": "Issue creation for testing API",
"description": "This is a sample issue made through REST API integration",
"issuetype": {
"name": "Task"
}
}
}
The equivalent curl command to use would be:
curl -u username:password -X POST --data @collector.json -H "Content-Type: application/json" http://jira.mycompany.com:8091/rest/api/2/issue/
When I run the PHP script, there is no output displayed on the screen. I’m not seeing any error messages or indications of success, just a blank screen. What could be the reason for this lack of feedback, and how can I debug the connection?