Just noticed that our SvelteKit server route for fetching queue stats is looping forever. i’m using the Analytics API to pull queue:stat data for the last 24 hours. The first page comes back fine, but the second page contains exactly the same records as page 1. It’s like the pageToken isn’t advancing properly or i’m parsing it wrong.
Here’s the fetch logic in our server function:
const getQueueStats = async () => {
let allStats = [];
let nextPageToken = null;
let pageCount = 0;
do {
const params = new URLSearchParams({
pageSize: 200,
nextPageToken: nextPageToken,
interval: 'PT1H',
query: 'queueId in [12345]'
});
const res = await fetch(`https://api.mypurecloud.com/api/v2/analytics/queues/statistics${params.toString()}`);
const data = await res.json();
if (data.pageInfo && data.pageInfo.pageToken) {
nextPageToken = data.pageInfo.pageToken;
allStats.push(...data.page);
pageCount++;
console.log(`Fetched page ${pageCount}, token: ${nextPageToken}`);
} else {
nextPageToken = null;
}
} while (nextPageToken);
return allStats;
};
The logs show the token changing every iteration, but the data.page array is identical. i’ve checked the raw JSON response and the pageToken in pageInfo looks like a valid base64 string. Is there a known issue with the Analytics API ignoring subsequent tokens for this specific endpoint? Or am i missing a header?
- Checked OAuth token validity - it’s fresh.
- Verified the
pageSizeisn’t hitting a hard limit.
This really shouldn’t be this hard. The docs just say “use the returned token”. i’m stuck.