Authenticate with the CLI

After installing CLI in your system and before using the commands, you need to authenticate yourself either by using the Login command or by adding the Management token within the CLI session.

Note: Even though we support using delivery token for bulk publishing and unpublishing entries/assets, we recommend using management token in CLI session for efficient usability.

In the following table, we have listed the necessity of auth:login and auth:tokens:add -m commands:

Command

Mandatory for Import & Export commands?

Mandatory for Bulk Publish commands?

auth:login

Yes, if you want to use authtoken in cm:import or cm:export commands

No

auth:tokens:add -m

Yes, if you don’t want to use authtoken in cm:import or cm:export commands

Yes

Prerequisites

Commands

Login

The auth:login command lets you log in to Contentstack and save the session. 

Open the terminal and run the following command to log in to your Contentstack account. After successful login, the authtoken will be generated automatically which you can use in import and export operations.

Note: If you want to use a specific endpoint, other than NA, refer to the Set Region command.

Usage

csdx auth:login

OR

csdx login

Options

  • -u, --username: Email address of your Contentstack account

Examples

  • csdx auth:login -u youremail@domain.com
  • csdx login -u youremail@domain.com

Logout

The auth:logout command lets you log out of Contentstack and clear the session.

Usage

csdx auth:logout

OR

csdx logout

Options

f, --force: Exclude confirmation to logout

Examples

  • csdx auth:logout -f
  • csdx logout -f

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 session for further use.

Usage

csdx auth:tokens:add -m 

OR

csdx auth:tokens:add --management

Options

  • -a, --alias=alias : Alias (name) you want to assign to the token
  • -k, --api-key=api-key: API key of the stack where the token exists
  • -t, --token=token: Value of the token
  • -f, --force: Exclude confirmation to replace existing alias

Examples

  • To use options/parameters in a single line:
    csdx auth:tokens:add -m -a tokenname -k blt******** -t cs*********
  • To exclude confirmation when replacing the value of an existing management token:
    csdx auth:tokens:add -m -a tokenname -k blt******** -t cs********* -f

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 -d

OR

csdx auth:tokens:add --delivery

Options

  • -a, --alias=alias : Alias (name) of your delivery token
  • -e, --environment=environment: Name of the environment to which the delivery token belongs
  • -k, --api-key=api-key: API key of the stack where the token exists
  • -t, --token=token: Value of the token
  • -f, --force: Exclude confirmation to replace existing alias

Examples

  • To use options/parameters in a single line:
    csdx auth:tokens:add -d -a tokenname -k blt******** -t cs*********
  • To exclude confirmation when replacing the value of an existing delivery token:
    csdx auth:tokens:add -d -a tokenname -k blt******** -t cs********* -f

Delete Token

The auth:tokens:remove command lets you delete a management/delivery token from the session.

Note: This command will not delete the management/delivery token from the stack.

Usage

csdx auth:tokens:remove

Options

-a,--alias=alias: Alias (name) of the token to delete

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 session..

Usage

csdx auth:tokens

Options

  • -columns=columns: To display specific columns, separated by comma
  • -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 a Session

The csdx auth:whoami command returns the username (email address) of the user who is currently logged in to the session.

Usage

csdx auth:whoami

OR

csdx whoami

Additional Resources: If you want to set and use a particular region, other than North America (NA) region, for managing your content using CLI, refer to the Configuration guide.

Next Steps

Was this article helpful?

Thanks for your feedbackSmile-icon

On This Page

^