Created
January 15, 2015 00:00
-
-
Save tstachl/ee69ce62f7367ce8461a to your computer and use it in GitHub Desktop.
A quick php script that shows how to create a case and then a reply.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function post($path, $json) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, "https://site.desk.com$path"); | |
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); | |
return $result; | |
} | |
// initial case | |
$json = json_encode(array( | |
"subject" => "Test", | |
"description" => "testing", | |
"message" => array( | |
"subject" => "Test", | |
"body" => "Test", | |
"direction" => "in", | |
"to" => "[email protected]", | |
"from" => "[email protected]", | |
"status" => "received" | |
), | |
"type" => "phone", | |
"_links" => array( | |
"customer" => array("href" => "/api/v2/customers/207020953") | |
) | |
)); | |
$case = json_decode(post('/api/v2/cases', $json)); | |
// another reply | |
$json = json_encode(array( | |
"subject" => "Re: Test", | |
"body" => "Test", | |
"direction" => "out", | |
"to" => "[email protected]", | |
"from" => "[email protected]", | |
"status" => "sent" | |
)); | |
$reply = post($case->_links->replies, $json); | |
echo $reply; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment