php [freshdesk php core] freshdesk php api #customer

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php [freshdesk php core] freshdesk php api #customer相关的知识,希望对你有一定的参考价值。

<?php
/*
Full: https://github.com/freshdesk/fresh-samples/tree/master/PHP
*/

//create a ticket
$api_key = "API_KEY";
$password = "x";
$yourdomain = "YOUR_DOMAIN";
$ticket_data = json_encode(array(
  "description" => "Some details on the issue ...",
  "subject" => "Support needed..",
  "email" => "tom@outerspace.com",
  "priority" => 1,
  "status" => 2,
  "cc_emails" => array("ram@freshdesk.com", "diana@freshdesk.com")
));
$url = "https://$yourdomain.freshdesk.com/api/v2/tickets";
$ch = curl_init($url);
$header[] = "Content-type: application/json";
curl_setopt($ch, CURLOPT_POST, true);
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'] == 201) {
  echo "Ticket created 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);

以上是关于php [freshdesk php core] freshdesk php api #customer的主要内容,如果未能解决你的问题,请参考以下文章

javascript [freshdesk节点核心] freshdesk nodejs纯#customer

使用 Swift 2.2 中的 Freshdesk API

javascript [freshdesk节点] #customer

html [freshdesk jquery] #customer

从 SQL Server 触发器调用 Freshdesk API

python [freshdesk - python]客户服务#customer