Written by Giles Bennett
Zendesk to Geckoboard
The first step is to set up the view in Zendesk that you want to query. In the example below I'm actually using two views, one which has the list of tickets closed in the last 24 hours (rolling), and one which has the list of tickets closed in the 24 hours before that (also rolling). Whatever it is you're querying, make a note of your custom Zendesk address and the query number. You'll also need to get the API token (I'm writing from memory here!) associated with the account that you'll be using. So the first step is to open up a CURL session with the relevant details : [php] <?php $curl = curl_init('https://CUSTOMADDRESS.zendesk.com/api/v2/views/VIEW_NUMBER/execute.json'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_USERPWD, 'USERNAME/token:API_TOKEN'); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $responseToday = curl_exec($curl); $resultsToday = json_decode($responseToday, true); [/php] which then fills $resultsToday with the response from our Zendesk query. If we were to output the value of $resultsToday at this stage with a : [php] print_r($resultsToday); [/php] then we'd see an array with, amongst other things, the details of the first 20 tickets closed today, with the ID, customer name, and the URL of the specific ticket for each. Note that I say the first 20 - as with the CSAT statistics, the API doesn't return every value in one go - we would have to loop through the query to get the next 20 and the next 20. But we just want the total number of closed tickets, and this is returned at the bottom of the array like so : [php] [count] => 297 [/php] So that's the first bit of information we need - the total count of tickets closed in the last 24 hours, which is now contained in $resultsToday[count], and which can just sit there for the time being. Next we repeat the same step, but querying the second view (which contains) the number of tickets closed in the 24 hours before that : [php] $curl2 = curl_init('https://CUSTOMADDRESS.zendesk.com/api/v2/views/VIEW_NUMBER/execute.json'); curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl2, CURLOPT_USERPWD, 'USERNAME/token:API_TOKEN'); curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1); $responseYesterday = curl_exec($curl2); $resultsYesterday = json_decode($responseYesterday, true); [/php] And the count of closed tickets for the preceding 24 hours is contained in $resultsYesterday[count]. So then we just need to get that information in the format that Geckoboard wants to see it. In this instance we're dealing with a number and secondary stat widget - so if we just pass Geckoboard the number of tickets closed in the last 24 hours, and the number of tickets closed in the 24 hours before that, it will show the former figure as the main statistic, and then a comparison (% up or down) against the preceding 24 hour period. So armed with $resultsToday[count], $resultsYesterday[count] and our Geckoboard API key, we can create the string that we need to pass to Geckoboard : [php] $values = '{"api_key":"YOUR_GB_API_KEY","data":{"item":[{"text":"","value":'.$resultsToday[count].'},{"text":"","value":'.$resultsYesterday[count].'}]}}'; [/php] And then the final step is to push that string to our custom push widget on Geckoboard, for which all we need is the Widget ID : [php] curl_setopt_array($ch = curl_init(), array( CURLOPT_URL => "https://push.geckoboard.com/v1/send/WIDGET_ID_HERE", CURLOPT_POSTFIELDS => $values, ) ); curl_exec($ch); curl_close($ch); ?> [/php] And that's it - the end result looks something like this : [caption id="attachment_184" align="alignnone" width="235"]