Pagination loop for queues across divisions in Genesys JS SDK

I’m trying to pull a complete list of all queues from our Genesys Cloud org using the @genesyscloud/queue-client SDK. The tricky part is we have queues spread across multiple divisions, and the standard getQueues call seems to only return results for the default division or requires a specific division ID.

Here’s the loop I’ve got so far:

const queueClient = new QueueClient({ ...config });

async function getAllQueues() {
 let allQueues = [];
 let page = 1;
 
 do {
 const response = await queueClient.getQueues({
 pageSize: 250,
 page: page,
 expand: ['statistics', 'members']
 });
 
 if (response.entities && response.entities.length > 0) {
 allQueues = [...allQueues, ...response.entities];
 page++;
 } else {
 break;
 }
 } while (true);
 
 return allQueues;
}

It works for one division, but I can’t figure out how to dynamically switch the context or pass multiple division IDs without making separate calls for each. Is there a way to set the division header globally for the client, or do I need to loop through the division list first and call getQueues for each one individually? The docs are a bit vague on handling multi-division data retrieval in the SDK.

You’re overcomplicating the division part. Just hit /api/v2/queues without a divisionId parameter. It returns queues from all divisions your token can see. If you need specific ones, filter the response locally. The SDK handles pagination for you if you use the getNextPage helper.

The suggestion above is mostly correct, but there’s a catch with how the JS SDK handles pagination when you’re dealing with multiple divisions. If you just call getQueues without a division ID, it might not return everything if your org has strict division visibility rules. I’ve seen this break scripts before.

Here’s a safer approach using the PureCloudPlatformClientV2 directly. It’s more verbose but gives you full control over the pagination and division filtering.

const platformClient = require('@genesyscloud/purecloud-platform-client-v2');

const api = new platformClient.QueueApi();

async function getAllQueues() {
 let allQueues = [];
 let page = 1;
 
 while (true) {
 const response = await api.getQueues({
 pageSize: 250,
 page: page
 });
 
 if (!response.body || response.body.entities.length === 0) break;
 
 allQueues = allQueues.concat(response.body.entities);
 
 if (!response.body.nextPageUri) break;
 page++;
 }
 
 return allQueues;
}

This loop checks for nextPageUri explicitly. It’s a bit more work than using the SDK helper, but it avoids the “missing division” trap. Also, make sure your OAuth token has the view:routing:queue scope. Without it, you’ll get a 403 and the loop will fail silently if you’re not catching errors properly.

One thing to watch out for: if you have queues in divisions you don’t have access to, they simply won’t appear in the response. The API doesn’t throw an error for invisible divisions. It just omits them. So if you’re expecting a certain count and it’s short, check your user’s division membership.

I use this pattern for our WFM adherence scripts. We track agent login states against queue membership, and missing a queue due to a division issue can skew the metrics badly. It’s a pain to debug later, so getting the list right upfront saves time.