在Freshdesk Api中更新票证时添加附件

时间:2019-10-15 13:10:56

标签: php api freshdesk

在freshdesk API中更新带有工单ID的工单时,我想添加附件

使用此api更新票证并在票证数据中添加附件

这是我的代码

<?php

    $api_key    = "api_key";
    $password   = "x";
    $yourdomain = "doamin";

    $ticket_data = json_encode(array(
    "priority"    => 3,
    "status"      => 4,
    "description" => "Need support for the issue"
        ));

    // Id of the ticket to be updated
    $ticket_id = 80;

    $url = "https://$yourdomain.freshdesk.com/api/v2/tickets/$ticket_id";

    $ch = curl_init($url);

    $header[] = "Content-type: application/json";
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_USERPWD, "$api_key:$password");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $ticket_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $server_output = curl_exec($ch);
    $info          = curl_getinfo($ch);
    $header_size   = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
    $headers       = substr($server_output, 0, $header_size);
    $response      = substr($server_output, $header_size);


    if ($info['http_code'] == 200) {
    echo "Ticket updated successfully, the response is given below \n";
    echo "Response Headers are \n";
    echo $headers . "\n";
    echo "Response Body \n";
    echo "$response \n";
    } else {
    if ($info['http_code'] == 404) {
        echo "Error, Please check the end point \n";
    } else {
        echo "Error, HTTP Status Code : " . $info['http_code'] . "\n";
        echo "Headers are " . $headers;
        echo "Response are " . $response;
    }
}

    curl_close($ch);

响应为

{"description":"Validation failed","errors":          [{"field":"attachments","message":"Value set is of type key/value    
> pair.It should be a/an Array","code":"datatype_mismatch"}]}

0 个答案:

没有答案