CLI Authentication and Adding Tokens
After installing the CLI in your system and before using the commands, you first need to authenticate yourself. You can do this either by using the Login command or by adding the Management token which is stored in the local config.
Note: Even though we support using the delivery tokens for bulk publishing and unpublishing of entries/assets, we recommend using the Management token for efficient usability.
Prerequisites
- Contentstack account
- CLI installed on your machine
Commands
Login
The auth:login command lets you log in to Contentstack and save the login information in your local config.
Note: The Contentstack CLI now supports Two-factor Authentication, which ensures additional security to your Contentstack account.
Open the terminal and run the following command to log in to your Contentstack account. Once you log in, you can use the Contentstack CLI commands such as Import, Export, Clone, Bulk Publish, Seed, Bootstrap, Migration, etc.
Note: Contentstack currently supports five regions: North America, Europe, Azure North America, Azure Europe, and Google North America. By default, the NA region is selected. If you want to use any other endpoint, refer to the Set Region command.
Usage
csdx auth:login
OR
csdx login
Options
- -u, --username: Email address of your Contentstack account.
- -p, --password: Password can be passed in command.
- --oauth: Enables single sign-on (SSO) in Contentstack CLI.
Examples
csdx auth:login -u youremail@contentstack.com
csdx auth:login -u youremail@contentstack.com -p *****
csdx auth:login --username youremail@contentstack.com --password *****
csdx login -u youremail@contentstack.com.com
csdx auth:login --oauth
Logout
The auth:logout command lets you log out of Contentstack and clear the authentication from the local config.
Usage
csdx auth:logout
OR
csdx logout
Options
-y, --yes: Exclude confirmation to logout
Examples
csdx auth:logout -y
csdx logout -y
Add Management Token
To perform content management tasks, we recommend using the management token.
Note: Before running this command, make sure you have generated a management token in your stack.
The following command lets you add an existing management token from your Contentstack account and save it to the local config for further use.
Usage
csdx auth:tokens:add --management
Options
- -a, --alias=alias : Alias (name) you want to assign to the token
- --management: Flag to set management token
- -k, --stack-api-key=stack-api-key: API key of the stack where the token exists
- --token=token: Value of the token
- -y, --yes: Force token replace
Examples
- To use options/parameters in a single line:
csdx auth:tokens:add --management -a tokenname -k blt******** --token cs*********
- To exclude confirmation when replacing the value of an existing management token:
csdx auth:tokens:add --management -a tokenname -k blt******** --token cs********* -y
Note: This command will not add a new management token in your stack. It just lets you perform content management tasks through CLI by using the existing management token.
Add Delivery Token
For Bulk Publish commands, if you don’t want to use the management token, you can use the delivery token instead. However, you will not be able to execute import and export content commands by using the delivery token.
Note: Before running this command, make sure you have generated a delivery token in your stack.
Usage
csdx auth:tokens:add --delivery
Options
- -a, --alias=alias : Alias (name) of your delivery token
- --delivery: Flag to set delivery token
- -e, --environment=environment: Name of the environment to which the delivery token belongs
- -k, --stack-api-key=stack-api-key: API key of the stack where the token exists
- --token=token: Value of the token
- -y, --yes: Force token replace
Examples
- To use options/parameters in a single line:
csdx auth:tokens:add --delivery -a tokenname -k blt******** --token cs*********
- To exclude confirmation when replacing the value of an existing delivery token:
csdx auth:tokens:add --delivery -a tokenname -k blt******** --token cs********* -y
Delete Token
The auth:tokens:remove command lets you delete a management/delivery token from your local config.
Note: This command will not delete the management/ delivery token from the stack, it deletes the token from the local config.
Usage
csdx auth:tokens:remove
Options
- -a,--alias=alias: Alias (name) of the token to delete.
- -i,--ignore: Ignores if the token is not present.
Examples
csdx auth:tokens:remove -a mytoken
csdx auth:tokens:remove --alias=mytoken
List All Tokens
The auth:tokens command lists the existing tokens added to the local config.
Usage
csdx auth:tokens
Options
- -x,--extended: To show extra columns
- --columns=columns: To display specific columns, separated by comma
- --csv: Output is csv format.
- --filter=filter: To filter the property by partial string matching, ex: name=foo
- --no-header: To hide table’s header in output
- --no-truncate: To not truncate output to fit screen
- --output=csv|json|yaml: To display output in a particular format
- --sort=sort: To sort the list, prepend '-' to sort in a descending order
Display Username of the Logged in User
The csdx auth:whoami command returns the username (email address) of the user who is currently logged in.
Usage
csdx auth:whoami
OR
csdx whoami
Additional Resources: Contentstack supports five regions: North America, Europe, Azure North America, Azure Europe, and Google North America. Refer to the configuration guide if you want to use a particular region, other than North America (NA).
Next Steps
- Export and import content
- Publish entries/assets in bulk