REST API for Categories

REST API for Categories

I am trying to write a PHP script to pull all of the categories for SDP that are not deleted.

I need PHP to create another XML feed that looks something similar to:

<category>Primary Category 1</category>
<sub>Sub Category 1</sub>
<sub>Sub Category 2</sub>
<category>Primary Category 2</category>
<category>Primary Category 3</category>
<sub>Sub Category 1</sub>
<sub>Sub Category 2</sub>

and so on

I know how to make the XML but I am having trouble parsing through the SDP XML with PHP.

My script is this:

<?php


function getMEXML($url, $operationName, $techKey){
//set POST variables
$fields_string = '';
$fields = array(
'OPERATION_NAME' => urlencode($operationName),
'TECHNICIAN_KEY' => urlencode($techKey)
);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

return $result;
}
$cats = simplexml_load_string(getMEXML("http://manageengine.domain.com/sdpapi/admin/category/","GET_ALL","techKey"));
foreach ($cats->record as $recordInfo){
foreach ($recordInfo->parameter as $parameter){
if ($parameter->name == "name"){
echo $parameter->value;
echo "<br>";
}
}
}
?>

When executing this code this is the error I get:

Warning: simplexml_load_string(): Entity: line 1: parser error : Start tag expected, '<' not found in /var/www/html/testbed/index.php on line 32 Warning: simplexml_load_string(): 1 in /var/www/html/testbed/index.php on line 32 Warning: simplexml_load_string(): ^ in /var/www/html/testbed/index.php on line 32 Notice: Trying to get property of non-object in /var/www/html/testbed/index.php on line 33 Warning: Invalid argument supplied for foreach() in /var/www/html/testbed/index.php on line 33

My questions is this:

Has anyone ever thought to try and get the categories from SDP using PHP? If so could you share your code?

We have built a windows app for our agents on the floor to use to file a ticket (submit a request). I don't want to have to manually type the categories all of the time and would like to programmatically do it.

Any help on this would be greatly appreciated!

By the way, using Service Desk Plus  8.2.0  Build  8212




                  New to ADSelfService Plus?