Is it possible to efficiently handle the paging object returned by the Genesys Cloud Analytics API when using the Python SDK to export large datasets without hitting rate limits or missing data? I am writing a CI/CD script to pull historical queue metrics for the last 30 days, and the API returns a paging object with pageSize, pageNumber, and pageCount fields. My current implementation uses a while loop that increments the pageNumber until it reaches pageCount, but I am encountering inconsistent behavior where the pageCount seems to change dynamically based on the data volume, causing the loop to either terminate prematurely or request pages beyond the available data, resulting in 400 Bad Request errors. Here is the relevant snippet from my export_metrics.py script:
client = genesyscloud.AnalyticsApi(configuration)
params = {'pageSize': 100, 'pageNumber': 1, 'interval': '2023-10-01T00:00:00.000Z/2023-11-01T00:00:00.000Z'}
response = client.post_analytics_queues_metrics(params)
all_data = response.entities
while response.paging.pageNumber < response.paging.pageCount:
params['pageNumber'] += 1
response = client.post_analytics_queues_metrics(params)
all_data.extend(response.entities)
time.sleep(1) # Rate limit handling
The issue arises when response.paging.pageCount returns a value like 5, but after fetching page 5, the API indicates there is still more data, or conversely, page 5 is empty. I suspect this is due to the pageCount being an estimate rather than a strict total. How can I reliably iterate through all pages using the Python SDK? Should I be checking for an empty entities array instead of relying on pageCount? I am running this in a London timezone environment, so time-based filters are critical. Any advice on robust paging logic for bulk analytics exports would be appreciated.