Hi guys, I have a problem creating a ticket, I am following this example from github:
but, I get this answer :
{
"description":"Validation failed",
"errors":[
{
"field":"custom_fields.nro_de_pedido",
"message":"It should be a/an Integer",
"code":"missing_field"
},
{
"field":"custom_fields.nombre_cliente",
"message":"It should be a/an String",
"code":"missing_field"
},
{
"field":"custom_fields.mail",
"message":"It should be a/an String",
"code":"missing_field"
},
]
}
Also verify that the data was of the string type, depending on what it says, my query is, in the response message it says error by the order_num, customer_name and mail are necessary ?, because in the github example it does not appear like this.
This is my code :
public function ttest(){
$this->autoRender = false ;
$user = __USUARIO__ ;
$api_key = __APIKEY__ ;
$password = __PAWWWORD__ ;
$yourdomain = __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")
));
echo '<pre>';
var_dump( $ticket_data ) ;
echo '</pre>';
$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);
}
PS: sorry my English, but I am not native in the language.