Skip to content

Instantly share code, notes, and snippets.

@verschoren
Created July 28, 2020 09:26
Show Gist options
  • Save verschoren/60271392fc1b527079aef066a21178b1 to your computer and use it in GitHub Desktop.
Save verschoren/60271392fc1b527079aef066a21178b1 to your computer and use it in GitHub Desktop.
<?php
function zd($url, $json, $action, $ZDAPIKEY,$ZDUSER,$ZDDOMAIN,$decode) {
$ZDURL = "https://".$ZDDOMAIN.".zendesk.com";
$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch, CURLOPT_URL, $ZDURL.$url);
curl_setopt($ch, CURLOPT_USERPWD, $ZDUSER."/token:".$ZDAPIKEY);
switch($action){
case "POST":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
break;
case "GET":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
break;
case "PUT":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
break;
case "DELETE":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
default:
break;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
if ($decode == true){
$decoded = json_decode($output);
return $decoded;
}
else {
return $output;
}
}
$ZDAPIKEY = "";
$ZDUSER = "";
$ZDURL = "";
$parameter = "";
$object = '{"data": {"type": "store","attributes": {}}}';
$object = json_decode($object, TRUE);
$object['attributes'] = $result;
$json = json_encode($object);
print_r($object);
echo "<br><br>";
$return = zd($parameter,$json,"POST",$ZDAPIKEY,$ZDUSER,$ZDURL,true);
print_r($return);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment