Platform SDK JS: Fetching queues across all divisions without pagination loops

We are migrating our queue inventory scripts from direct REST calls to the Genesys Cloud Platform SDK for JavaScript. The objective is to retrieve every queue in the organization, regardless of the division. The current implementation relies on api.routing.listQueues() with expand: 'members' to get detailed membership data. The issue arises when handling multiple divisions. The SDK does not expose a simple fetchAll method that automatically iterates through divisions. We are currently writing a manual loop to fetch division IDs first, then iterating through each division to call listQueues. This approach feels brittle and prone to missing newly created divisions if the division list is stale. The code structure looks like this:

const divisions = await api.organizations.listOrganizations();
const allQueues = [];
for (const div of divisions.entities) {
 const queues = await api.routing.listQueues({
 divisionId: div.id,
 expand: 'members'
 });
 allQueues.push(...queues.entities);
}

This works for small orgs, but it’s inefficient. We are also seeing occasional 429 Too Many Requests errors when running this against large tenant environments. We want to avoid hitting rate limits by making sequential calls. Is there a more efficient pattern in the JS SDK to handle this? We considered using the pageToken approach with listQueues without a divisionId, but the documentation suggests that omitting divisionId returns queues only for the default division. We need to ensure we capture queues in non-default divisions as well. The goal is to have a single, solid method to export queue data for state backup purposes. We’ve tried setting pageSize to the maximum allowed value, but that only helps within a single division. We are looking for a best practice or a hidden SDK feature that simplifies cross-division resource aggregation. Any insights on how others handle this in their CX-as-Code pipelines would be appreciated.

The JS SDK doesn’t have a built-in pager for queues. You’ll need to loop on nextPageUri from the response.

let next = '/api/v2/routing/queues';
while (next) {
 const resp = await platformClient.RoutingApi.getQueues({ expand: 'members' }, next);
 next = resp.body.nextPageUri;
 // process resp.body.entities
}