Last updated March 21st, 2019
What You'll Learn 🧠
- What a GET request is and what it does
- How to use a GET request with the API block in Voiceflow
- How to map the responses to variables
- Hence the name, the GET request retrieves data from an outside codebase.
- You can retrieve data as long as you have the supported API endpoint.
This is where we will be getting our example endpoint from.
This is the endpoint which we will be fetching data from.
The screenshot below is the data which the endpoint points to.
If you find code intimidating, rest assured, we're only copying and pasting here 😎
All you need to know is that in each row, the left side of the colon is the name of our data, and the right side is our data.
To clarify further:
"id" : 2,
- "id" is the name of the data; 2 is the data it holds.
- If "id" is called for from the API block; the value of 2 will be returned and mapped to a variable.
Let's Get Started!
In the API block, you will see the 'URL Endpoint' entry box. This is where we put our selected endpoint.
In order to access the data in the response, we will map "response.data.name" to fill in the 'first_name' variable. Don't forget to declare this variable on Voiceflow using the left-side task bar!
Now that we've mapped our variable, it should store "Janet." Let's try it out!
We've just learned how to use the most common use of the API block, fetching data from another API. Head over to one of our other tutorials to see how the other requests work!
Still have questions? Did we miss something? Have a suggestion?