Genesys Cloud Analytics API: Handling pagination with pageSize and pageNumber

Hey everyone, trying to pull a full dataset of interaction reports using the Analytics API. The endpoint is GET /api/v2/analytics/interactions/summary. I’m using the Python SDK and passing the paging object in the request, but I’m hitting a wall when it comes to getting all the pages. The API returns a pageCount of 5, but my loop isn’t catching everything correctly. It feels like I’m either duplicating data or missing chunks entirely.

Here’s the basic structure I’ve got so far:

paging = Paging(pageSize=25000, pageNumber=1)
response = client.analytics_api.get_interactions_summary(
 interval_start='2023-10-01T00:00:00.000Z',
 interval_end='2023-10-02T00:00:00.000Z',
 paging=paging
)

print(f"Total pages: {response.paging.pageCount}")

The issue is that when I try to increment the pageNumber in a while loop to fetch the next batch, the response body stays the same for the first two iterations, then suddenly shifts. It seems like the pageSize parameter isn’t strictly limiting the results per page as I’d expect, or maybe the pageCount is calculated dynamically based on the total entity count before filtering?

I’ve tried hard-coding the pageNumber in the loop like this:

for page_num in range(1, response.paging.pageCount + 1):
 paging.pageNumber = page_num
 next_response = client.analytics_api.get_interactions_summary(
 interval_start=...
 paging=paging
 )
 # process data

But this feels brittle. Is there a cleaner way to handle this with the SDK? The docs mention using the nextPage link in the response headers, but I can’t seem to access that directly from the Python response object. It just gives me the JSON body and the paging metadata. Am I supposed to parse the raw HTTP response to get the link header? Or is there a helper method I’m missing? The current approach works but it’s messy and I feel like I’m fighting the library. Any tips on best practices for iterating through these large datasets without hitting rate limits or missing data? Also, if the pageCount changes mid-request due to new data coming in, does that break the loop?