title: Getting all tickets from Zendesk API
body: <p>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)</p>
  
  <p>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:</p>
  
  <pre><code>for ($page=1;$page&lt;20;$page++) {
      if ($page==1) {
          $data = curlWrap("/ticket_metrics.json", null, "GET");
      } else {
          if ($data-&gt;next_page!="NULL"&amp;&amp;$data-&gt;next_page!=""&amp;&amp;$data-&gt;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-&gt;reply_time_in_minutes-&gt;calendar;
                  if ($time!=0 &amp;&amp;$time!="") {
                      $total_time=$total_time+$time;
                      $counter++;
                  }
              }
          }
      }
  }
  
  
  
  $answer=$total_time/$counter;
  
  print $total_time."/".$counter."=".$answer;
  </code></pre>
  
  <p>How can I get the total number of tickets and the first response time so I can perform this calculation?</p>
  
  <p>Thanks</p>