I’ve been working on a script to pull WEM adherence data for our US/Central shift. The goal is to get all the records for the last 24 hours. I’m using the Python SDK, specifically get_analytics_wfm_schedulegroup_details.
Here is the snippet I’m using:
client = Client.create_client(
client_id='my_client_id',
client_secret='my_secret',
base_url='https://api.mypurecloud.com'
)
analytics_api = client.analytics_api
# Requesting first page with size 100
resp = analytics_api.get_analytics_wfm_schedulegroup_details(
date_from='2023-10-25T00:00:00.000Z',
date_to='2023-10-26T00:00:00.000Z',
size=100,
page=1
)
print(f"Total pages: {resp.paging.page_count}")
print(f"Current page: {resp.paging.page_number}")
print(f"Records returned: {len(resp.entity)}")
The response comes back with a 200 OK. The paging object looks like this:
{
"page_count": 5,
"page_size": 100,
"page_number": 1,
"total": 450
}
This seems right. But when I loop through to get the next pages by incrementing the page parameter, the data doesn’t seem to paginate correctly. I’m getting duplicate records on page 2.
I tried setting size to 250 to reduce the number of calls, but the API returns a 400 Bad Request saying the max size is 100.
Is there a specific way to handle the pageNumber increment? Should I be using the next_page cursor from the paging object instead? The docs are a bit vague on whether page is 0-indexed or 1-indexed. I assumed 1-based since the first call used page=1 and returned results.
Also, the page_count in the first response is 5, but when I request page 5, I only get 50 records. Is that expected? I want to make sure I’m not missing any data or hitting an off-by-one error.
Any pointers on the correct loop structure would be great. I don’t want to miss any adherence gaps in the report.