Using the HTTP Request to connect with APIs
Send and receive data from external APIs using HTTP requests in your chatbot agent. Learn how to configure HTTP requests, handle responses, and display dynamic content in your agent dialogs.
What is an HTTP Request?
An HTTP Request allows your chatbot to communicate with external services or APIs to fetch or send data. It is a standardized way to interact with web-based services by specifying:
- A URL (endpoint) to request data from.
- A method (e.g., GET or POST) to determine the nature of the request.
- Additional parameters, headers, or a body if required by the API.
In this example, we will use an HTTP GET
request to retrieve movie details from the OMDB API based on a movie title provided by the user.
Steps to Implement
1. Collect User Input
Create a dialog to collect the movie name from the user.
Example Setup:
- Prompt Text: “Search for a movie”
- Variable Name:
Movie
2. Configure HTTP Request to Fetch Data
Use the HTTP request block to call the OMDB API and retrieve movie details.
HTTP Request Configuration:
- URL:
Replace{{Movie}}
with the variable containing the user input: - Method:
GET
Testing the Request:
- Set Variable Test Value:
- Variable:
Movie
- Test Value:
Indiana Jones
- Variable:
- Click Test the Request to ensure the API call is functioning correctly.
Example Response:
3. Save API Response to Variables
Map the relevant JSON keys from the API response to variables for use in subsequent steps.
API Response Key | Variable Name |
---|---|
data.Title | Title |
data.Year | Year |
data.Poster | Poster |
Example Configuration:
- Data:
data.Title
Set Variable:Title
- Data:
data.Year
Set Variable:Year
- Data:
data.Poster
Set Variable:Poster
4. Display the Results Dynamically
Create a dialog bubble to display the fetched movie details.
Dynamic Content Setup:
- Agent dialog:
- Agent image dialogle:
Set the image source to{{Poster}}
.
5. Optional: Call a Webhook
You can integrate services like Make.com or Zapier for further processing by sending the collected data to a webhook URL.
Webhook Configuration:
- Webhook URL: Enter the provided URL (e.g.,
https://hook.eu1.make.com/...
). - Custom Payload Example:
Testing the Webhook:
- Click Test the Request to ensure the data is sent successfully.
- Use tools like Webhook Tester for debugging.
Validation and Testing
Before deployment, ensure the following:
- The API key is valid and has sufficient quota.
- The
Movie
variable captures user input correctly. - All variables (
Title
,Year
,Poster
) are saved and mapped without errors. - Dynamic content displays the movie information properly.
Notes and Tips
Note: Always secure your API key. Avoid exposing it in client-side environments.
Tip: Use fallback messages for cases where the movie is not found or the API request fails.
Example: Full Flow
-
User Input:
User types “Shawshank Redemption”. -
API Call:
Fetch data fromhttp://www.omdbapi.com/?t=Shawshank%20Redemption&apikey=YOUR_API_KEY
. -
Response Variables:
Title
: “The Shawshank Redemption”Year
: “1994”Poster
: URL to movie poster
-
Dynamic Output:
(Displays the poster image)