PHP curl Zendesk更新主题和描述的票证

时间:2015-09-12 11:16:06

标签: php curl zendesk

我想通过php curl方法更新zendesk票据我想更新主题和描述字段。或者有什么我们可以拥有自己的票证ID并在创建票证时传递它。

我使用以下代码来更新故障单。

$create = json_encode(array('ticket' => array('subject' => $arr['z_subject'], 'description' => $arr['z_description'], 'requester' => array('name' => $arr['z_name'], 'email' => $arr['z_requester'],'custom_fields' => $custom_fields))), JSON_FORCE_OBJECT);

//new ticket
$data = curlWrap("/tickets.json", $create, "POST");

$ticket_id = $data->ticket->id;

$arr['z_description'] = $arr['z_description'] . " " . $ticket_id;
$arr['z_subject'] = $arr['z_subject'] . " " . $ticket_id;

print_r($arr);
echo "<br /><br />";

$create = json_encode(array('ticket' => array('subject' => $arr['z_subject'], 'description' => $arr['z_description'])));
$ticketid="/tickets/" . $ticket_id . ".json";

print $ticketid ."<br />";
//updating ticket
$data = curlWrap($ticketid, $create, "PUT");
var_dump($data);

function curlWrap($url, $json, $action)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
    curl_setopt($ch, CURLOPT_URL, ZDURL.$url);
    curl_setopt($ch, CURLOPT_USERPWD, ZDUSER."/token:".ZDAPIKEY);

    switch($action){
        case "POST":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
            break;
        case "GET":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
            break;
        case "PUT":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
            curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
            break;
        case "DELETE":
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
            break;
        default:
            break;
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
    curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    $output = curl_exec($ch);
    curl_close($ch);
    $decoded = json_decode($output);
    return $decoded;
}

1 个答案:

答案 0 :(得分:0)

正如您在此处所见,Zendesk Core API主题只是您发布的第一条评论,因此,您无法更改主题。但你可以按照你提出的问题进行描述。

如果这可能有所帮助,无论何时创建故障单,您都会收到一条包含该ID的回发消息以及更多信息,如您在Creating tickets所见。