I am trying to get all ticket data from Zendesk using their v2 API - the API is limited to 100 responses per page and then paginated but I cannot seem to cycle through all the pages to get the total number of tickets (and other information)
As I have no idea how many pages there will be I am stuggling to set a loop to deal with this efficiently. At the moment I have used 20 as I know I have less than 2000 tickets:
for ($page=1;$page<20;$page++) {
if ($page==1) {
$data = curlWrap("/ticket_metrics.json", null, "GET");
} else {
if ($data->next_page!="NULL"&&$data->next_page!=""&&$data->next_page!=0) {
$data = curlWrap("/ticket_metrics.json?page=$page", null, "GET");
}
}
foreach ($data as $ticket) {
if (is_array($ticket)) {
foreach ($ticket as $i) {
$time=$i->reply_time_in_minutes->calendar;
if ($time!=0 &&$time!="") {
$total_time=$total_time+$time;
$counter++;
}
}
}
}
}
$answer=$total_time/$counter;
print $total_time."/".$counter."=".$answer;
How can I get the total number of tickets and the first response time so I can perform this calculation?
Thanks