HTTP Callout in Flow

Your Users need some daily inspiration on their Home Page, and the Affirmations API seems like the perfect vehicle toward providing this. Thanks to Flow Builder's HTTP Callout, we can fulfill this requirement declaratively!

Here are the high-level steps:

  1. Create External Credential
  2. Create Named Credential
  3. Create Permission Set
  4. Create Screen Flow
  5. Add the Screen Flow to the Home Page

Create External Credential

We'll add an External Credential to specify the authentication protocol in use. With this specific API, there is no authentication required.

  • Navigate to Setup > Security > Named Credentials > External Credentials and click "New"
  • Label: No Authentication
  • Name: No_Authentication
  • Authentication Protocol: No Authentication
External Credential

Add a Principal for the External Credential so that we can expose this metadata to Permission Sets.

  • Under Principals, click "New"
  • Parameter Name: All Users
  • Sequence Number: 1
Principal

Create Named Credential

Let's add a Named Credential that will encompass the Affirmations API's endpoint details.

  • Navigate to Setup > Security > Named Credentials and click "New"
  • Label: Affirmations
  • Name: Affirmations
  • URL: https://www.affirmations.dev/
  • External Credential: No Authentication
Named Credential

Create Permission Set

Create a Permission Set that grants access to the Anonymous External Service.

  • Navigate to Setup > Security > Named Credentials and click "New"
  • Label: Affirmations
  • API Name: Affirmations
  • Description: Grants access to the Affirmations API and related metadata.
  • Add the "No_Authentication - All Users" External Credential Principal
  • Assign the Permission Set to all relevant Users
Permission Set

Create Screen Flow

Now that we've done our busywork, let's put that metadata to use! We'll build a Screen Flow to leverage the API and display affirmations to Users.

  • Navigate to Setup > Flows and click "New Flow"
  • Choose Screen Flow and click "Create"

We'll add the HTTP Callout action to the Flow through the use of External Services.

  • Choose Add Element > Action and click "Create HTTP Callout"
  • Name: Affirmations
  • Description: This External Service leverages the Affirmations API.
  • Named Credential: Affirmations
  • Click "Next"
External Service

Following along, we'll build the Invocable Action that encompasses the GET callout. We can skip over the URL path variables due to the simplicity of this API.

  • Label: Get Affirmation
  • Method: GET
  • Description: Makes a GET callout to the Affirmations API and returns an affirmation.
Invocable Action

We'll also need to provide a sample API response body.

  • Click "New"
  • Input the sample JSON response (see below) and click "Review"
  • After the Data Structure compiles, click "Done"
  • Click "Save"

Sample JSON Response

Let's finish defining the action.

  • Label: Get Affirmation
  • API Name: Get_Affirmation
  • Description: Gets an affirmation from the Affirmations External Service.
HTTP Callout Action

Let's add a Screen element to the canvas. The Screen will solely be used to display an affirmation upon page load (i.e. no interaction will be taking place).

  • Choose Add Element > Screen
  • Label: Affirmation Screen
  • API Name: Affirmation_Screen
  • Description: Displays an affirmation to the current user.

Hide the header as it's unnecessary for our purpose.

  • Expand the Configure Header accordion
  • Show Header: unchecked

Hide the footer to prevent navigation.

  • Expand the Configure Footer accordion
  • Show Footer: unchecked

Add some Display Text to the Screen that displays an affirmation.

  • Drag the Display Text component onto the Screen
  • API Name: textAffirmation
  • Encapsulate the affirmation output (via Outputs from Get_Affirmation > 2XX > affirmation) in quotes from the Get Affirmation action
Screen Component

Finally, Save and Activate the Flow.

  • Click "Save"
  • Flow Label: Affirmations Screen Flow
  • Flow API Name: Affirmations_Screen_Flow
  • Description: This Screen Flow will display a random affirmation.
  • Click "Activate"
Screen Flow

Add the Screen Flow to the Home Page

Add the Flow to the Home Page so that affirmations are displayed to Users.

  • Navigate to the Home Page
  • Navigate to Setup and click "Edit Page"
  • Add the Affirmations Screen Flow to the page
  • Click "Save"

Share

References