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 displaycommand to get the instance URL for the org to connect to. See the value for theInstance Urlkey. -
Run the
org auth show-access-tokencommand to get the access token. -
Use
config setto set theorg-instance-urlconfiguration variable. To set it locally, run the command from a Salesforce DX project; to set it globally, use the--globalflag. -
When you run the CLI command, use the org’s access token as the value for the
--target-orgflag rather than the org’s username. For example:If your access token contains a
!character, you must sometimes escape it with a backslash (\). For example, if your access token is00007wpr!AQkAQA, specify it this way:--target-org 00007wpr\!AQkAQA
Salesforce CLI doesn’t store the access token in its internal files. It uses it only for this CLI command run.
See Also