Export Content to .CSV File

The cm:export-to-csv command allows users to export the following data into a CSV file:

This makes it easy for users to perform other operations such as create content backups, perform data analysis, and so on.

To export the content of a stack, you need to have access to it. Likewise, to export an organization’s user data, you need to be the “owner” or an “admin” user of that organization.

You can export content into a .csv file by performing the following two steps:

  1. Log in to the CLI session
  2. Use the “cm:export-to-csv” command

Prerequisites

  1. Log in to the CLI Session

    Note: By default, the CLI session uses the North America region. To set the Europe or Azure North Amercia region, refer to the Set Region command for more details.

    You will need an authtoken to use the export-to-csv command. To generate the authtoken, open your terminal, and run the following command to log in to your Contentstack account:

    csdx auth:login

    It will ask you to provide your email address and password of your Contentstack account. Once you log in successfully, an authtoken will be generated and saved to the CLI session until you log out from this session.

    Additional Resource: To learn more about the login command, refer to the Login command section.

    login.png
  2. Use the ‘cm:export-to-csv’ command

    Now that you are logged in to Contentstack, let’s export content from the source stack in a CSV file by running the following command in your terminal:

    csdx cm:export-to-csv

    This command will prompt the following options as follows:

    • Export entries to CSV: Export all entries of a stack to a CSV file. You should have access to the stack.
      This option will ask you to select the following:
      • Organization where your stack resides. 
      • Stack where the content type resides.
      • Content type(s) to which the entries belong.
      • Language of which you want to export the entries.

      You can also export entries to CSV using the Management Token alias.

    • Export organization users to CSV: Export the organization users’ details to a CSV file. To use this option, you should either be an Organization Owner or the Organization Admin. This option lists the organization(s) of which you are either an owner or admin.
    • Note: You must be logged in to the Contentstack app to export organization users.

    • Exit: Stop this command from further execution.

    Once you select any one of the above-mentioned options, the “data” folder is auto-generated in the current working directory (folder), and the corresponding CSV files are stored within this “data” folder.

The alternate way of using the command is by providing the required parameters after the command in a single line as shown below:

csdx cm:export-to-csv -a <alias_of_management_token> -n <name_of_the_stack> --action <<entries_or_users>>  --org <organization_UID> --org-name <name_of_the_organization> --locale <name_of_the_locale> --content-type <content_type_name>
Options:
  • -a,--alias=alias: Alias of the management token. 
  • -n,--stack-name=stack-name: Name of the stack that needs to be created as CSV filename. 
  • --action=action: Option to export data (entries, users). Select entries or users.
  • --org=org: Provide organization UID to clone org users. 
  • --org-name=org-name: Name of the organization that needs to be created as CSV filename.
  • --locale=locale: Locale of entries that will be exported.
  • --content-type=content-type: Content type of entries that will be exported

Examples:

  • Exporting entries to CSV:
    csdx cm:export-to-csv --action <entries> --locale <locale> --alias <management-token-alias> --content-type <content-type> 
  • Exporting entries to CSV with stack name provided:
    csdx cm:export-to-csv --action <entries> --locale <locale> --alias <management-token-alias> --content-type <content-type> --stack-name <stack-name> 
  • Exporting organization users to CSV
    csdx cm:export-to-csv --action <users> --org <org-uid>
  • Exporting organization users to CSV with organization name provided
    csdx cm:export-to-csv --action <users> --org <org-uid> --org-name <org-name> 

Was this article helpful?

Thanks for your feedbackSmile-icon

On This Page

^