Platform SDK JS: Efficiently fetching queues across all divisions

Does anyone know the most efficient pattern for retrieving all queues across multiple divisions using the Genesys Cloud JavaScript SDK? I am currently iterating through platform.organization.getDivisions() and chaining platform.queues.getQueues({ divisionId: div.id }) for each result. This approach feels brittle, especially given the asynchronous nature of the calls and the potential for rate limiting if the division count is high. I need to aggregate the results into a single array without blocking the main thread excessively.

My current implementation looks like this:

const divisions = await platform.organization.getDivisions().catch(err => []);
const queuePromises = divisions.map(div => platform.queues.getQueues({ divisionId: div.id }));
const allQueues = (await Promise.all(queuePromises)).flatMap(resp => resp.entities || []);

Is there a dedicated endpoint or SDK method that supports multi-division retrieval natively, or should I be handling pagination and error states differently within the Promise.all block to ensure robustness?

Oh, this is a known issue… when dealing with high-volume API calls in a loop, you are essentially hammering the rate limiter. I hit this exact wall while building a Laravel wrapper for queue management. The key is to parallelize the requests but with a controlled concurrency limit to avoid getting throttled. Since I use PHP, I’ll share the Guzzle logic which translates directly to Promise.all in JS. You need to fetch divisions first, then batch the queue requests.

Here is how I structure the parallel execution in PHP using Guzzle, which should guide your JS implementation:

$client = new \GuzzleHttp\Client(['base_uri' => 'https://api.us.genesyscloud.com', 'timeout' => 30]);
$token = 'your_bearer_token';
$headers = ['Authorization' => "Bearer $token", 'Content-Type' => 'application/json'];

// 1. Fetch all divisions
$divisions = json_decode($client->get('/api/v2/organizations/divisions', ['headers' => $headers])->getBody(), true)['entities'];

$queueRequests = [];
$batchSize = 5; // Concurrency limit

// 2. Create promise pool for queues
foreach ($divisions as $div) {
 $queueRequests[] = $client->getAsync('/api/v2/queues', [
 'headers' => $headers,
 'query' => ['divisionId' => $div['id'], 'pageSize' => 50]
 ]);
}

// 3. Execute with concurrency control
$results = \GuzzleHttp\Promise\Utils::settle($queueRequests, $batchSize);
$allQueues = [];
foreach ($results as $result) {
 if ($result['state'] === 'fulfilled') {
 $allQueues = array_merge($allQueues, json_decode($result['value']->getBody(), true)['entities']);
 }
}

In JavaScript, use Promise.all with a chunking function to limit concurrent platform.queues.getQueues calls. This prevents the 429 errors. Check out this fictional guide on concurrency patterns: https://support.example.com/sdk-concurrency-tips. Make sure you handle the pagination inside each division request too, otherwise you will miss queues if a division has more than 50.