In this blog we are going to explore practical example of making the HTTP GET callout using Salesforce Flow.
Salesforce introduced a new feature that empowers us to perform HTTP GET callouts using Flows from summer’23 release.
Salesforce utilizes HTTP callouts to interact with external systems and APIs through the HTTP protocol, enabling user to send requests and receive responses from external endpoints.
Configure Permissions
To enable HTTP callouts using Salesforce Flow, it is essential to configure the permission sets in our Salesforce org.
This permission set empowers the user to perform callouts seamlessly using Salesforce Flow.
To create a new permission set and add your user to it, follow these steps:
- Click on the âš™ gear icon and and navigate to permission sets.
- Create a new permission set.
- Click the “Manage Assignments” button and assign your user to the newly created permission set.
Now we need to create a named credential and external credential.
A Named credential serves as a secure storage for authentication information related to an external service or endpoint.
It allows for easy access and retrieval of essential authentication details, including username, password, or OAuth token.
In this blog post we are going to make a callout to the Joke API which will give us some random jokes in the output.
As you are aware, the external credential is a compulsory field during the creation of a Named Credential.
First, we will create the external credential and then proceed with the creation of the Named credential.
External Credentials
To ensure data security between Salesforce and external systems, a reliable authentication protocol is implemented, establishing a secure connection.
This fortified connection guarantees confidential data exchange, safeguarded against unauthorized access.
When configuring external credentials, there are three authentication protocol options available:
-
- OAuth 2.0
- AWS Signature Version 4
- Custom
If the API doesn’t require a client and secret key, the Custom authentication protocol can be used.
For APIs that require a client and secret key, either OAuth 2.0 or AWS Signature Version 4 should be selected as the authentication protocol.
AWS Signature Version 4 is used to authenticate callouts to Amazon Web Services resources over HTTP, with the identity type as Named Principal.
Check out more Summer’23 release Salesforce Flow features and enhancements here
OAuth uses an authentication provider to issue a token to Salesforce after user login via a browser, granting access for callouts to the endpoint.
For this example, since we are communicating with a publicly available API, a custom authentication protocol will be used.
Once the external credential is created, we will create the principal record.
By passing this principal record to our pre-existing permission set, we can authorize it to recognize the named credential.
Named Credential
Now we will create the Named credential.
In the URL field, we will add the URL to the Joke API of appspot.com
Create the Flow
We have completed the prerequisites for making the HTTP GET callout using Flow. Let’s proceed by going to the Flow Builder and crafting a Screen Flow.
Firstly, we will add a screen element to the Flow and prompt the user to choose whether they want a single joke or multiple jokes to be generated.
Now, let’s add a decision element to the flow to check whether the user wants to generate a single joke or multiple jokes.
Based on the number of jokes the user wants to generate, we will take the appropriate action.
Want to Learn Salesforce Flows? Checkout our Salesforce Flow Course
Configuring HTTP Callout
Navigate to the Action element and click Create HTTP Callout button.
Provide the external service name and select the named credential.
Click next and now you should provide the invocable action and select the GET method. Pass “/random_joke” in the URL path field.
In the Provide Sample Response section click on New and pass the response you get by hitting the API.
Paste the response in the Sample JSON Response section.
It’s essential to note that since this API generates random jokes, the callout will produce different output for each user.
Click on Done and save the new action by providing its label name.
Now we will add a screen element to display the joke to the user generated by the API callout.
You can observe that the API callout generates a single joke. Now, let’s set up the HTTP callout action to generate multiple jokes through a GET request.
Generating Multiple jokes using HTTP GET callout
Please give the name of the external service and choose the “Joke named credential”.
Click next and provide the invocable action and select the GET method. Pass “/random_ten” in the URL path field.
Click on New in the “Provide Sample Response” section, Afterward, paste the API callout response into the “Sample JSON Response” section.
To display these multiple jokes, we’ll utilize a Loop element since they constitute a collection of jokes.
Introduce a screen element that showcases the multiple user-generated joke from the API callout
Debug the Flow. If you choose ‘Multiple’ from the picklist, the API callout will generate multiple jokes.
Business use cases for initiating HTTP callouts using Salesforce Flow
- The retail company wants to showcase its real-time product inventory to customers to make their shopping experience seamless.
- The marketing team needs to analyze social media trends and how people feel about their brand.
- An event management firm wants to get weather updates for upcoming events and update event records accordingly.