Blog

21
Nov

ZenDesk API Integration to get ticket details daily

Aim:

To get count of tickets for every day.
 

User flow and implementation:

 

Step 1: Authorization as per https://support.zendesk.com/entries/24458591-Using-OAuth-authentication-with-your-application

 

  • Redirect the user to the authorization page in ZenDesk
  • Get authorized using the access token.

 

Step 2: Get count of tickets created for a particular date.

 

curl Call:

 

  • curlWrap($zendfetchmail, $zendfetchkey, $zendfetchurl, “/api/v2/search.json?query=created>$dayin”, null, “GET”);

Note: curlWrap is a curl function which gives the response output. It passes the parameters of <mail_id>,<API key>, <app_url>,<request url>.

 

<request url> specifies our request. If we want to request for create a new ticket the url endpoint must be “/tickets.json”. Here <request url> =”/api/v2/search.json?query=created>$dayin” .Here $dayin is date passing for get the result for the particular date.Here we uses the operator “>”, it means the result returns the most recent tickets. In our code we send the <yesterday’s date> since we want to get the details daily.

 

curlWrap:

 

function curlWrap($ZDUSER, $ZDAPIKEY, $ZDURL, $url, $json, $action)

{       $ch = curl_init();

       // set url

       curl_setopt($ch, CURLOPT_URL, $ZDURL.$url);

       curl_setopt($ch, CURLOPT_USERPWD, $ZDUSER.”/token:”.$ZDAPIKEY);

       //return the transfer as a string

    .     .    .    .

       $options[CURLOPT_USERAGENT] = $useragent;

       curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

      curl_setopt($ch,CURLOPT_FOLLOWLOCATION,true);

          $output = curl_exec($ch);  //output

         curl_close($ch);

          $decoded = json_decode($output,1);

    return $decoded;

}

 

Response:

 

The response we get contains count, next_page, prev_page, results

count : The total number of results matching this query

next_page:URL to the next page of results.

prev_page: URL to the previous page of results.

results: May consist of Tickets, Users, Groups, Organizations, and Topics.

 
 

Integration and interaction diagrams

 

1. Authorize App using Zendesk.

2. Get Refresh token and Access token from Zendesk.

 

 

3.Get count of tickets for particular date.

PHP Library:

 

https://code.google.com/p/zendesk-php-lib/

 

Links: