What is the standard approach to fetch all queues across multiple divisions using the Genesys Cloud Platform SDK for JavaScript? I am currently using platformClient.queue.listQueues() but it only returns queues from the default division. I tried passing a division ID in the options object, but the SDK seems to ignore it or throw a validation error. Here is my current attempt:
const queues = await platformClient.queue.listQueues({ divisionId: 'division_id_here' });
The response is empty or incomplete. Should I be iterating through divisions manually and merging results, or is there a built-in method to bypass division scoping and retrieve everything in one call?
The easiest fix here is this is to iterate through the divisions explicitly. The SDK’s listQueues method does not natively support a “all divisions” flag or an array of division IDs in a single call. It expects a single divisionId or defaults to the authenticated user’s division. If you pass an invalid ID, it throws. If you pass nothing, it scopes to default.
Here is how I handle this in my Node.js Lambdas. I first fetch the available divisions, then parallelize the queue requests. This avoids serial bottlenecks and keeps the cold start impact minimal.
const { platformClient } = require("@genesyscloud/genesyscloud");
async function fetchAllQueues() {
// Initialize SDK (assuming env vars are set for oauthClientCredentials)
await platformClient.init({
clientId: process.env.GC_CLIENT_ID,
clientSecret: process.env.GC_CLIENT_SECRET,
basePath: process.env.GC_BASE_PATH || "https://api.mypurecloud.com"
});
// 1. Get all divisions
const { body: divisions } = await platformClient.organizations.listOrganizationsDivisions();
const divisionIds = divisions.map(d => d.id);
// 2. Fetch queues for each division in parallel
const queuePromises = divisionIds.map(async (divId) => {
try {
const { body: queues } = await platformClient.queue.listQueues({
divisionId: divId,
pageSize: 250 // Max page size
});
return queues.entities || [];
} catch (err) {
console.error(`Failed to fetch queues for division ${divId}:`, err.message);
return [];
}
});
// 3. Aggregate results
const allQueues = await Promise.all(queuePromises);
return allQueues.flat();
}
module.exports = { fetchAllQueues };
Note that listOrganizationsDivisions requires the organization:divisions:read scope. If your OAuth client lacks this, you’ll get a 403. Also, if you have a massive org, consider adding pagination logic inside the queue.listQueues call, as 250 entities might not cover all queues per division. I usually wrap this in a Step Function if the division count exceeds 50 to manage timeout limits.