use GuzzleHttp\Client;
function insert_freshdesk_note($ticketId, $content, $attachments=null)
{
if(is_null($content)) {
return false;
}
$url = 'https://mydomain.freshdesk.com/api/v2/tickets/'.$ticketId.'/notes';
$method = 'POST';
$userName = config('freshdesk_api_key');
$password = 'password';
$data = (!empty($attachments)) ? [
"attachments[]" => $attachments,
"body" => $content,
"private" => false,
] : [
"body" => $content,
"private" => false,
];
$options = (!empty($attachments)) ? [
'json' => $data,
'auth' => [$userName, $password],
'headers' => ['content-type' => 'multipart/form-data']
] : [
'json' => $data,
'auth' => [$userName, $password]
];
$client = new Client();
try {
$response = $client->request($method, $url, $options);
return json_decode($response->getBody(), true);
} catch (Exception $e) {
Log::error($e);
}
}
上面的代码在没有附件的情况下工作正常,但是当附件出现在图片中时,它会引发以下错误:-
GuzzleHttp\Exception\ClientException: Client error: `POST https://mydomain.freshdesk.com/api/v2/tickets/13033/notes` resulted in a `400 Bad Request` response:
{"description":"Validation failed","errors":[{"field":"{\"attachments","message":"Unexpected/invalid field in request","
我正在根据文档工作,到目前为止我已经走到了死胡同。我尝试了其他排列和组合,但通过这些,我无法解决这个问题。
谁能帮帮我吗。这是freshdesk文档的链接 并且在 $attachments[] = '@/path/to/xyz.ext' 中,这个特别的东西正在发生。
函数调用将如下所示:-
insert_freshdesk_note($this->freshdesk_ticket_id, $noteText, $image->image_full_path);