Looking for advice on handling pagination logic when querying conversation details via the Analytics API. I am building a background sync service in my Android app using Kotlin and the Genesys Cloud Platform SDK (com.genesyscloud:genesys-cloud-core). The goal is to fetch all conversation records for a specific queue within a 24-hour window to update local analytics caches.
The issue arises when the pageSize is large (e.g., 500) but the total result set is smaller than the page size. According to the documentation, pageCount should reflect the total number of pages available. However, when I send a request with pageSize=500 and the result set contains only 100 items, the response returns pageCount=1, which is correct. But when I attempt to fetch the next page by incrementing pageNumber to 2, the API returns an empty list instead of a 404 or a clear boundary error, and pageCount remains 1. This makes it difficult to implement a robust do-while loop in Kotlin that checks response.pageCount > currentPage.
Here is the JSON payload I am sending to /api/v2/analytics/conversations/details/query:
{
"dateFrom": "2023-10-25T00:00:00.000Z",
"dateTo": "2023-10-26T00:00:00.000Z",
"viewId": "my-custom-view-id",
"pageSize": 500,
"pageNumber": 1,
"groupBy": ["routing.queue.id"]
}
In my Kotlin code, I am using the AnalyticsApi().queryConversationsDetails(...) method. The response object QueryConversationDetailsResponse provides getCount() and getTotalCount(), but the pagination metadata seems inconsistent when the final page is not full. Should I be relying on getCount() < pageSize to determine if I have reached the end, or is there a specific flag in the paging object that indicates no more results? I want to avoid making unnecessary API calls that return empty lists, which impacts my app’s battery life and API rate limits.