Pagination logic for fetching queues across divisions with JS SDK

Hey folks,

Trying to pull a full list of queues across multiple divisions using the Genesys Cloud JS SDK. The routingApi.getRoutingQueues() method only returns the first 25 items by default. I’m trying to loop through pages, but the nextPage logic feels clunky when dealing with multiple division IDs.

Here’s what I’ve got so far:

const res = await client.platformClient.routing.getRoutingQueues({
 pageSize: 100,
 divisions: ['division1', 'division2']
});

Is there a cleaner way to handle the pagination cursor or should I just nest a while loop? The docs are a bit vague on bulk fetching.

Cause:
The JS SDK doesn’t handle multi-division pagination automatically for getRoutingQueues. When you specify multiple divisionIds, the API treats it as a single query that might still paginate if the total result set exceeds the page size (default 25). The nextPage logic feels clunky because you’re manually chaining requests without a wrapper. Also, if you’re fetching across many divisions, you might be hitting rate limits or simply making redundant calls if you’re not batching correctly.

Solution:
You need a recursive or iterative wrapper that checks the nextPage token from the response. Here’s a clean pattern using async/await that collects all queues into a single array. It handles the pagination loop cleanly so you don’t have to manually track page numbers.

const getAllQueues = async (client, divisionIds) => {
 let allQueues = [];
 let nextPage = null;

 do {
 const response = await client.platformClient.routing.getRoutingQueues({
 divisionIds: divisionIds,
 pageSize: 100, // Increase page size to reduce calls
 nextPage: nextPage
 });

 if (response.entities && response.entities.length > 0) {
 allQueues = allQueues.concat(response.entities);
 }

 nextPage = response.nextPage;
 } while (nextPage);

 return allQueues;
};

Set pageSize to 100 to minimize the number of HTTP calls. The nextPage token returned by the API is opaque, so just pass it through as-is. Don’t try to parse it. If you’re dealing with a massive org with thousands of queues, add a small delay between iterations to be polite to the API gateway, though the SDK usually handles throttling reasonably well. This approach keeps your code linear and avoids nested callbacks. Make sure you’re passing the divisionIds as an array of strings, not a comma-separated string, otherwise the filter won’t apply correctly.