CXone CX as Code CLI: export all Architect flows to JSON

Running nice-cxone export --type architect only pulls the last modified flow. We need a script to dump every flow in the org to JSON for backup. The CLI doesn’t seem to have a --all flag. Is there a way to iterate through the flow IDs via the API and chain the export commands?

The CLI really isn’t built for bulk operations, so you’ll need to script the API calls yourself. First, hit GET /api/v2/architect/flows to grab the list of all flow IDs and their metadata. You’ll want to filter out the system flows if you’re only interested in custom logic, usually by checking if the type field matches architect. Once you have that array of IDs, loop through each one and call GET /api/v2/architect/flows/{flowId}. This endpoint returns the full JSON definition for that specific flow. Make sure your OAuth token has the architect:flow:view scope, or the requests will just bounce back with 403s. It’s straightforward, but you’ll hit rate limits if you fire them off too fast, so add a small delay between requests or use concurrent requests with caution.

Here is a quick Node.js snippet using the genesys-cloud SDK to show how I usually handle this in my Terraform pre-commit hooks. It fetches the list, iterates, and saves each flow to a local directory structure that mirrors the org’s folder hierarchy.

const PlatformClient = require('@genesyscloud/platform-client-sdk');
const fs = require('fs');
const path = require('path');

async function exportAllFlows() {
 const api = PlatformClient.init({
 clientId: process.env.GENESYS_CLIENT_ID,
 clientSecret: process.env.GENESYS_CLIENT_SECRET,
 baseUri: 'https://api.mypurecloud.com'
 });
 
 const { result: flows } = await api.architectApi.getArchitectFlows();
 
 for (const flow of flows) {
 if (flow.type === 'architect') {
 const { result: flowDetail } = await api.architectApi.getArchitectFlow(flow.id);
 const filePath = path.join('backups/architect', `${flow.id}.json`);
 fs.writeFileSync(filePath, JSON.stringify(flowDetail, null, 2));
 console.log(`Exported ${flow.name}`);
 }
 }
}
exportAllFlows();

Keep an eye on the lastModified timestamp if you’re doing incremental backups, saves a lot of unnecessary I/O.