Creating a connected app in Salesforce and setting up the OAuth 2.0 client credentials flow for API testing involves several steps within the Salesforce platform and your application or script that will be accessing the Salesforce API.
Here’s a step-by-step guide to get you started:
Step 1:
Create a Connected App in Salesforce
Log in to Salesforce:
Go to your Salesforce instance and log in with an administrator account.
Step 2:
Navigate to Setup:
Click on the gear icon in the upper right corner and select “Setup”.
Step 3:
In the Quick Find box, search for App Manager.
Step 4:
Click on new Connected app on the right side
Step 5:
Fill in the necessary information:
Connected App name: Enter a name for your app
API name: will be filled automatically based on the app name.
Contact email
In the API (Enable OAuth Settings) section:
Check the Enable OAuth Settings checkbox.
Callback URL: For client credentials flow, this is not used, but Salesforce requires a value. You can enter a placeholder URL like https://localhost.
Under Selected OAuth Scopes, add the relevant scopes your application will need. Because this an environment for demo and dev purposes, you can set it too full access, which is not normally used in production scenarios for API testing
Check Use digital signatures if you are using a certificate., for this demo that is not used
Also enable device flow and some other settings as displayed in the below screenshot
Step 7:
Goto manage connected apps for this new created connected app
Now use this curl command to login
You also need to provide a policy and because we are using the client credentials flow search for your user
Now you are ready to do an api test with Salesforce
curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "grant_type=client_credentials&client_id=3erVG34clientid&client_secret=cliensecret" "https://bsure-digitalbv-dev-ed.develop.my.salesforce.com/services/oauth2/token"
Once you get a bearer token (“access_token”) you can use this for any of the salesforce apis as long as they are alive.
{"access_token":"tokenbear","signature":"Udfdwerewrw=","instance_url":"https://bsure-digitalbv-dev-ed.develop.my.salesforce.com","id":"https://login.salesforce.com/id/00D7R000005GtSnUAK/0057R00000As7ZPQAZ","token_type":"Bearer","issued_at":"1711272981326"}%
For Katalon Studio I added a custom implementation which I will explain in my course in more detail in the near future https://learnautomatedtesting.com/course/katalon-and-salesforce/