Analytics API paging logic failing on pageSize > 1000

Looking for advice on the paging object behavior for the Analytics API. I’m trying to pull a full schedule adherence report via the SDK in Python. The docs say pageSize defaults to 100 but can go up to 1000.

I set pageSize to 1000 in the request body. First call returns fine. But when i loop through pageNumber, the second page comes back empty. The pageCount in the response header says 5, but items is an empty array for page 2 and beyond.

“The request was processed successfully but returned no items for the specified page.”

Here’s the snippet:

params = {
 'pageSize': 1000,
 'pageNumber': 1,
 'query': '...' 
}
response = client.analytics_api.get_analytics_report(query_id, params)

Is pageCount calculated before pagination or after? Feels like the server is ignoring the pageSize boost. Or am i missing a header?

The endpoint is /api/v2/analytics/reports/{reportId}/query. Status code is 200. Just empty data. Weird.

This looks like a standard pagination header mismatch issue, specifically when you’re trying to mix SDK method calls with manual loop logic.

The docs say pageSize defaults to 100 but can go up to 1000. I set pageSize to 1000 in the request body. First call returns fine. But when i loop through pageNumber, the second page comes back empty. The pageCount in the response header says 5, but items is an empty array for p

the python SDK (PureCloudPlatformClientV2) handles paging internally if you use the with_pagination decorator or the async variants. when you manually increment pageNumber, you’re likely losing the context of the pageSize or the sort order between requests. the API is strict: if the sort order changes or the page size differs from the first call, it resets the cursor, often returning empty results or throwing a validation error.

here’s how i handle this in my data action wrappers. i don’t loop manually. i let the SDK handle the Link headers. also, make sure you’re not injecting tracing headers in a way that breaks the Accept header parsing, though that usually causes 400s, not empty arrays.

from purecloudplatformclientv2 import AnalyticsApi, Configuration
from purecloudplatformv2.models import GetScheduleAdherenceRequest

config = Configuration()
api_instance = AnalyticsApi(configuration=config)

# ensure consistent sort order and page size
request = GetScheduleAdherenceRequest(
 page_size=1000,
 page_number=1,
 sort_by='startTime', # critical for stable paging
 sort_order='desc'
)

# use the iterator if available, or handle the response object properly
try:
 result = api_instance.post_analytics_schedule_adherence(
 body=request,
 with_http_info=True # check headers manually if needed
 )
 
 # check result[1] for headers like X-Page-Count
 # if using manual paging, ensure request object is identical except for page_number
 
except Exception as e:
 print(f"API call failed: {e}")

if you really need to loop, clone the request object and only update page_number. don’t recreate the GetScheduleAdherenceRequest inside the loop. that’s a common mistake. the OTel span should wrap the entire loop, not individual calls, to avoid context loss.

also, check your timezone offset in the query. if startTime spans a DST boundary, the sorting might get weird.

This is actually a known issue… the server caps pageSize at 1000 but returns empty arrays if you don’t respect the pageCount header strictly. i hit this in Go last week.

here’s the fix. check resp.PageCount() before looping. if it’s zero, stop. don’t assume pages exist just because the header says so.

if resp.PageCount > 0 {
 // process items
}