Import Content into Contentstack

Once you have exported content using one of the exporting utility tools, the next step is to import this data into Contentstack. If you have used any other exporting tool (other than Contentstack’s import utility), refer to this guide to understand how to restructure your data in the format that Contentstack’s import utility will understand. Once you restructure the data (or if you have used Contentstack’s export tool), refer to the steps given below to import content into Contentstack.

Download the utility

To import your content to Contentstack, you need to first download the 'contentstack-import' utility tool from GitHub. This utility tool consists of modules that will help you import your content saved in JSON format in your file system.

In order to import data into Contentstack, it is imperative to have converted your content into JSON format. This makes it easier to import data into Contentstack.

Install Node modules

Node.js modules play an essential part in the effective working of the import utility tool. Using Node.js package manager (npm), the essential modules of the utility tool will be extracted into your file system.

Navigate to the root folder of the utility tool and run the command given below to install the node modules that are necessary for executing the utility tool:

npm install

Add configuration details

Before importing the content, certain changes need to be made in the configuration file of the utility tool. So, open the 'index.json' file within the 'config' folder of the utility tool and add the following configuration details:

{
master_locale: {
name: '', // Stack's master locale. ex: 'English - United States'
code: '' // Stack master locale's code. ex: 'en-us'
},
email: '', // Your registered email id
password: '', // Account password
target_stack: '', // Stack api_key. This is the stack, where the data will be imported
data: '' // The data that's to be exported. This is generally the one exported via the contentstack-export utility. ex: '../contentstack-export/contents'. Kindly provide the relative path or absolute path to the directory

Here's a brief of what values you need to provide for the above configuration parameters:

  • master_locale: Enter the name and code of the master locale of your stack in the parameters given below:
    • name: The name of the master locale (e.g. English - United States)
    • code: The language code of the master locale mentioned above (e.g. en-us)
  • email: Your Contentstack account's registered email address
  • password: Your Contentstack account password
  • target_stack: The API key of the destination stack to which you need to import your data
  • data: The path of the location in your file system where the data you intend to migrate is stored

Note: You need to be careful when providing the 'master_locale' value because if it differs to the master locale of the stack, the migration procedure fails.

Import modules

After entering the configuration details, you are now ready to import content into Contentstack. Content will be imported into Contentstack only if it is saved in the JSON format.

On the basis of your requirement, you can either perform a complete import of your content or you can import specific modules.

  1. To import the entire content, run the command given below:
    npm run import
    This command will import data from the content that is exported and stored in our local system. These files are imported from the path mentioned in the 'data' key in the 'index.js' file under the 'config' folder.
  2. To import specific modules, run the command given below:
    npm run import {module-name}
    When importing modules individually, make sure you follow the module sequence as given below, for example, before importing entries, you must have had imported assets, environments, locales, and content types:
    • assets
    • environments
    • locales
    • contentTypes
    • entries

Note: This utility tool can be used to import only the latest published version of an entry.

Was this article helpful?
top-arrow