Blog

HTTP Callout Using Lightning Flow

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

HTTP Callout Using Lightning Flow

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.

HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow

Step 2:

Create a named credential along with the external credentials. Choose the authentication protocol type as “Custom”.

HTTP Callout Using Lightning Flow

Map the newly created permission set to the external credential.

HTTP Callout Using Lightning Flow

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

HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow

Step 4:

Create a screen flow to get the city details for getting the weather details.

HTTP Callout Using Lightning Flow

We need to pass the API Key while making a callout, So, store the API Key value to custom settings and pass it.

HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow

Once the flow is launched we get this API Key value.

HTTP Callout Using Lightning Flow

Step 5:

Get the city details from the user and customize the input screen with a footer button.

HTTP Callout Using Lightning Flow

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.

HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow

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.

HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow

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.

HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow

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.

HTTP Callout Using Lightning Flow

Based on the response we mapped to the output screen.

Debug the Flow:

HTTP Callout Using Lightning Flow

Once entered the city then hit the “Get Weather Report” button. It will display the current weather details on the output screen.

HTTP Callout Using Lightning Flow

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.

HTTP Callout Using Lightning Flow

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.

HTTP Callout Using Lightning Flow
HTTP Callout Using Lightning Flow