cs-icon.svg

Export Content using the CLI

If you want to migrate your content from one stack to another, you need to export the content from the source stack and then import it into the destination stack.

You can export the following modules from a stack:

Prerequisites

Commands

The cm:stacks:export command lets you export content from one stack to another.

Below we have listed down how you can use the cm:stacks:export command:

Let us understand in detail how you can export content from your stack.

Note: In a stack with no branches, the exported data is stored in the root folder. In a branch-enabled stack, all the exported data is stored in the folder of the selected branch. Also, if there are several branches, each branch content is exported to its respective folder.

Example for storage of stack with no branches:

CLI_Taxonomy_Export_NoBranch.png

Example for storage of branch-enabled stack:

CLI_Taxonomy_Export_Branch.png

Export Content Using Management Token and Parameters

This command lets you export content using a management token. For ease, you can pass several parameters/options to this command at once.

Tip: To store the exported content efficiently, create a folder named “content” in your system and make a note of its path.

Usage

csdx cm:stacks:export -a <<alias>>

Alternatively, refer to the following command to add several parameters/options in a single line:

csdx cm:stacks:export -a <<alias>> -d <<file_path>>

Options

  • -c--config=config: [optional] Path of the config.
  • -k--stack-api-key=stack-api-key: API key of the source stack.
  • -a, --alias=alias: The management token alias of the source stack from which you will export content.
  • -d, --data-dir=data-dir: The path or the location in your file system to store the exported content. For e.g., ./content
  • --branch=branch: The name of the branch where you want to export your content. If you don’t mention the branch name, then by default the content will be exported from all the branches of your stack.
  • --module=module: [optional] Specific module name. If not specified, the export command will export all the modules to the stack. The available modules are assets, content-types, entries, environments, extensions, marketplace-apps, global-fields, labels, locales, webhooks, workflows, custom-roles and taxonomies.
  • --content-types=content-types: [optional] The UID of the content type(s) whose content you want to export. In case of multiple content types, specify the IDs separated by spaces.
  • --secured-assets=secured-assets: [optional] Use this flag for assets that are secured.
  • -y, --yes: Force override all Marketplace prompts.

    Note: If the --yes flag is not passed, you are prompted to enter an encryption key while exporting the Marketplace App for the app configurations.

Examples:

  • To export all modules from a stack:
    csdx cm:stacks:export -a mytoken  -d "C:\Users\Name\Desktop\cli\content"
    
  • To export all modules from a particular branch of your stack (For example: develop).
    csdx cm:stacks:export -a mytoken -d "C:\Users\Name\Desktop\cli\content" --branch develop
    
  • To export only content types from a stack:
    csdx cm:stacks:export -a mytoken  -d "C:\Users\Name\Desktop\cli\content" --module content-types
    
  • To export only environments from a stack:
    csdx cm:stacks:export -a mytoken  -d "C:\Users\Name\Desktop\cli\content" --module environments
    

Note: When exporting modules individually, make sure you follow this module sequence: assets > environments > locales > extensions > marketplace-apps > webhooks > taxonomies > global-fields > content-types > workflows > entries > labels > custom-roles. For example, before exporting entries, you must have had exported assets, environments, locales, extensions, marketplace-apps, webhooks, taxonomies, global-fields, content-types, and workflows.

Export Content Using Management Token and Config file

This command lets you export content to your stack using a management token and a configuration file containing the parameters/options and their associated values.

To get started with this command, download this config file, add values to this file, and note down the path where you have saved this file. By doing so, you don’t need to provide parameters/options in the command separately.

Note:
  • Mac OS users must use "\" for paths in a JSON file.
  • Windows OS users must use "\\" for paths in a JSON file.

Tip: To store the exported content efficiently, create a folder named “content” in your system and make a note of its path.

Usage

csdx cm:stacks:export -a <<alias>> -c <<config_file_path>>

Options

  • -a,--alias=alias: The management token alias of the source stack from where you export content.
  • -c--config=config: The path of the configuration JSON file containing all the options for a single run. You can refer to this example config file

Example

  • To export content using a config file:
    csdx cm:stacks:export -a mytoken -c “C:\Users\Name\Desktop\cli\config.json

Export Content Using Auth Token and Parameters

You can use this method to export content to your stack if you have logged in to the session using the Login command. Running the Login command generates an auth token, which is used in the command below.

Tip: To store the exported content efficiently, create a folder named “content” in your system and note its path.

Usage

Refer to the below command for adding several parameters/options in a single line:

csdx cm:stacks:export -k <<stack_ApiKey>> -d <<file_path>>

Note: If the management token is not specified, by default export command uses Auth token.

Options

  • -d, --data-dir=data-dir: The path or the location in your file system to store the exported content. For e.g., ./content
  • -k,--stack-api-key=stack-api-key: The API key of the source stack.
  • --branch=branch: The name of the branch where you want to export your content. If you don’t mention the branch name, then by default the content will be exported from all the branches of your stack.
  • --module=module (optional): Specify the module to export to the source stack. If not specified, the export command will export all the modules to the stack. The available modules are assets, content-types, entries, environments, extensions, marketplace-apps, global-fields, labels, locales, workflows, releases, webhooks, custom-roles and taxonomies.
  • --secured-assets=secured-assets: Use this flag to export your content, if the secured assets feature is enabled for your stack.
  • -y, --yes: Force override all Marketplace prompts.

    Note: If the --yes flag is not passed, you are prompted to enter an encryption key while exporting the Marketplace App for the app configurations.

    Note: Make sure to add the --secured-assets flag to avoid errors while exporting content for the stack where the secured assets feature is enabled.

Examples

  • To export all modules from a stack:
    csdx cm:stacks:export -d "C:\Users\Name\Desktop\cli\content" -k bltxxxxxx 
    
  • To export all modules from a particular branch of your stack (For example: develop).
    csdx cm:stacks:export -d "C:\Users\Name\Desktop\cli\content" -k bltxxxxxx  --branch develop
    
  • To export only content types from a stack:
    csdx cm:stacks:export -d "C:\Users\Name\Desktop\cli\content" --module content-types -k bltxxxxxx 
    
  • To export only environments from a stack:
    csdx cm:stacks:export -d "C:\Users\Name\Desktop\cli\content" --module environments -k bltxxxxxxxx 
    
  • To export content from your stack where secured assets feature is enabled:
    csdx cm:stacks:export -d "C:\Users\Name\Desktop\cli\content" -k bltxxxxxx --secured-assets
    

Note: When exporting modules individually, make sure you follow this module sequence: assets > locales > environments > extensions > marketplace-apps > webhooks > taxonomies > global-fields > content-types > workflows > entries > labels > custom-roles.For example, before exporting entries, you must have had exported assets, environments, locales, extensions, marketplace-apps, webhooks, taxonomies, global-fields, content-types, and workflows.

Export Content Using Auth Token and Config file

This command lets you export content to your stack using an auth token and a configuration file containing the parameters/options and their associated values. 

To get started with this command, download this config file, add values to this file, and note down the path where you have saved this file.

By doing so, you don’t need to provide parameters/options in the command separately.

Note:
  • Mac OS users must use "\" for paths in a JSON file.
  • Windows OS users must use "\\" for paths in a JSON file.

Tip: To store the exported content efficiently, create a folder named “content” in your system and make a note of its path.

Usage

csdx cm:stacks:export -c <<config_file_path>>

Options

  • -c, --config=config: The path of the configuration JSON file containing all the options for a single run. You can refer to this example config file.

Example

  • To export content using a config file:
    csdx cm:stacks:export -c “C:\Users\Name\Desktop\cli\config.json

Support for Marketplace Apps

You can export public and private Marketplace Apps from a stack using CLI commands.

Note:
  • You must be logged in to your Contentstack account to perform the export operation on Marketplace Apps.
  • If you use a region other than NA, EU, Azure NA, Azure EU, or GCP-NA, you must provide the Developer Hub URL for the specific region when prompted.
  • You must have owner or admin rights to perform Marketplace Apps export.
  • To override the default Marketplace App Encryption Key you can replace the config.json file.

Support for Variants

If the stack you are exporting is synced with a Personalize project, then the following items will be exported along with the stack:

  • The corresponding Personalize project
  • The modules within the Personalize project, including:
    • Experiences
    • Audience
    • Attributes
    • Events
  • Entry Variants (exported from the stack as part of entries)

Limitations

  • For assets, if you are exporting two or more assets having the same UID and file name, then only the first asset in the queue will get exported.
  • Currently, you cannot export content from the following modules:

Next Steps

Was this article helpful?
^