Hello,
I try to create ticket with curl in php but i always have this issue :
HTTP/1.1 401 Unauthorized Date: Sun, 03 Jan 2021 13:09:56 GMT Server: Plack::Handler::Starlet Content-Length: 26 Content-Type: application/json; charset=utf-8 Connection: close {“message”:“Unauthorized”}
This is my code
$ticket_data=array(
“Queue” => “General”,
“Subject” => “hello world 2021”,
“Content” => " my test content",
“ContentType”=> “text/html”,
//“CustomFields”=>$files
);
$post = $ticket_data; //array(‘val1’ => ‘value’,‘val2’ => ‘value’,‘CustomFields’=> $files );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$base_url.‘ticket/’);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, array(‘Content-Type: application/json’,‘Authorization: token 1-14-c6cde7f274dcbf4f8d1bf2da32449518’));
//curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
$result=curl_exec ($ch);
$resp=json_decode($result);
echo curl_error($ch);
var_dump($resp);
curl_close ($ch);
Please help thanks