Skip to main content

Salesforce

"Salesforce is a cloud-based software company that provides customer relationship management software and applications focused on sales, customer service, marketing automation, e-commerce, analytics, and application development."

Configuration​

Reference: Salesforce OAuth 2.0 Client Credentials Flow for Server-to-Server Integration.

Pre-requisites: An existing Salesforce subscription or signup for a free trial version.

Setting up Salesforce​

Login to your salesforce account. Click on the Quick Settings icon.

Quick Settings

Click on Open Advanced Setup

Quick Settings

Click on ‘PLATFORM TOOLS > Apps > Apps Manager’.

Apps Manager

Click New Connected App.

Connected App

Click on Enable OAuth Settings.

Enable OAuth Settings

Enter a fake Callback URL, select the following form fields for Selected OAuth Scopes and check Enable Client Credentials Flow.

Selected OAuth Scopes and Credentials Flow

Scroll down and click Save.

OAuth Setup Save

Click Continue. OAuth Continue

Wait 10 minutes.

OAuth 10 Minutes

Configuration Values for crul​

Type my domain in the quick find box.

my domain

Copy the Current My Domain URL value to a safe place. You will need this later for the credentials setup.

my domain

Click on Apps > App Manager > Manage dropdown associated to your app.

App Manager

Click on Manage Consumer Details

Manage Consumer Details

You will be redirected to a Verify Your Identity screen, follow the instructions.

Verify Your Identity

Copy the Consumer Key and Consumer Secret values to a safe place. You will need this later for the credentials setup.

Consumer Key and Consumer Secret

Final Permission Settings for Salesforce​

Click on Apps > App Manager > Manage for your app.

App Manager

Click on Edit Policies.

Edit Policies

Update Client Credentials Flow > Run As with a registered users full name to grant permissions.

NOTE: Salesforce OAuth 2.0 Client Credentials Flow for Server-to-Server Integration will not work without enabling this permission to a specified user. Although there's no user interaction in the client credentials flow, Salesforce still requires you to specify an execution user. By selecting an execution user, you allow Salesforce to return access tokens on behalf of this user. The execution user must have the API Only permission.

Client Credentials Flow > Run As

Configuring Salesforce OAuth Credentials in crul​

Navigate to the credentials page in crul (top right corner menu credentials).

OAuth > Salesforce

Click the create button.

Select OAuth Provider (Client Credentials) from the type dropdown, then select Salesforce from the provider dropdown.

OAuth > Salesforce

Copy the Salesforce Current My Domain URL value into the Token Host credentials form entry. Copy the Consumer Key value into the Client Id credentials form entry. Then copy the Consumer Secret into the Client Secret credentials form entry.

Current My Domain URL, Consumer Key and Consumer Secret

Test the credential by running the following query. You should see a populated token.access_token column in the results.

oauth --credential "salesforce"

oauth --credential "salesforce"

Example queries​

NOTE: Replace all <> with respective values copied from Salesforce configuration.

Raw oauth command authentication​

oauth
--auth.tokenHost "<Current My Domain URL>"
--auth.tokenPath "/oauth2/token"
--client.id "<Consumer Key>"
--client.secret "<Consumer Secret>"
--grant "clientcred"

List of recently viewed records (REST)​

Use the Recently Viewed Items resource to get a list of recently viewed records.

oauth --credential "salesforce"
|| curl "$auth.tokenHost$/services/data/v58.0/recent/?limit=100" -H "Authorization: Bearer $token.access_token$"

or

api GET "<CURRENT DOMAIN URL>/services/data/v58.0/recent/?limit=100" --credentials.oauth "salesforce"

Salesforce via GraphQL​

The Salesforce GraphQL API is available in Enterprise, Performance, Unlimited, and Developer Editions. It adheres to the June 2018 version of the spec.

oauth --credential "salesforce"
|| graphql "$auth.tokenHost$/services/data/v57.0/graphql" "
query accounts {
uiapi {
query {
Account {
edges {
node {
Id
Name {
value
}
}
}
}
}
}
}"
--headers '{
Authorization: "Bearer $token.access_token$"
}'