HTTP Callout pulls or sends data between the Salesforce database and an external system. In legacy implementations, this was achieved using Apex code. You can set up direct integrations as needed without having to work with a developer or call a middleware tool, using Salesforce Flow Builder.
Below are the steps to configure Flow to call APIs.
Use case:
Get the current weather details about the city by making an HTTP callout using the “GET” method on the lightning flow.
Prerequisites:
1. Create a permission set in Salesforce and assign the users to it.
2. Create an account on the following weather API site (For the demo have created a sample account with limited access) and get the API Key.
Weather API: www.weatherapi.com
3. Create an account on the following weather API site (For the demo have created a sample account with limited access) and get the API Key.
In Salesforce we need to consider a few things to make an HTTP callout (Beta):
HTTP Callout Considerations (Beta)
Step 1:
Create a permission set without any permission changes on Salesforce and assign the users to it.
Step 2:
Create a named credential along with the external credentials. Choose the authentication protocol type as “Custom”.
Map the newly created permission set to the external credential.
Step 3:
Based on the external credential to create a named credential with the URL endpoint.
The base URL is: https://api.weatherapi.com/v1
Step 4:
Create a screen flow to get the city details for getting the weather details.
We need to pass the API Key while making a callout, So, store the API Key value to custom settings and pass it.
Once the flow is launched we get this API Key value.
Step 5:
Get the city details from the user and customize the input screen with a footer button.
Step 6:
Call the “Create HTTP callout (Beta)” action and then create an External Service alone with the Named Credentials and press Next.
It will authorise the connection between Salesforce and the API.
Step 7:
Create an Invocable Action and choose the Method of “GET” then pass the parameter of Key (key), city (q) and additional parameter to get the additional details, language (language) and air quality (api) with the help of “Add Query Parameter Key section”.
We can add the URL Path as well if required or if we need an exact response.
Once added the parameter, need to provide the sample response and get it from the postman tool.
Copy the response and paste it to the “Provide Sample Response” section then preview and Done.
Step 8:
Finally, we map the responses to the output screen field to see the current weather details on the entered city.
All the responses are stored on the output element.
Based on the response we mapped to the output screen.
Debug the Flow:
Once entered the city then hit the “Get Weather Report” button. It will display the current weather details on the output screen.
Step 9:
We can update the existing HTTP Callout action in Beta services..
When you create an HTTP Callout action in a flow, Flow Builder creates an external service object and an invocable action object. Anyone with permissions in your org can reuse the invocable action in Flow Builder and across Salesforce.
In the Quick Find box, enter External Services, and select External Services.
Edit the external services which we created on the flow. Update the JSON field, which contains the auto-generated API specification that Salesforce reads to perform the operation and save the changes.