Action Block: Service Call
REST APIs are used to Push / Pull data to / from third party systems. Using the Service Call action block, you can directly integrate a third party system’s REST API in a flow.
You can integrate GET, POST or PUT type REST API through Service Call action block from the bot builder page.
Here are the steps that you can follow to configure the same;
Step 1: Add the ‘Service Call’ action block
To add the ‘Service Call’ action block on canvas, click on ‘+’ sign and look for ‘Service Call’
Step 2: Configure your API on the right panel
To configure your API on the Service Call action block, below are the fields that you would be filling values in. If you are a developer, you would feel at home here, for other, you may need to refer to the APIs documentation to find what to fill on the right panel.
Type of Method:
You will first need to select the ‘Type of Method’ from the drop down list from the available options. i-genie currently supports three types of methods, they are;
- * GET
- * POST
- * PUT
Endpoint URL:
You will need to provide the absolute URL i.e URL starting with HTTP or HTTPS. You can also use the variables too in the URL by typing ‘#’ as some of the APIs do not have headers and everything is mentioned in the URL itself.
For Instance:
https://api.weatherapi.com/v1/current.json?key=e943b863ebed4572b55140350200312&q=#city# Here in the above URL #city# is the variable that has been used
Headers:
‘Request Headers’ allows you to authenticate the API based on its tokens. You can also use variables as tokens too by typing ‘#’.
You need to ensure that you add following token in the header: Key: Content-type Value/Variable: application/JSON
Body:
Under ‘Request Body’ you can define what information needs to be sent or retrieved by calling the API. There are two ways through which the information can be sent or retrieved, they are;
Raw: It is normal JSON format in which the request needs to be passed
{ “User_name”: “John”, “City”: “New York” }
Form: It allows to map the fields. You can either provide static value or map with the variables
The values can be mapped in following way Key1: User_name Value/Variable1: John / #name# Key 2: City Value/Variable: New York / #city#
Response:
You can further store the responses received from the API into the variables which can be further used in the bot flow or bot message. i-genie follows the dot pattern to store the responses into the variables. Below are few of the ways in which the path can be defined
Object path for storing the response into variable where single value is returned result.data.'variable name' Here the 'variable name' is name of the variable where the response will be stored Object path for storing the response into variable where list is returned result.data.list[0].'variable name' Here the 'variable name' is name of the variable where the response will be stored
Test the API:
With the recent upgrades, you now have the ability not only to test the API within the block itself but also to define the variables and store responses in them.
How does it work?
In-order to test the API, you can follow the following steps;
Step 1: Click on ‘Test the API’
Step 2: Provide the input in the variable (optional)
Step 3: Click on ‘Test the API’ again to check the results
How do I store the responses?
To store the API responses directly into the variables, you can follow the following steps;