---
schema_version: "1"
id: b61240829fa352b5124332c8843f65277282ac034f70e62cf4d51d5b327b32a8
title: Authentication to the Anypoint Platform CLI
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/anypoint-cli/latest/auth.md
canonical_url: https://docs.mulesoft.com/anypoint-cli/latest/auth
source_site: docs.mulesoft.com
content_type: documentation
content_hash: f64821b837d6abcd3a33d23c0d292e109c7d6d83e84e31421a9c69a50a6b60b9
description: MuleSoft Documentation Site
release: 4.x
latest: true
---
---
product: Anypoint CLI
version: 4.x
is-latest-version: true
---

# Authentication to the Anypoint Platform CLI

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

To authenticate to Anypoint CLI, you must use one of the authentication option combinations:

- Username and password

- Client ID and client secret

- Bearer token (command line only)

> [!NOTE] As a part of Multi-factor authentication (MFA) enablement for all users, starting October
> 2022, the only way to use Anypoint CLI will be through
> [Connected Apps](https://docs.mulesoft.com/access-management/connected-apps-overview).

The default host, environment, and organization are used if you do not specify them.

Pass Anypoint CLI credentials by using the following methods:

- [Using a credentials configuration file](#credentials-file)

- [Using command-line parameters and Environment Variables](#command-line-parameters)

Configuration settings are overridden as follows:

- Command-line parameters override all other methods.

- Environment variables are used if command-line parameters are not specified and override any
  credentials configuration file settings.

- Credentials configuration file parameters are used if no command-line parameters or environment
  variables are set.

## Set Credentials Using the Conf command

You can authenticate to Anypoint Platform by running the `anypoint-cli-v4` command with the `conf`
option to add your credentials to a configuration file and then running the `anypoint-cli-v4`
commands you want to use. You can set authentication values in the configuration file using a
combination of the following parameters:

username password client\_id client\_secret host session.selectedEnvironment.id
session.selectedOrganization.id

To create your configuration file:

- Run the `anypoint-cli-v4 conf` command with the parameters you want to use to set the
  authentication method. For example, the following command sets the username and password.

  $ anypoint-cli-v4 conf username <username>
    $ anypoint-cli-v4 conf password <password>

The commands store the credential information in the `config.json` file in the following locations:

- MacOS: `~/Library/Preferences/anypoint-cli-v4-nodejs/config.json`

- Windows: `%APPDATA%\anypoint-cli-v4-nodejs\Config`

- Unix: `~/.config/anypoint-cli-v4-nodejs/`

**Examples:**

- Set configuration file authentication using username and password

  - Add authentication values to the configuration file using the following commands:

    $ anypoint-cli-v4 conf username myUserName
        $ anypoint-cli-v4 conf password myPassword $
    anypoint-cli-v4 conf organization myOrgId

  - Run a command and the authentication will be done using the configuration file values.

    $ anypoint-cli-v4 account:environment:list

- Set configuration file authentication using client ID and client secret

  - Add authentication values to the configuration file using the following commands:

    $ anypoint-cli-v4 conf client\_id myClientID
        $ anypoint-cli-v4 conf client\_secret
    myCLientSecret $ anypoint-cli-v4 conf organization myOrgId

  - Run a command and the authentication will be done using the configuration file values.

    $ anypoint-cli-v4 account:environment:list

    The `organization` flag is optional. It defaults to your main organization from Anypoint
    Platform.

> [!NOTE] You can get your `client_id` and `client_secret` via Connected Apps. For more information
> see [Connected Apps for Developers](https://docs.mulesoft.com/access-management/connected-apps-developers).
>
> Connected Apps require the `View Organization` and `View Environment` scopes to authenticate to
> Anypoint Platform.

## Command-Line Parameters and Environment Variables

You can authenticate to Anypoint Platform through the command line by running the `anypoint-cli-v4`
command with a combination of parameters, or by setting a combination of the following environment
variables before running the `anypoint-cli-v4` command:

<table><colgroup><col> <col></colgroup><thead><tr><th>Command-Line Parameters</th><th>Environment Variables</th></tr></thead><tbody><tr><td><div><div><p><code>--username</code></p></div></div></td><td><div><div><p><code>ANYPOINT_USERNAME</code></p></div></div></td></tr><tr><td><div><div><p><code>--password</code></p></div></div></td><td><div><div><p><code>ANYPOINT_PASSWORD</code></p></div></div></td></tr><tr><td><div><div><p><code>--client_id</code></p></div></div></td><td><div><div><p><code>ANYPOINT_CLIENT_ID</code></p></div></div></td></tr><tr><td><div><div><p><code>--client_secret</code></p></div></div></td><td><div><div><p><code>ANYPOINT_CLIENT_SECRET</code></p></div></div></td></tr><tr><td><div><div><p><code>--bearer</code></p></div></div></td><td><div><div><p><code>ANYPOINT_BEARER</code></p></div></div></td></tr><tr><td><div><div><p><code>--organization</code></p></div></div></td><td><div><div><p><code>ANYPOINT_ORG</code></p></div></div></td></tr><tr><td><div><div><p><code>--environment</code></p></div></div></td><td><div><div><p><code>ANYPOINT_ENV</code></p></div></div></td></tr><tr><td><div><div><p>-</p></div></div></td><td><div><div><p><code>ANYPOINT_CERTIFICATE</code></p></div></div></td></tr><tr><td><div><div><p>-</p></div></div></td><td><div><div><p><code>ANYPOINT_HOST</code></p></div></div></td></tr><tr><td><div><div><p><code>--[no-]collectMetrics</code></p></div></div></td><td><div><div><p><code>COLLECT_METRICS</code></p></div></div></td></tr></tbody></table>

> [!NOTE] The `--organization` flag is optional. It defaults to your main organization from Anypoint
> Platform.

**Examples:**

- Authenticate on the command line using username and password

  $ anypoint-cli-v4 account:environment:list --username myUserName --password myPassword
  --organization myOrgId

- Authenticate on the command line using client ID and client secret

  $ anypoint-cli-v4 account:environment:list --client\_id myClientID --client\_secret myClientSecret
  --organization myOrgId

- Authenticate on the command line using a bearer token

  You can generate a bearer token in Anypoint Platform and pass it to Anypoint CLI directly. When
  you provide a bearer token, Anypoint CLI ignores any provided user or client credentials.

  $ anypoint-cli-v4 account:environment:list --bearer myBearerToken --organization myOrgId

  Your Anypoint Platform session expires when the bearer token expires.

  For information about generating a bearer token, see
  [How to Generate Your Authorization Bearer Token for Anypoint Platform](https://help.salesforce.com/s/articleView?id=001115323&type=1).

- Authenticate by setting the environment variables for username and password

  $ export ANYPOINT\_USERNAME=myUserName
    $ export ANYPOINT\_PASSWORD=myPassword
  $ export ANYPOINT\_ORG=myOrgId
    $ anypoint-cli-v4 account:environment:list

- Authenticate by setting the environment variables for client ID and client secret

  $ export ANYPOINT\_CLIENT\_ID=myClientID
    $ export ANYPOINT\_CLIENT\_SECRET=myCLientSecret
  $ export ANYPOINT\_ORG=myOrgId
    $ anypoint-cli-v4 account:environment:list
