# Contentful CLI
> Manage Contentful headless CMS from the terminal

## Summary
Official Contentful CLI for managing spaces, content types, entries, environments, and content migrations in the Contentful headless CMS platform.

## Capabilities
- Manage Contentful spaces and environments
- Run content migrations with versioned migration scripts
- Export and import space content and schema
- Manage content types and content model
- Scaffold and manage Contentful extensions and apps
- Generate boilerplate projects from Contentful templates

## When to Use
- Managing Contentful CMS content and schemas from the terminal
- Running content migrations across Contentful environments
- Exporting or importing Contentful space data for backup or migration
- Automating Contentful operations in CI/CD pipelines

## When NOT to Use
- Not using Contentful as your CMS
- Prefer the Contentful web UI for content editing
- Managing non-CMS cloud infrastructure

## Key Flags
- `login`: Authenticate with Contentful
- `space list`: List all available spaces
- `space export`: Export content and schema from a space
- `space import`: Import content and schema into a space
- `space migration`: Run a content migration script
- `space environment create`: Create a new environment in a space

## Usage Patterns
### Export a space for backup
```
contentful space export --space-id SPACE_ID --export-dir ./backup
```
Exports all content types, entries, and assets to JSON files

### Run a content migration
```
contentful space migration --space-id SPACE_ID migrations/01-add-author.js
```
Applies a migration script to modify the content model

### Create a new environment
```
contentful space environment create --name staging --space-id SPACE_ID
```
Creates a new environment for testing content changes

## Input / Output
- **stdin**: Accepts interactive input for login and confirmations
- **stdout**: Space listings, export progress, and migration results
- **stderr**: Error messages and API errors

## Installation
- **npm**: `npm i -g contentful-cli`

## Related Tools
- [sanity](/tools/sanity) (alternative): Sanity CLI manages a competing headless CMS platform
- [hugo](/tools/hugo) (complementary): Hugo can consume Contentful content for static site generation

---
Source: https://littlescripts.sh/tools/contentful-cli
