首页 > 解决方案 > 具有最大结果的 ZenPy 搜索调用

问题描述

我正在使用 ZenPy 在 ZenDesk 中搜索几张票:

open_tickets = zenpy_client.search(type='ticket', status=['new', 'open'], subject=subject, group=group_name, created_between=[two_weeks_ago_date, current_date])

问题是当我从这个 Search 调用中得到太多结果时(超过 1.000,因为它是 ZenDesk API 的新查询限制)。我得到以下异常:

<Invalid search: Requested response size was greater than Search Response Limits>

我正在尝试查看 ZenPy 文档,但找不到任何可用于将搜索调用限制为 10 页的参数(在本例中,1.000 条记录,因为我们每个请求获得 100 张票证)。

我最终在通话中进行了尝试,但我确信这不是最好的解决方案:

from zenpy.lib.exception import APIException
try:
    open_tickets = zenpy_client.search(type='ticket', status=['new', 'open'], subject=subject, group=group_name, created_between=[two_weeks_ago_date, current_date])
except APIException as ex:
    ... 

限制此搜索的最佳解决方案是什么?

我也知道我可以限制更多的日期,但是我们在一周的某一天创建了很多票,所以没有办法过滤更多,我只需要一直到限制。

参考:

  1. https://developer.zendesk.com/rest_api/docs/support/search
  2. https://develop.zendesk.com/hc/en-us/articles/360022563994--BREAKING-New-Search-API-Result-Limits

谢谢!

标签: pythonzendesk-api

解决方案


返回的生成器search支持 Python 切片,因此以下代码会将结果拉取到 1000 条,并防止超出新限制:

ticket_generator = zenpy_client.search(type="ticket")
print(ticket_generator[:1000])

推荐阅读