Fetching queues across all divisions with Genesys Cloud JS SDK

Here is the code I’m using to pull queues:

import { PureCloudPlatformClientV2 } from '@genesyscloud/genesyscloud';

const apiInstance = new PureCloudPlatformClientV2.QueueApi();
const result = await apiInstance.getQueues({
 divisionId: 'some-division-id',
 pageSize: 50
});

The thing is, I need to get queues from every single division in the org. My current approach involves calling getDivisions() first, then looping through each division ID and calling getQueues for each one. It feels wrong. The API docs mention a divisionId parameter but don’t clearly state if omitting it returns everything or just the default division.

I tried leaving divisionId out of the options object:

const result = await apiInstance.getQueues({
 pageSize: 50
});

But it only returns queues from the default division. I checked the HTTP request being made and it doesn’t include the divisionId header or query param, which makes sense why it’s scoped. Is there a way to tell the SDK to ignore division scoping? Or do I really have to write a loop like this?

const divisions = await apiInstance.getDivisions();
const allQueues = [];
for (const div of divisions.entities) {
 const queues = await apiInstance.getQueues({ divisionId: div.id });
 allQueues.push(...queues.entities);
}

This feels inefficient if we have hundreds of divisions. The loop runs sequentially and takes forever. I know I could parallelize it with Promise.all, but I’m worried about hitting rate limits on the Queue API endpoints. The SDK documentation for the JavaScript client is a bit sparse on best practices for bulk operations across divisions.

I also tried using the expand parameter but that just adds more data to each queue object, it doesn’t change the division scope. I’m building a custom agent desktop app using the Embeddable Client App SDK, and I need this data to populate a dropdown. The latency of the loop is causing the UI to freeze for a few seconds. Is there a better pattern here? Maybe a different API endpoint? Or am I stuck with the loop?