JavaScript SDK pagination for multi-division queue fetch

I need to pull every queue across all divisions using the Genesys Cloud JavaScript SDK. The getQueues method respects the divisionsId parameter, so I can’t just call it once without filtering. I’ve tried looping through getDivisions results and chaining promises, but the batch size caps out before hitting the API limit, and I’m not seeing a clean way to handle the pagination cursor across the division loop. How do you properly chain these calls to ensure you get every queue without missing pages or hitting rate limits?

Cause: The SDK’s built-in pagination helpers don’t automatically nest inside a division loop. You’re hitting rate limits because you’re firing async calls without controlling the concurrency or chaining the cursors correctly.

Solution: Flatten the logic. Fetch divisions first, then use a simple recursive loop for each division’s queues. This keeps the call stack clean and respects the API limits.

const platformClient = require('genesys-cloud-purecloud-platform-client');
const api = platformClient.QueueApi;

async function getAllQueues() {
 const divisions = await api.getOrganizationDivisions();
 const allQueues = [];
 
 for (const div of divisions.entities) {
 let nextUri = div.id; // Initial fetch uses division ID
 while (nextUri) {
 const response = await api.getQueues({ divisionId: nextUri });
 allQueues.push(...response.entities);
 nextUri = response.nextPage; // SDK handles cursor extraction
 }
 }
 return allQueues;
}

Just make sure you’re using the nextPage property from the response object. It returns the full URL for the next batch, so you don’t have to parse query params manually. Watch out for empty divisions though, they still return a valid response with zero entities.