使用API​​ 5.1中的rest api和PHP更新JIRA中的问题

时间:2013-07-16 05:31:42

标签: php curl jira put

我使用以下代码更新JIRA中的问题但无法诊断错误。我得到的错误如下:

HTTP状态415 - 不支持的媒体类型 类型状态报告 消息不支持的媒体类型

我写的代码如下:

$resource_array['api_name'] = 'issue/SPC-60';
$resource_array['fields'] = array (
'summary' => 'CLONE - Testing label stuff',
'assignee' => 
array (
  'emailAddress' => 'avinashk.dubey@gmail.com',
),
'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 个答案:

答案 0 :(得分:0)

实际上,我在这里做错了:

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

它应该是:

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