Use an Existing Access Token
When you authorize an org using the org login
commands, Salesforce CLI takes care of generating and refreshing all tokens, such as the access
token. But sometimes you want to run a few CLI commands against an existing org without going
through the entire authorization process. In this case, you provide the access token and URL of
the Salesforce instance that hosts the org to which you want to connect.
Almost all CLI commands that have the --target-org |
-o flag accept an access token. The only exception is org display user.
- Open a terminal (macOS and Linux) or command prompt (Windows).
-
Run the org display command to get the instance
URL for the org to connect to. See the value for the Instance
Url key.
-
Run the org auth show-access-token command to get
the access token.
-
Use config set to set the org-instance-url configuration variable. To set it locally,
run the command from a Salesforce DX project; to set it globally, use the --global flag.
-
When you run the CLI command, use the org’s access token as the value for the --target-org flag rather than the org’s username. For
example:
Salesforce CLI doesn’t store the access token in its internal files. It uses it only for this CLI command run.