We are attempting to build a data extraction script that pulls call detail records from the Genesys Cloud Analytics API. The objective is to iterate through all pages of results without hitting the default page size limits.
The documentation indicates that the response includes a paging object with pageSize, pageNumber, and pageCount. Our current implementation uses a while loop to fetch data until the current page number matches the total page count. However, the script terminates prematurely, missing approximately 40% of the dataset.
Here is the relevant section of our Python code using the standard requests library:
import requests
base_url = "https://api.us.genesys.cloud/analytics/v2/details"
params = {
"intervalStart": "2023-10-01T00:00:00Z",
"intervalEnd": "2023-10-02T00:00:00Z",
"viewId": "callDetail",
"pageSize": 100
}
response = requests.get(base_url, params=params, auth=(client_id, client_secret))
data = response.json()
page = 1
total_pages = data["paging"]["pageCount"]
print(f"Total pages reported: {total_pages}")
while page <= total_pages:
print(f"Fetching page {page}")
params["pageNumber"] = page
response = requests.get(base_url, params=params, auth=(client_id, client_secret))
data = response.json()
# Process data...
page += 1
The initial response shows pageCount as 5. The loop runs for page 1, 2, and 3, then exits. When we manually request page 4 via Postman, the data exists and is valid. The paging object in the response for page 3 shows pageNumber: 3 and pageCount: 5, so the loop condition should allow it to continue.
We have verified that the auth token is valid and the query parameters are correct. Is there a specific behavior with the Analytics API where pageCount changes dynamically based on the filters applied in subsequent requests? Or are we misinterpreting how the pageNumber parameter interacts with the paging object in the response body? The documentation is sparse on edge cases for large datasets.