我正在尝试使用他们的v2 API从Zendesk获取所有票证数据 - API每页限制为100个响应然后分页,但我似乎无法遍历所有页面以获取票证总数(和其他信息)
因为我不知道会有多少页面,所以我正在努力设置一个循环来有效地处理这个问题.目前我使用了20,因为我知道我的门票不到2000张:
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;
如何获得门票总数和第一个响应时间,以便我可以执行此计算?
谢谢
不确定您是否还需要它,但会发布以防其他人遇到此问题.
门票的数量在响应中返回为"count".你也是正确的,每页最多返回100条记录 - 尽管你可以减少回报.此页面供参考:http://developer.zendesk.com/documentation/rest_api/introduction.html
我重构代码以使用while循环,直到next_page为'null'(我认为这是你的问题).
$page_num = '1'; $total_records = -1; while ($page != 'null') { //query API return to $data $url = "/ticket_metrics.json?page=" . $page_num; $data = curlWrap($url, null, "GET"); //'count' is returned in json if ($total_records < 0) $total_records = $data->$count; $page = $data->next_page; //add total_time and increase your counter } //process your data