Skip to content

Instantly share code, notes, and snippets.

@coderhs
Created June 2, 2013 12:45
Show Gist options
  • Save coderhs/5693543 to your computer and use it in GitHub Desktop.
Save coderhs/5693543 to your computer and use it in GitHub Desktop.
<?php
/* *** WHMCS JSON API Sample Code *** */
$url = "localhost/order/includes/api.php"; # URL to WHMCS API file goes here
$username = "user"; # Admin username goes here
$password = "passs"; # Admin password goes here
$postfields = array();
$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "gettickets";
$postfields["responsetype"] = "json";
$postfields["limitstart"] = 3470;
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$jsondata = curl_exec($ch);
if (curl_error($ch)) die("Connection Error: ".curl_errno($ch).' - '.curl_error($ch));
curl_close($ch);
$arr = json_decode($jsondata); # Decode JSON String
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment