<html>
<head>
<title>Bomgar Zendesk SetStatus</title>
</head>
<body>
<?php
// zendesk-setstatus.php
//
// This sample PHP script can be used with Bomgar "outbound events" configured
// via the administrative interface on the appliance (/login URL).
// See Management / Outbound Events...
// Create an event called "Representative Exit Survey is Completed"
// Enter the complete URL of this PHP script
// Check "Events to Send" as "Support Session End"
// Be sure to enable the XML API in Management / Security.
// CUSTOMIZE THESE VARIABLES FOR YOUR SPECIFIC ENVIRONMENT...
//Bomgar Info...
$BomgarURL = 'https://support.company.com/api/reporting.ns'; //path to the reporting API URL of your Bomgar support portal
//Zendesk Login Info...
$zenurl = "http://yoursite.zendesk.com";
$zenemail = "your-email@company.com";
$zenpassword = "yourpassword";
// Create a header for the comment update...
$message = "BOMGAR Ticket Status Update". "\r\n";
date_default_timezone_set('America/Chicago');
function set_status($ticket_location, $value)
{
global $zenurl,
$zenemail,
$zenpassword;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ticket_location);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt
($ch, CURLOPT_HTTPHEADER,
array("Content-type: text/xml"));
$xml = "<ticket><status-id>$value</status-id></ticket>";
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$zenemail:$zenpassword");
curl_exec($ch);
curl_close($ch);
}
function add_comment($ticket_location, $value, $is_public, $token = '')
{
global $zenurl,
$zenemail,
$zenpassword;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $ticket_location);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt
($ch, CURLOPT_HTTPHEADER,
array("Content-type: text/xml"));
$xml = "<ticket><comment><value>$value</value><is_public>$is_public</is_public></comment><uploads>$token</uploads></ticket>";
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$zenemail:$zenpassword");
curl_exec($ch);
curl_close($ch);
}
// Post the necessary info to query Bomgar for the session details using the Bomgar Reporting API...
(
'username' => "apiuser", //account with admin access to the Bomgar portal
'password' => "testtest", //password for this account
'generate_report' => "SupportDesk", //this give us a report of sessions
'lsid' => $_REQUEST['lsid'] //this is the session ID for the request that just entered the queue
);
// Use curl to invoke the Bomgar Reporting API to retrieve session details...
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $BomgarURL);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Assign the output from the URL to $output.
$output = curl_exec($curl);
// close curl resource, and free up system resources
curl_close($curl);
// Use DOM to parse the XML output of the reporting API to query the necessary information
$dom = new DOMDocument();
$dom->loadXML($output);
if (!$dom)
{
// Handle the error
return;
}
//Load returned XML for this session into the $xml varialble.
$xml = simplexml_import_dom($dom);
// Loop through the "rep_survey_list" object(s) and get the values desired. Note, there should be only
// one Customer in typical support sessions.
// ................
// Or, we could directly get the specific instance of customer from customer_list using...
// $Customer = $xml->session->customer_list[0]->customer;
//extract the Zendesk incident number (aka "External_Key") from the Bomgar session details...
$external_key = $xml->session->external_key;
$RepName = $xml->session->primary_rep;
$survey = $xml->session->rep_survey_list[0]->rep_exit_survey;
//Retrieve comments entered by the Rep in the exit survey at the end of the support session
//These can be included along with the incident status update.
$StatusComments = $survey->value[0]["value"];
//Pull the value chosen by the rep at the end of the session to set the corresponding status
//in the incident. See TicketStatus / TicketStatusValue below.
$TicketStatus = $survey->value[1]["value"];
// Clean up ampersands in comments & chats... not valid in XML
// Example URL for testing manually...
// Ex. https://support.yoursite.com/api/reporting.ns?username=yourAPIuser&password=yourpassword&generate_report=SupportDesk&lsid=410
//testing values...
//$TicketStatus="Pending";
//$external_key=201;
if ($TicketStatus=="Open")
{
$TicketStatusValue=1;
}
elseif ($TicketStatus=="Pending")
{
$TicketStatusValue=2;
}
elseif ($TicketStatus=="Solved")
{
$TicketStatusValue=3;
}
echo "sleeping for 5 seconds...";
// sleep for 5 seconds just to make sure this update happens after other Outbound Events are processed.
$StatusComments = "Rep: " . $RepName ." changed status to: ". $TicketStatus . " and added the following comment:\r\n" . $StatusComments;
// Adding a public comment to the ticket
add_comment($zenurl."/tickets/".$external_key . ".xml", $StatusComments, true);
echo "Comment added to ticket: ".
$StatusComments;
//set the status based on rep exit survey
set_status($zenurl."/tickets/".$external_key . ".xml", $TicketStatusValue);
//echo "Setting Status on Ticket #:".$external_key;
// ZenDesk Ticket Status IDs
// Status Status ID
//New 0
//Open 1
//Pending 2
//Solved 3
//Closed 4
?>
</body>
</html>