Mushroomheadbangers

Zendesk API curlfunc.php script

Aug 20th, 2013
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. #!/usr/bin/php
  2.  
  3. <?php
  4.  
  5. define("ZDAPIKEY", "FoIjUg572mUrOVrSNm18Q8IbktTCCj5H1Rwm8KVy");
  6. define("ZDUSER", "clinton@korcett.com");
  7. define("ZDURL", "https://korcett.zendesk.com/api/v2");
  8.  
  9. function curlWrap($url, $json, $action)
  10. {
  11.         $ch = curl_init();
  12.         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  13.         curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
  14.         curl_setopt($ch, CURLOPT_URL, ZDURL.$url);
  15.         curl_setopt($ch, CURLOPT_USERPWD, ZDUSER."/token:".ZDAPIKEY);
  16.         switch($action){
  17.                 case "POST":
  18.                         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  19.                         curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  20.                         break;
  21.                 case "GET":
  22.                         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  23.                         break;
  24.                 case "PUT":
  25.                         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  26.                         curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
  27.                         break;
  28.                 case "DELETE":
  29.                         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  30.                         break;
  31.                 default:
  32.                         break;
  33.         }
  34.  
  35.         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  36.         curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
  37.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  38.         curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  39.         $output = curl_exec($ch);
  40.         curl_close($ch);
  41.         $decoded = json_decode($output);
  42.         return $decoded;
  43. }
  44. ?>
Add Comment
Please, Sign In to add comment