Analytics API paging object pagination logic and pageSize handling

Running into some unexpected behavior with the paging object in the Genesys Cloud Analytics API. I’m trying to fetch historical data for a specific metric and I need to handle pagination manually since the SDK doesn’t seem to auto-paginate for this specific endpoint.

Here’s the setup. I’m using the Python SDK genesyscloud version 7.0.0. I’m calling get_routing_analytics_queue_metrics with a pageSize of 1000. The response includes a paging object with pageSize, pageNumber, and pageCount.

from genesyscloud import analytics_api

client = analytics_api.AnalyticsApi()

# Initial request
result = client.get_routing_analytics_queue_metrics(
 metric_ids=['queue/conversations/offered'],
 date_from='2023-10-01T00:00:00.000Z',
 date_to='2023-10-31T23:59:59.999Z',
 group_by=['date'],
 page_size=1000
)

print(f"Page Count: {result.paging.page_count}")
print(f"Page Number: {result.paging.page_number}")
print(f"Page Size: {result.paging.page_size}")

The issue is that pageCount seems to be static based on the total number of entities, but pageNumber in the response is always 1 unless I explicitly pass a page parameter. However, the docs are a bit vague on whether pageNumber in the response reflects the current page fetched or just confirms the request parameter.

I noticed that if I set pageSize to something large, say 5000, the API returns a 400 error saying the page size is too large. But there’s no clear max documented. I tried 2000 and it worked.

My loop looks like this:

current_page = 1
while True:
 result = client.get_routing_analytics_queue_metrics(
 metric_ids=['queue/conversations/offered'],
 date_from='2023-10-01T00:00:00.000Z',
 date_to='2023-10-31T23:59:59.999Z',
 group_by=['date'],
 page_size=1000,
 page=current_page
 )
 
 # Process data
 for entity in result.entities:
 process_entity(entity)
 
 if current_page >= result.paging.page_count:
 break
 
 current_page += 1

Sometimes result.paging.page_count is 0 even though there’s data. Other times it’s accurate. Is pageCount reliable for determining the end of pagination? Or should I be checking if the returned entities list is empty?

Also, is there a recommended max pageSize to avoid rate limiting issues? I’m seeing some 429s when I loop too fast.

Any insights on the most solid way to handle this pagination in code?