0
votes

I am using the following code to update an issue in JIRA but unable to diagnose the error. The error I am getting is as follows:

HTTP Status 415 - Unsupported Media Type type Status report message Unsupported Media Type

The code I have written is as follows:

$resource_array['api_name'] = 'issue/SPC-60';
$resource_array['fields'] = array (
'summary' => 'CLONE - Testing label stuff',
'assignee' => 
array (
  'emailAddress' => '[email protected]',
),
'customfield_10649' => 
array (
  'id' => '10668',
),
'customfield_10616' => 'This is observation'
);

$data = putJiraAPI($resource_array);
print_r($data);
////////////////////////////////////////////
function putJiraAPI($resource_array)
{
    $api_name = $resource_array['api_name'];
    unset($resource_array['api_name']);
    $result = put_to($api_name, $resource_array);
    if(is_array($result))
    {
            return $result;
    }
    else 
    {
     return "error while getting data using ".BASE_URL.API_URL.$resource_string;
    }
}

function put_to($api_name, $resource_array) 
{
    $jdata = json_encode($resource_array);
    print_r($jdata);
    $ch = curl_init();
    curl_setopt_array($ch, array(
    CURLOPT_CUSTOMREQUEST => "PUT",
    CURLOPT_URL => BASE_URL . API_URL . $api_name,
    CURLOPT_USERPWD => USER_NAME . ':' . PASSWORD,
    CURLOPT_POSTFIELDS => $jdata,
    CURLOPT_HTTPHECURLOPT_HTTPHEADER => array(
        'Content-Type: application/json'
        ),
    CURLOPT_RETURNTRANSFER => true
        ));

    echo BASE_URL . API_URL . $api_name;

    $result = curl_exec($ch);
    curl_close($ch);
    return json_decode($result,true);
}
1

1 Answers

0
votes

Actually, I did wrong here:

CURLOPT_HTTPHECURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
    ), 

it should be:

CURLOPT_HTTPHEADER => array('Content-type: application/json'),