Hey folks,
I’m trying to pull a full history of WEM adherence metrics for a specific team using the Analytics API. The goal is straightforward: iterate through all pages and aggregate the data into a single CSV for my weekly report. I’ve been using the Python SDK, but I keep hitting a wall where the loop terminates prematurely or throws an index error.
Here’s the basic structure I’m using:
from genesyscloud import analytics_api
analytics_client = analytics_api.AnalyticsApi(configuration)
params = {
'query': 'from:interaction interval:1d dateFrom:2023-10-01T00:00:00.000Z dateTo:2023-10-31T23:59:59.999Z',
'pageSize': 100,
'pageNumber': 1
}
all_data = []
try:
while True:
response = analytics_client.post_analytics_conversations_details_query(**params)
all_data.extend(response.entities)
# This is where I get stuck
if params['pageNumber'] >= response.pageCount:
break
params['pageNumber'] += 1
except Exception as e:
print(f"Failed: {e}")
The first page comes back fine with pageCount: 5. The code increments pageNumber to 2 and fetches the next batch. But when it tries to fetch page 3, I sometimes get a 400 Bad Request saying the page number is out of range, even though pageCount clearly indicated there were more pages. Other times, the loop runs forever because response.pageCount seems to reset or change depending on the query load.
I’ve read the docs on paging, but they’re a bit vague on whether pageCount is static or dynamic. Should I be checking hasMore instead? Or is there a specific way to handle the offset in the query string? I don’t want to miss any adherence records, but I also don’t want my script hanging indefinitely.
Any examples of a solid paging loop in Python for this specific endpoint would be appreciated.