Select Page

Sometimes need to get a quick bearer token to test an API in postman or python. Rather than going through the tedious process of setting up an App or fiddling with OAuth, the salesforce cli tool can be used to get a token to use in API queries.
First step is authenticating, this pops up a web-page where you can SSO-login or password login to salesforce. On login, execute the second command to get a token.

PS C:\>  sfdx force:auth:web:login
 »   Warning: sfdx-cli update available from 7.182.1 to 7.191.1.
Successfully authorized with org ID XXXXXXXXXXXXXX

PS C:\> sfdx force:org:display --targetusername
 »   Warning: sfdx-cli update available from 7.182.1 to 7.191.1.
WARNING: This command will expose sensitive information that allows for subsequent activity using your current authenticated session.
Sharing this information is equivalent to logging someone in under the current credential, resulting in unintended access and escalation of privilege.
For additional information, please review the authorization section of the

=== Org Description

 KEY              VALUE                                                                                                 
 ──────────────── ────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 Client Id        PlatformCLI                                                                                           
 Connected Status Connected                                                                                             
 Id               XXXXXXXXXXXXXX
 Instance Url                                                               

Extract the Access Token, and you’re in business. Bear in mind the token expires in a few hours typically.