Codebase API Documentation

PHP - Display Categories for a Project

The following code fetches all of the Ticket Categories for a project and populates the result into an array.

define('CBAUTH', 'accountName/userAccount:authToken'); 

$catArray = array(); 
$headers = array('Accept: application/xml', 'Content-type: application/xml');
$apiRequest = APIURL . '/tickets/categories'; 

/* Fetch the categories from the API */
$c = curl_init(); 
curl_setopt($c, CURLOPT_URL,$apiRequest); 
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($c, CURLOPT_USERPWD, CBAUTH); 
curl_setopt($c, CURLOPT_HTTPHEADER, $headers); 
$result = curl_exec($c); 

$myxml = simplexml_load_string($result); 
$xmlArray = toArray($myxml); 
$catArray = $xmlArray['ticketing-category']; 

/* Returns an array from fetched XML */ 
function toArray($xml) { 
  $array = json_decode(json_encode($xml), TRUE); 
  foreach (array_slice($array, 0) as $key => $value) { 
    if (empty($value)) $array[$key] = NULL; 
    elseif (is_array($value)) $array[$key] = toArray($value); 
  return $array; 

Thanks to Luke Davies for this example.