Accessing the Zendesk API with LogicMonitor.


Recommended Posts

  • LogicMonitor Staff

Accessing the Zendesk API with LogicMonitor.  

Details for the Zendesk API can be found from the below link

The below blog is not intended as a copy\paste Zendesk datasource but as instructions to create Groovy Script datasources based on custom criteria.

Zendesk data can be imported and alerted on with LogicMonitor using various API methods.  This post will focus on using Zendesk Views and the Zendesk query

First we will focus on the View, specifically the count of tickets in the view.  Zendesk views are a way to organize your tickets by grouping them into lists based on certain criteria.  In my example I’ve created a view for tickets for my rated tickets within the last 7 days.  The criteria can be anything you require. Zendesk has various json files already created for views.  This example will use the count.json.  

Create a Zendesk view.  Load the view in Zendesk and the view ID will be in the URL

For example:

90139988 is the view ID.  


Zendesk documentation on views can be viewed  with the below link

From the LogicMonitor side we can use a datasource with an embedded groovy script with the built-in json slurper to parse the data.  

More information on Groovy Script Datasources can be found in the below URLs


Create a new Groovy Script Datasource and be sure to import the Jason slurper and http API by adding the below 3 lines to the top of the script.  


// import the logicmonitor http and JsonSlurp class

import com.santaba.agent.groovyapi.http.*;

import groovy.json.JsonSlurper;


The URL and authentication information to retrieve the view’s count json is defined as



Authentication is using a Zendesk token instead of a password by appending the ‘/token’ string to the user ID

user = '' + '/token'

pwd = '##ZENDESK TOKEN##'


Next use the groovyapi HTTP

// get data from the ZenDesk API

http_body = HTTP.body(url, user, pwd);


This will return the count json file which should look similar to the below

view_count=[url:, view_id:101684888, value:45, pretty:45, fresh:false]


Value=45 is the count data, so we need to parse the Value data


You can print the json to output in the !groovy debug window by using the below code

// Debug - print json slurp to identify keyvalues
// iterate over the response object, assigning key-value pairs
{ key, value ->
   // print each key-value pair
      println key + "=" + value;


This can be done by using the json slurper

// user groovy slurper

json_slurper = new JsonSlurper();

response_obj = json_slurper.parseText(http_body);


LogicMonitor can use multi-line key value pairs, so parse so adding in a key of “TicketCount=” to the ouput will make it easy to add a datapoint for the count value.  Do this by printing to the output


// Print key Value pair for Logicmonitor Datapoint

println "TicketCount=" + response_obj.view_count.value


In your datasource you can add a new datapoint

*Content the script writes to the standard output

Inturpret output with - Multi-line Key Value Pairs

Key = TicketCount




LogicMonitor will reconize the TicketCount as a datapoint and alert thresholds can be set accordingly.  



In the attached Example Zendesk_TixCnt.xml The zendesk specific values have been tokenized to be added on the device level were the datasource will be applied.  


Tokens required on the device are

ZEN.ACCOUNT - i.e. logicmonitor

ZEN.EMAIL - i.e.

ZEN.TOKEN - Token for authentication

ZEN.VIEW - view ID if using a view (This can be found in the URL while viewing the view)

The second example uses the search API to query for tickets with a specified status for the last 48 hours.  

When building the URL it’s important to remember spaces and special characters are not allowed.  Use Encoded Characters instead


an example for solved tickets in the last 48 hours query=type:ticket status:solved created>48hours

The URL after including encoded Characters.  

url = ""


The output will look similar to

~brand_id:854608, allow_channelback:false, result_type:ticket]]






We only need the count.  Using the same key value output as the previous example we can add a key for "Solved"

println "solved=" + response_obj.count.value



In the attached example ZenDesk_TixStatus this process is repeated for Created, Open, Solved, Pending, On-Hold, and closed.  




Link to post
Share on other sites


This topic is now archived and is closed to further replies.