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.