Call Deploy CLI Tool Programmatically

Call Deploy CLI Tool Programmatically

You can call the CLI tool programmatically as shown in the following example:

import { deploy, dump } from 'auth0-deploy-cli';

const config = {
  AUTH0_DOMAIN: process.env.AUTH0_DOMAIN,
  AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
  AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
  AUTH0_ALLOW_DELETE: false
};


// Export Tenant Config
dump({
  output_folder: 'path/to/yaml/or/directory',   // Input file for directory, change to .yaml for YAML
  base_path: basePath,                          // Allow to override basepath, if not take from input_file
  config_file: configFile,                      // Option to a config json
  config: configObj,                            // Option to sent in json as object
  strip,                                        // Strip the identifier field for each object type
  secret                                        // Optionally pass in auth0 client secret separate from config
})
  .then(() => console.log('yey dump was successful'))
  .catch(err => console.log(`Oh no, something went wrong. <%= "Error: ${err}" %>`));


// Import tenant config
deploy({
  input_file: 'path/to/yaml/or/directory',  // Input file for directory, change to .yaml for YAML
  base_path: basePath,                      // Allow to override basepath, if not take from input_file
  config_file: configFile,                  // Option to a config json
  config: configObj,                        // Option to sent in json as object
  env,                                      // Allow env variable mappings from process.env
  secret                                    // Optionally pass in auth0 client secret separate from config
})
  .then(() => console.log('yey deploy was successful'))
  .catch(err => console.log(`Oh no, something went wrong. <%= "Error: ${err}" %>`));

Was this helpful?

/

Troubleshooting

The auth0-deploy-cli tool uses the Management API to pass through objects for create, update, and delete actions.

You may occasionally see Bad Request and Payload validation errors returned by the Management API. These errors usually mean the object you're working with has attributes which are not writable or are no longer available. This can happen when you are exporting from an older Auth0 tenant and importing into a newly-created tenant.

If this is the case, update your configuration to support the new object format used by Auth0.

Learn more