CLI overview

Ask about this Page
Copy for AI
View as Markdown

The commercetools CLI is a unified command-line interface for managing your Projects and resources.

The commercetools CLI (commercetools) is an open-source command-line tool for developers, operators, and AI coding agents. It lets you work with commercetools APIs directly from the terminal. The CLI groups its commands into topics, and each topic covers a different API surface.

Topics and commands

Topic or commandDescription
authAuthenticates and shows the active session
sphereManages API resources
integration-layerAuthors, runs, and publishes Commerce Integration Layer extensions (installed as a plugin)
connectManages Connect deployments and connectors
importManages Import API containers, operations, and summaries
aiInstalls the commercetools AI plugin into your coding agent
doctorChecks the installation, authentication, and AI agent setup
pluginsInstalls, lists, and removes optional topics

Installation

The CLI is distributed via npm. It requires one of these Node.js versions:

  • 22.23.4 or later on the 22 line
  • 24.22.1 or later on the 24 line
  • 26.12.1 or later
Install the CLIbash
npm install -g @commercetools/cli

Verify the installation:

Check the CLI versionbash
commercetools --version

Authentication

All commands that interact with commercetools APIs require an authenticated session. This section is the single place where authentication is described, and the topic pages link here.

Create an API Client in the Merchant Center, then run the login command once. Your credentials are persisted locally.

Log in with client credentialsbash
commercetools auth login \
  --client-credentials \
  --client-id <client-id> \
  --client-secret <client-secret> \
  --project-key <project-key> \
  --region <region>
The --region flag takes the Region of your Project, for example europe-west1.gcp. Use the optional --scope flag to request specific scopes for the access token.
Give the API Client the scopes that the commands need. For example, the integration-layer topic needs the manage_project scope. If a command needs a session and you are not logged in, it stops and tells you to run commercetools auth login.

To view the active session:

Show the active sessionbash
commercetools auth whoami
Add --json to print the session as JSON, for example {"authenticated": true, "projectKey": "my-project", ...}. When no session exists, the output is {"authenticated": false}.

Authenticate in CI

In CI pipelines, keep the client credentials in your secret store, such as GitHub Secrets or another secret manager. Expose them to the step as environment variables. Do not write them into scripts or commit them to your repository.

GitHub Actions exampleyaml
- name: Log in to commercetools
  env:
    CLIENT_ID: ${{ secrets.CTP_CLIENT_ID }}
    CLIENT_SECRET: ${{ secrets.CTP_CLIENT_SECRET }}
    PROJECT_KEY: ${{ secrets.CTP_PROJECT_KEY }}
  run: |
    npm install -g @commercetools/cli
    commercetools auth login --client-credentials \
      --client-id "$CLIENT_ID" --client-secret "$CLIENT_SECRET" \
      --project-key "$PROJECT_KEY" --region europe-west1.gcp

Common flags

Every command accepts --help, which displays the usage, flags, and examples of the command.

Commands that are meant to be scripted or run by AI agents also support these flags:

FlagDescriptionAvailable on
--jsonPrint machine-readable JSONauth whoami, doctor, ai install, plugins
--dry-runShow what would happen without changing anythingai install, connect deployment delete
--yesSkip the confirmation promptconnect deployment delete

Output format

The sphere and import topics output pretty-printed JSON, which makes them easy to compose with tools like jq:
Pipe output to jqbash
commercetools sphere products list --limit 5 | jq '.results[].key'
The connect topic prints human-readable output such as tables and logs.

Plugins

Some topics are not bundled with the CLI. You can add them at runtime as plugins. For example, to install the integration-layer topic:
Install the integration-layer topicbash
commercetools plugins install @commercetools/cli-topic-integration-layer
After the installation, the commands of the topic are available like any other command. See the integration-layer topic reference:
Show the topic helpbash
commercetools integration-layer --help

To list the installed plugins or remove one:

List and remove pluginsbash
commercetools plugins
commercetools plugins uninstall @commercetools/cli-topic-integration-layer

Next steps