Genesys Cloud JS SDK: Fetching queues across multiple divisions

I need to retrieve all queues across various divisions using the Genesys Cloud Platform SDK for JavaScript. The QueuesApi.getQueues() method only returns results for the authenticated user’s division by default. How do I iterate through all divisions properly? I have tried calling OrganizationsApi.getOrganizations() but the pagination logic seems off. Is there a built-in helper or a specific pattern to handle this without hitting rate limits?

The QueuesApi doesn’t have a built-in “get all across divisions” helper, so you’re right to look at the division logic. The key is using the divisionId parameter in the request body or query string, but you first need the list of divisions.

Here’s a pattern that works for our instrumentation scripts. We fetch divisions first, then loop through them. Be careful with rate limits if you have hundreds of divisions. We usually batch these calls or add a small delay.

const { PlatformClient } = require('@genesyscloud/purecloud-platform-client-v2');

async function getAllQueues(platformClient) {
 const divisions = await platformClient.DivisionsApi.getDivisions();
 const allQueues = [];

 for (const division of divisions.entities) {
 try {
 // Get queues for this specific division
 const queues = await platformClient.QueuesApi.getQueues({
 divisionId: division.id,
 pageSize: 250 // Max page size
 });

 if (queues.entities) {
 allQueues.push(...queues.entities);
 }
 
 // Small delay to avoid hitting rate limits if you have many divisions
 await new Promise(resolve => setTimeout(resolve, 100));
 } catch (error) {
 console.error(`Failed to fetch queues for division ${division.id}:`, error);
 }
 }

 return allQueues;
}

You’ll need to handle pagination if a single division has more than 250 queues. The QueuesApi.getQueues response includes a nextPageUri. You can loop until nextPageUri is null.

Also, make sure your OAuth scope includes queue:view or admin:queue:view depending on what you’re trying to access. If you’re hitting 403s, check the token scopes.

We use this in our New Relic Lambda functions to correlate queue data with transaction traces. It’s a bit verbose but reliable.