Batch fetching queues across divisions in JS SDK

How should I properly to fetch all queues across multiple divisions using the Platform SDK for JavaScript without hitting rate limits? I am refactoring our staging validation script to check queue configurations before a Terraform apply. Currently, I am iterating through a list of division IDs and calling genesyscloud.queuesApi.getQueues for each one. This works for a single division but fails when we scale to our production-like environment with over 50 divisions. The issue is not just performance but also the asynchronous nature of the requests causing unhandled promise rejections if the SDK throttles us. I tried wrapping the calls in a loop with async/await, but it still feels brittle. Here is my current approach:

const divisions = ['div-1', 'div-2', 'div-3']; for (const div of divisions) { const response = await genesyscloud.queuesApi.getQueues({ divisionId: div }); console.log(Fetched queues for ${div}: ${response.body.entities.length}); }

The problem arises when divisionId is null or when I try to omit it to get a global list. The API returns a 400 Bad Request if I send an empty string, and omitting the parameter entirely seems to default to the user’s primary division only, missing the cross-division queues we need to validate. I want to avoid manual pagination logic for each division if the SDK supports a batch or multi-division endpoint. Is there a method like getQueuesWithDivisions or a way to pass an array of division IDs directly to the getQueues call? Or should I be using the low-level genesyscloud.platformClientApi.getQueues with a custom header? I need a robust pattern that handles the 200 OK responses efficiently and aggregates the entities into a single map for our CI/CD check.

The root of the issue is that you are treating the SDK like a synchronous iterator when it should handle concurrency. You need to parallelize the requests using Promise.all to avoid the rate limit hammer.

Promise.all will batch the GET calls internally, and you just need to map your division IDs to the API calls. Here is the pattern:

const queuePromises = divisionIds.map(async (id) => {
 return await genesyscloud.queuesApi.getQueues({ divisionId: id });
});
const results = await Promise.all(queuePromises);

Have you tried using the GET /api/v2/queues endpoint without specifying a division ID? This returns all queues across the organization in a single request, bypassing the need for multiple calls.

const queuesResponse = await genesyscloud.queuesApi.getQueues({
 pageSize: 250
});

The SDK handles pagination automatically, and this approach avoids rate limits entirely since it is one API call instead of fifty.