Import Content Using the CLI
After exporting content from a source stack, unzip the exported file and then use the Contentstack CLI to import it into the destination stack.
This guide covers how to use the cm:stacks:import command with:
- Authentication via CLI login or a management token
- Content import using a configuration file or CLI parameters
Prerequisites
- Contentstack account
- Contentstack CLI installed
- CLI authenticated
- Configured management token (optional)
- Exported content extracted (unzipped) in a local folder
Supported Modules
- Assets
- Locales
- Environments
- Stacks (CLI supports Stacks from v1.43.0)
- Extensions
- Marketplace Apps
- Webhooks
- Global Fields (CLI supports Nested Global Fields from v1.42.0)
- Content Types
- Entries
- Labels
- Workflows
- Custom Roles
- Taxonomies
- Personalize
- Studio
Note: Imported content gets published to the same environment and locale as in the source stack. Unpublished content in the source stack remains unpublished after import.
Commands
The cm:stacks:import command lets you import content into your destination stack.
Note: By default, an audit fix is performed on the exported content before import. This helps identify and address potential issues in the exported data.
Usage
csdx cm:stacks:import -k <<stack_ApiKey>> -d <<path_of_folder_where_content_is_stored>>
Options
Use the following options with any applicable import command:
- -k, --stack-api-key=stack-api-key: API key of the target stack.
- -a, --alias=alias: Management token alias of the destination stack.
- -d, --data-dir=data-dir: Absolute path to the folder with your exported content.
Example: -d "C:\Users\Name\Desktop\cli\content"
If using branches, include the branch folder in the path:
-d "C:\Users\Name\Desktop\cli\content\branch_name" - --branch=branch: [default: main] Name of the branch to import content into.
- --branch-alias=branch-alias: Alias of the branch to import content into.
- --exclude-global-modules: Exclude branch-independent modules from the import operation.
- --module=module: (optional) Import a specific module into the target stack. If not specified, all modules are imported.
Available modules: assets, content-types, entries, environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks, workflows, custom-roles, taxonomies, personalize, and studio.
- --backup-dir=backup-dir: (optional) Backup directory name for a specific module.
- --import-webhook-status=<option>: [default: disable] Maintain webhook state configuration from the source stack. <options: disable|current>
- --skip-audit: (optional) Skip the audit fix that occurs during import.
- --skip-app-recreation: (optional) Skip the recreation of private apps if they already exist.
- --skip-assets-publish: Skip asset publishing during import.
- --skip-entries-publish: Skip entry publishing during import.
- -y, --yes: Force override all Marketplace prompts.
- -c, --config=config: Path to the configuration JSON file containing all the options for a single run.
- --skip-existing: (Optional) Skips the module exists warning messages.
- --personalize-project-name=<value>: (Optional) Unique name for the Personalize project.
Note:
- If you do not use the --yes flag during import:
- You’ll be prompted to enter an encryption key for Marketplace App configurations.
- You have three attempts to enter the correct key. After three failed attempts, the import process stops and must be restarted from the beginning.
- If you don’t use the --skip-audit flag during import:
- The audit step removes all workflow branches except the one you're importing into.
- For example, if your source stack includes main, development, and production, and you import into development, the audit deletes the main and production branches from the workflow module.
Module-wise Import
Use the --module flag in the import command to import individual modules into the target stack. If you do not use the flag, the import command includes all available modules by default.
Dependency Order
Some modules depend on others. When importing modules individually, follow this sequence to avoid errors:
Locales → Environments → Assets → Taxonomies → Extensions → Marketplace Apps → Webhooks → Global Fields → Content Types → Personalize → Workflows → Entries → Labels → Custom Roles → Studio.
Note: Before importing a module, ensure all its dependencies have been imported.
Example:
- To import only locales:
csdx cm:stacks:import --stack-api-key bltxxxxxx -d "C:\Users\Name\Desktop\cli\content" --module locales
Use of --backup-dir Flag
When importing modules individually with the import command, include the --backup-dir flag to prevent errors caused by inter-module dependencies. This flag stores mapping files that are required by dependent modules in future imports.
csdx cm:stacks:import --stack-api-key <<stack_ApiKey>> -d <<path_of_folder_where_content_is_stored>> --module <<module>> --backup-dir <<backup_dir>>
During each module import, the system saves updated mapping files in the specified backup folder. These mappings are reused by dependent modules to ensure consistent and successful imports.
Note: The parent backup folder created during the initial import can be reused for subsequent module imports. To avoid errors, always include the --backup-dir flag when importing modules one at a time.
Examples
- To import assets into a stack:
csdx cm:stacks:import --stack-api-key bltxxxxxx -d "C:\Users\Name\Desktop\cli\content" --module assets - To import entries into a stack with backup mapping:
csdx cm:stacks:import --stack-api-key bltxxxxxx -d "C:\Users\Name\Desktop\cli\content" --module entries --backup-dir <backup_dir>
Using Configuration File
You can also import content using a configuration file that stores all required parameters and values.
To get started, follow the steps below:
- Download the configuration file.
- Add your values.
- Save the file and note its path.
Usage
csdx cm:stacks:import -c <<config_file_path>>
Example
- To import content using a configuration file:
csdx cm:stacks:import -c "C:\Users\Name\Desktop\cli\config.json"
Note:
- Mac OS users must use \ for paths in a JSON file.
- Windows OS users must use \\ for paths in a JSON file.
Using a configuration file simplifies the import process by storing all required parameters and values in one place. This removes the need to enter each option manually and is helpful for repeated or complex imports.
Import Content Using Management Token
Use a management token to import content into a stack when you prefer token-based authentication instead of CLI login. You can pass the token directly through the command line or reference it from a configuration file.
Usage
csdx cm:stacks:import -a <<alias>>
Optional Parameters:
- -d <path_of_folder_where_content_is_stored>: Specify the folder where the content is located.
- -c <config_file_path>: Use a configuration file that contains all import parameters.
Examples:
- To import content from a specific folder:
csdx cm:stacks:import --alias mytoken -d "C:\Users\Name\Desktop\cli\import-folder" - To import content using a configuration file:
csdx cm:stacks:import --alias mytoken -c "C:\Users\Name\Desktop\cli\config.json"
Import Overwrite Feature
Use the --replace-existing flag in the import command to overwrite the existing content in the target stack. This prevents import failures caused by module collisions and ensures that existing items are overwritten while new items are added.
When the import process detects a module that already exists in the target stack, the CLI replaces it instead of throwing an error. If the module does not exist, the CLI creates it as a new item.
Example:
csdx cm:stacks:import --replace-existing --backup-dir <backup-dir-path> --stack-api-key <value> -d <content-dir-path>
For more details, refer Overwrite Existing Content using CLI Import document.
Toggle Between Console Logs and Progress Manager View (2.x.x-beta)
Contentstack CLI lets you toggle between the raw console logs and the visual Progress Manager UI during import or plugin workflows.
Default Usage:
csdx cm:stacks:import -d "./export-data" --stack-api-key bltxxxxxx
Note: By default, the Progress Manager UI displays when you run the import command and does not require any configuration.
Example for Progress Manager View (Default Mode):
LOCALES:
├─ Master Locale |████████████████████████████████████████| 100% | 1/1 | ✓ Complete (1/1)
├─ Locales Create |████████████████████████████████████████| 100% | 1/1 | ✓ Complete (0/1)
├─ Locales Update |████████████████████████████████████████| 100% | 1/1 | ✓ Complete (1/1)
ENVIRONMENTS:
└─ Environments |████████████████████████████████████████| 100% | 2/2 | ✓ Complete (2/2)
STACK:
└─ Stack |████████████████████████████████████████| 100% | 1/1 | ✓ Complete (1/1)
ASSETS:
├─ Folders |████████████████████████████████████████| 100% | 2/2 | ✓ Complete (2/2)
├─ Upload |████████████████████████████████████████| 100% | 12/12 | ✓ Complete (12/12)
├─ Publish |████████████████████████████████████████| 100% | 12/12 | ✓ Complete (12/12)
TAXONOMIES:
└─ Taxonomies |████████████████████████████████████████| 100% | 1/1 | ✓ Complete (1/1)
EXTENSIONS:
├─ Extensions Create |████████████████████████████████████████| 100% | 1/1 | ✓ Complete (1/1)
Steps to Switch to Console Logs (Optional):
- Run the following command to switch to console log mode:
csdx config:set:log --show-console-logs
- Run the import command:
csdx cm:stacks:import -d "./export-data" --stack-api-key bltxxxxxx
The screen displays the console logs for the import operation.
Tip: Use --show-console-logs for detailed debugging when troubleshooting import issues.
- Run the following command to switch back to default mode:
csdx config:set:log --no-show-console-logs
Options:
- --show-console-logs: Displays the console logs for the operation.
- --no-show-console-logs: Hides the console logs and displays the Progress Manager view for the operation.
Example for Console Log Mode:
[2025-09-10 19:19:02] INFO: Audit process completed [2025-09-10 19:19:03] INFO: Starting to import content version 2 [2025-09-10 19:19:03] INFO: Starting import of locales module [2025-09-10 19:19:05] INFO: Created locale: 'fr-fr' [2025-09-10 19:19:07] INFO: Updated locale: 'fr-fr' [2025-09-10 19:19:07] SUCCESS: Languages have been imported successfully! [2025-09-10 19:19:07] INFO: Starting import of environments module
Limitations
- Only the latest version of published entries or assets is imported.
- Workflow imports do not include admins or workflow stage users.
- To resolve maxContentLength and maxBodyLength errors, include these parameters in the configuration JSON with values in bytes. The default limit is 100MB. For implementation details, refer to the example configuration file.
- To manage API request timing and prevent concurrency issues, add the delayMs parameter to your configuration JSON.
Example: delayMs: 1000 (adds a 1-second delay between API requests). - The following modules cannot be imported through CLI:
Additional Resource: Learn more about the CLI-supported import operations in the Support for CLI-Based Stack Import Operations document.
More articles in "Contentstack CLI Core Commands"
