Skip to main content

Exporting and importing data using the Contensis CLI

Log in to add to favourites
This guide will show you how to easily export and import data using the Contensis CLI. We'll walk through a simple example using "Staff" records, which include fields for Name, Job title and Email. The process involves exporting data from Contensis as a CSV file, making bulk edits, and then re-importing it while ensuring data integrity and avoiding duplicates.

Before running the Contensis CLI, it's best to navigate to a directory where you can easily access and manage your files, such as your Desktop or Documents folder. Open a terminal and move to your desired directory:

Bash
cd /Desktop  # or /Documents

This ensures that exported files are easy to find and manage. Once in your chosen directory, you can run the Contensis CLI using:

Bash
contensis

Export data from Contensis

To make bulk edits, first export your existing data from Contensis using the CLI. This command retrieves entries using ZenQL and saves them in CSV format:

Bash
get entries --zenql "sys.contentTypeId = staff" --fields entryTitle, jobTitle, emailAddress, linkedIn, sys.id, sys.contentTypeId, sys.dataFormat, sys.language --output ./staff.csv --format csv

Lets upload this sheet to Google Sheets and edit our @LinkedIn field data. Once we have updated our data, we can export this as a CSV file.

  • sys.id
  • sys.contentTypeId
  • sys.language
  • sys.dataFormat

This ensures that the sys object in your imported data looks something like this:

JSON
"sys": {
  "id": "6b3c63d9-fcda-41ac-9c72-5f9af7ed466b",
  "contentTypeId": "staff",
  "language": "en-GB",
  "dataFormat": "entry"
}

Import data using the Contensis CLI

Use the CLI to import your CSV data. To view available import commands, run:

Bash
contensis import --help
Bash
contensis import entries --from-file updated-staff.csv --preserve-guids

This will render a preview of the changes for you to review:

Commit the changes

If everything looks good in the preview, commit the changes:

Bash
contensis import entries --from-file updated-staff.csv --preserve-guids --commit

Once the changes have been successfully committed, a confirmation will be displayed in the terminal:

The imported entries will then be available in your Contensis project. They will be stored in the Draft state until you are ready to publish them:

Conclusion

By following these steps, you can efficiently export and import data in Contensis CMS using the CLI. This process ensures data integrity and prevents duplication while streamlining large updates.

Troubleshooting

Need help setting up the Contensis CLI? Check out this article here.

Still need help?

If you still need help after reading this article, don't hesitate to reach out to the Contensis community on Slack or raise a support ticket to get help from our team.
New support request