Skip to content

Instantly share code, notes, and snippets.

@tstachl
Created September 25, 2014 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tstachl/4f1b8393168186819d8e to your computer and use it in GitHub Desktop.
Save tstachl/4f1b8393168186819d8e to your computer and use it in GitHub Desktop.
Creating a case using PHP and CURL in desk.com
<?php
$json = json_encode(array(
"subject" => "Test",
"description" => "testing",
"message" => array(
"subject" => "Test",
"body" => "Test",
"direction" => "in",
"to" => "support@example.com",
"from" => "customer@example.com",
"status" => "received"
),
"type" => "phone",
"_links" => array(
"customer" => array("href" => "/api/v2/customers/207020953")
)
));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://site.desk.com/api/v2/cases');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_USERPWD, "my-email:my-password");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($json))
);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment