Fetch data from an external API and work with it

Send HTTP requests and store data in the Context object

Many use cases require fetching data from an external API. An HTTP request is an easy way to exchange data with 3rd party systems. The Context object is designed to hold such and other data during the user session of conversational interaction.

#1 Create a new Flow

Create a new Flow and name it "Developer Flow".

#2 Create a Question Node

Add a Question Node, select Type Text. Use the text “What is your favorite Star Wars character?”

Progress

 

#3 Send an HTTP Request

For this tutorial, we’ll use the popular Star Wars API to fetch some demo data. Add an HTTP Request Node after the Question Node. Select Type GET. The URL should be this:

https://swapi.dev/api/people/?search={{input.text}}

The object {{input.result}} represents the user input and is used as a search query. The API will return a list of all Star Wars characters in the database that match the user input. Open the “Storage Options” menu and navigate to Context Key. This is the attribute that can later be used to work with the data. In this example, use this key:

result_character

Progress

#4 See the results in the Context object

Use the Interaction Panel and process through the VA’s dialog. Type in “Luke” as an example. Now navigate to Info and Context. You’ll see a "result_character" JSON object that holds the info retrieved from the API.

Progress

 

#DONE! Now let's process data and build custom logic to enhance your Virtual Agent!


Comments

2 comments

  • #3 The object {{input.result}} represents the user input

    isn't it: {{input.text}} ?

    #3 Open the “Advanced” menu and navigate to Context Key.

    seems like it is now called "Storage Options" "Context"

    2
  • Thanks for commenting, Tycho. We'll fix the points you mentioned in the next content update.

    0

Please sign in to leave a comment.

Was this article helpful?
1 out of 1 found this helpful