This article explains how you can automate the testing of Salesforce API from ACCELQ.
Before you can make Salesforce API calls, you will need to set up a Connected App from your Salesforce instance. Here are the instructions.
Create API statement to execute Login to Salesforce
While automating Salesforce API, you need to provide a Bearer Token in the API call as part of authorization headers. This token is generated when you run an API call to login into Salesforce.
POST Login to Salesforce with OAuth Authorization. |
|
End Point URL
|
<Salesforce Instance URL>/services/oauth2/token
|
Request Headers
|
Content-Type : application/x-www-form-urlencoded
|
Query Params
|
grant_type : password |
Sample Response
|
{
"access_token":"00D5g000004FukL!AQUAQOUmfFr_kfJapSdPOIG3VfSuHkkEmd7_pZSV_Shm8fdwdJwMz9n00AOSWcpttdOm3hWJ5cdr7.w24gN7DORwr8wtXTRw",
"instance_url": "https://accelq-dev-ed.my.salesforce.com",
"id": "https://login.salesforce.com/id/00D5g000004FukLEAS/0055g000004LrQxAAK",
"token_type": "Bearer",
"issued_at": "1625398015156",
"signature": "izP5ZUwLON+Pz6Dv00Apx+wNdMW0vaQLvnG0oN9ipmQ="
}
|
Here is how you make this API call in ACCELQ and derive the bearer token.
- Open an Action in ACCELQ, and click the API button dropdown and choose "REST" API.
- Fill in all the API information as shown below and click theNEXTbutton.
- In the REST Request Payload modal choose the content-type as "application/x-www-form-urlencoded" and fill in all the information as shown below. "client id" and "client secret" values are read from the Salesforce Connected App (as explained in the pre-requisite).
- Click the SEND REQUEST button to trigger the request and navigate to the REST Response Information modal.
- Response information should look somewhat like this.
The response will contain a node called access_token. The access_token node value contains the Bearer token which can be used in all subsequent Salesforce API calls for API Authentication - Click on the node access_token to generate the JSON node path that can be later used to extract the access_token node value.
Extract the Access Token from the OAuth Login API response
Use the command "Get Node From ReST Response" in the Action Login to extract access token from the path $['access_token']
Here is an example that includes the Login API call and the extraction of the access token.
Convert Access Token to Bearer Token
Use the Expression Builder to create the Bearer Token in the below format as shown below.
Bearer <access_token generated from the OAuth Login API>
Add Authorization Header to all subsequent Salesforce API calls
Add the generated Access Token in the header of all the Salesforce API calls in the below format:
Header Name |
Value |
Authorization |
<bearer token generated from the first step>
|
Here is an example:
Comments
0 comments
Please sign in to leave a comment.