Contentful CLI
raw JSON →The Contentful CLI (Command Line Interface) tool allows developers to interact with Contentful features directly from their terminal. It supports managing spaces (listing, creating, deleting), exporting and importing content, executing and generating migration scripts using the Contentful Migration DSL, seeding spaces with example data, and managing extensions. The current stable version is `4.0.0`. The project maintains an active release cadence, with minor and patch versions frequently released, often monthly or bi-monthly, addressing bugs and adding new features like organization security checks. Its key differentiators include deep integration with Contentful's content management and delivery APIs, robust migration capabilities, and recently, features for assessing organization security posture. It is a critical tool for automating content workflows and managing Contentful projects programmatically.
Common errors
error Error: Node.js version 18.x.x is not supported. Please upgrade to Node.js 22 or higher. ↓
nvm (Node Version Manager) for easy switching: nvm install 22 && nvm use 22. error command not found: contentful ↓
npm install -g contentful-cli or yarn global add contentful-cli). Restart your terminal or shell. Check if your global npm packages directory is in your system's PATH. error Unable to connect to Contentful through your Proxy? ↓
rawProxy: true in your .contentfulrc.json file via the command: contentful config add --raw-proxy. This might help with certain proxy configurations. error Error: Access to space '<SPACE_ID>' failed. Check if you have access to it and if your token has the right permissions. ↓
contentful login. If using a management token, ensure it is still valid and has the necessary CMA permissions (e.g., space.manage). If it's an API key, ensure it's a Management API key, not a Delivery API key. Warnings
breaking Version 4.0.0 introduces a breaking change by requiring Node.js version 22 or higher. Older Node.js versions are no longer supported. This release also updates internal dependencies to `contentful-management` v12, `contentful-batch-libs` v11, and `contentful-export` v8, which may introduce further breaking changes within those libraries' APIs. ↓
gotcha When using the CLI with a proxy, there's a specific order of precedence for configuration. Environment variables (`https_proxy`, `http_proxy`) override settings in `.contentfulrc.json`, and `https_proxy` takes precedence over `http_proxy`. Incorrect precedence or misconfiguration can lead to connectivity issues. ↓
gotcha For users operating in the Contentful EU region, the CLI by default connects to the global Contentful API endpoints. Failing to configure EU-specific hosts will result in attempting to authenticate and manage resources in the wrong region. ↓
gotcha After global installation with `npm install -g contentful-cli` or `yarn global add contentful-cli`, the `contentful` command might not be immediately available in your shell's PATH, especially on some operating systems or if your shell's cache is not updated. ↓
Install
npm install contentful-cli yarn add contentful-cli pnpm add contentful-cli Imports
- contentful wrong
import { contentful } from 'contentful-cli'correctnpm install -g contentful-cli - Login/Auth wrong
contentful auth --token <YOUR_TOKEN>correctcontentful login - Configuration wrong
contentful config set host=api.eu.contentful.comcorrectcontentful config add --host api.eu.contentful.com
Quickstart
# Install the Contentful CLI globally
npm install -g contentful-cli
# Log in to your Contentful account (this will open a browser for OAuth)
contentful login
# List all available spaces for your account
contentful space list
# Export a space to a JSON file
# Replace <SPACE_ID> with your actual Space ID and <FILE_NAME> with your desired output file name
# You can find your Space ID in the Contentful web app URL or via 'contentful space list'
# Example: contentful space export --space-id 'your_space_id' --output 'exported-space.json'
contentful space export --space-id <YOUR_SPACE_ID> --output exported-space.json
# Get help for a specific command
contentful migration --help