Import Content Using the CLI

After you have exported the content from the stack from the source stack, the next step is to import it into the destination stack. To do this, you can use the import command in several ways.

Note: Before you try the import commands, make sure you have unzipped the exported content from the folder that contains the exported content.

Content can be imported in a stack for the following modules:

Note: The imported content, in the target stack, will be automatically published to the environment and locale in which it was previously published in the source stack. If any exported content wasn’t published on any environment, that particular content won’t get published to any environment after it is imported into the target stack.

Prerequisites

Commands

The cm:import command lets you import content to your destination stack. Below we have listed down the ways in which you can use the cm:import command:

Let's discuss in detail how you can import content in your stack.

Import Content Using Management Token and Parameters

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

Usage

csdx cm:import -a <management_token_alias>

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

csdx cm:import -a <management_token_alias> -d <path_of_folder_where_content_is_stored> 

Options

  • -a, --management-token-alias=management-token-alias: The management token of the destination stack to which you will import the content
  • -d, --data=data: The path or the location in your file system where the content, you intend to import, is stored. For example, -d "C:\Users\Name\Desktop\cli\content"
  • -m, --module=module: (optional) Specify the module to import into the target stack. If not specified, the import command will import all the modules into the stack. The available modules are assets, content-types, entries, environments, extensions, global-fields, labels, localeswebhooks, and workflows.

Examples

  • To import all modules into a stack:
    csdx cm:import -a mytoken -d "C:\Users\Name\Desktop\cli\content"
  • To import only content types into a stack:
    csdx cm:import -a mytoken -d "C:\Users\Name\Desktop\cli\content" -m content-types 
    OR
    csdx cm:import -a mytoken -d "C:\Users\Name\Desktop\cli\content" --module content-types 
  • To import only environments into a stack:
    csdx cm:import -a mytoken -d "C:\Users\Name\Desktop\cli\content" -m environments
    OR
    csdx cm:import -a mytoken -d "C:\Users\Name\Desktop\cli\content" --module environments 

Note: When importing  modules individually, make sure you follow this module sequence: locales > environments > assets > extensions > webhooks > global-fields > content-types > workflows > entries > labels.  For example, before importing entries, you must have had imported assets, environments, locales, extensions, webhooks, global-fields, content-types, and workflows.

Import Content Using Management Token and Config file

This command lets you import content to your stack by using a management token and a configuration file that contains the parameters/options and their associated value.

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.

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

Usage

 csdx cm:import -a <management_token_alias> -c <config_file_path> 

Options

  • -a, --management-token-alias=management-token-alias: The management token of the destination stack to which you will import the content
  • -c, -config: The path of the JSON file containing all the options for a single run. You can refer to an example config file here

Example

  • To import content using a config file:
    csdx cm:import -a mytoken -c “C:/Users/Name/Desktop/cli/config.json”

Import Content Using Auth Token and Parameters

You can use this method to import 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.

Usage

csdx cm:import -A

Alternatively, refer to the below command for adding several parameters/options in a single line:

csdx cm:import -A -s <stack_ApiKey> -d <path_of_folder_where_content_is_stored>

Options

  • -A, --auth-token: To use the auth token of the current session. It is automatically generated and stored in the session after running the login command.
  • -s, --stack-uid-stack-uid: The API key of the target stack
  • -d, --data=data: The path or the location in your file system where the content, you intend to import, is stored. For example, -d "C:\Users\Name\Desktop\cli\content"
  • -m, --module=module: (optional) Specify the module to import into the target stack. If not specified, the import command will import all the modules into the stack. The available modules are assets, content-types, entries, environments, extensions, global-fields, labels, localeswebhooks, and workflows.

Examples

  • To import all modules into a stack:
    csdx cm:import -A -d "C:\Users\Name\Desktop\cli\content" -s bltxxxxxx 
  • To import only content types into a stack:
    csdx cm:import -A -d "C:\Users\Name\Desktop\cli\content" -m content-types -s bltxxxxxx 
    OR
    csdx cm:import -A -d "C:\Users\Name\Desktop\cli\content" --module content-types -s bltxxxxxxxx 
  • To import only environments into a stack:
    csdx cm:import -A -d "C:\Users\Name\Desktop\cli\content" -m environments -s bltxxxxxx 
    OR
    csdx cm:import -A -d "C:\Users\Name\Desktop\cli\content" --module environments -s bltxxxxxxxx 

Note: When importing modules individually, make sure you follow this module sequence: locales > environments > assets > extensions > webhooks > global-fields > content-types > workflows > entries > labels. For example, before importing entries, you must have had imported assets, environments, locales, extensions, webhooks, global-fields, content-types, and workflows.

Import Content Using Auth Token and Config file

This command lets you import content to your stack by using auth token and a configuration file that contains the parameters/options and its associated value.

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.

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

Usage

csdx cm:import -A -c <config_file_path> 

Options

  • -A, --auth-token: To use the auth token of the current session. It is automatically generated and stored in the session after running the login command.
  • -c, -config: The path of the configuration JSON file containing all the options for a single run. You can refer to an example config file here.

Example

  • To import content using a config file:
    csdx cm:import -A -c “C:/Users/Name/Desktop/cli/config.json”

Limitations

  • The import commands will import only the latest version of a published entry/asset.
  • Currently, you cannot import content for the following modules:

Additional Resources: Check out the Export Content documentation to learn how you can export content from your stack using CLI. 

Was this article helpful?

Thanks for your feedbackSmile-icon

On This Page

^