To start using CLI commands, you must first authenticate yourself after installing the CLI and configuring the region. The Contentstack CLI Authentication feature allows you to securely log in or use tokens—such as Management or Delivery tokens—to perform content management tasks via the terminal.
It supports login credentials, Two-Factor Authentication, and Single Sign-On (SSO). You can authenticate either by using the login command or by adding a Management Token to the local config.
The auth:login command lets you log in to Contentstack and save the login information in your local storage.
Note: The Contentstack CLI supports Two-factor Authentication for enhanced security.
Open the terminal and run the following command to log in with your Contentstack account credentials. Once you log in, you can use the Contentstack CLI commands such as export, import, clone, bulk publish and unpublish, seed, bootstrap, migration, etc.
Usage
csdx auth:loginOR
csdx login
Options
Note: To enable automatic OTP generation for MFA-enabled Contentstack accounts, set the CONTENTSTACK_MFA_SECRET environment variable using the MFA secret key provided by Contentstack. This allows the Contentstack CLI to generate one-time passwords (OTPs) automatically, eliminating the need to enter them manually from an authenticator app.
Examples
csdx auth:login -u youremail@contentstack.comcsdx auth:login -u youremail@contentstack.com -p *****csdx auth:login --username youremail@contentstack.com --password *****csdx login -u youremail@contentstack.comcsdx auth:login --oauthThe auth:logout command lets you log out and clear the authentication from the local storage.
Usage
csdx auth:logoutOR
csdx logout
Options
Examples
csdx auth:logout -ycsdx logout -y
The csdx auth:whoami command returns the username (email address) of the user who is currently logged in.
Usage
csdx auth:whoamiOR
csdx whoami
Note: Ensure you have already generated a Management Token in your stack before running this command.
The following command lets you add an existing Management Token from your Contentstack account to the local config for further use.
Usage
csdx auth:tokens:add --managementOptions
Examples
csdx auth:tokens:add --management -a tokenname -k blt******** --token cs*********csdx auth:tokens:add --management -a tokenname -k blt******** --token cs********* -yNote: This command does not generate a new token in your stack. It only allows you to use an existing Management Token with the CLI.
Note: Ensure you have already generated a Delivery Token in your stack before running this command.
For CLI commands, you may use a Delivery Token instead of a Management Token. However, Delivery Tokens cannot be used for importing or exporting content.
Usage
csdx auth:tokens:add --deliveryOptions
Examples
csdx auth:tokens:add --delivery -a tokenname -k blt******** --token cs*********csdx auth:tokens:add --delivery -a tokenname -k blt******** --token cs********* -yNote: This command will not delete the Management/Delivery token from the stack; it deletes the token from the local config.
Usage
csdx auth:tokens:removeOptions
Examples
csdx auth:tokens:remove -a mytokencsdx auth:tokens:remove --alias=mytokenThe auth:tokens command lists all tokens stored in the local config.
Usage
csdx auth:tokensOptions