REST

REST

The REST function allows users and the bot to communicate and interact with online applications through a REST endpoint and to store the results for later use.

Inputs

Here you can define the inputs which you can then use in the path, headers and body by surrounding them with square brackets (This is an [Input]).

Method

You can choose all of the possible REST methods, GET to get information, POST to send information (with a JSON body), PUT and PATCH to edit information and DELETE to delete information.

API Path

Here you can put the full function path as provided by the endpoint host.

Headers

The header contains metadata about your request. For example the content type or authentication information.

Body

The body is only available for the POSTPUT and PATCH methods. Here you need to provide a JSON in the correct format as provided by the endpoint host. The body accepts FormData or raw JSON data.

Outputs

As a result of making any rest call, the endpoint will respond with a JSON, which can contain information about your call, for example if it was successful, and any information you requested. You can define the path of any value you want to extract from the JSON by giving the consecutive element names separated by dots in the object path. If you need to address a list within the JSON (square brackets) you can do this by giving the index of the element you want, starting at zero.

Within the Blits platform it is possible to make use of reverse indexing (-1 will give you the last element of the list, -2 will give you the second to last element in the list and so on)

Show Output

With the show output function you can show the result of your REST call. The default values will be used for the variables. If you do not define any outputs it will show you the full JSON output. If you do define outputs, it will show your output values.


Example

In this example we will get weather information for a city. We will use the API from OpenWeatherMaps, whose documentation can be found here: https://openweathermap.org/current

Click add a function. The name can be anything, description is optional. Function type is of course REST.

For the input you must define the city for which you want to find weather info, so call the input variable city with default value Amsterdam. As we will only be getting information, the method will be GET. The API Path can be found on the open weather map website and is:

https://api.openweathermap.org/data/2.5/weather?q=[City]&appid=4252a8f378a51e841eb91528c5ef2c00&units=metric

The first part until the first question-mark is the function we want to call. After that we will input settings. firstly we will pass the city variable. we define that we want to pass more variables with the ampersand (&). after that we pass our personal API key, which can be found on the OpenWeatherMap website. Finally we tell the API that we want to use metric units.

For the header we will write down “content-type: application/json” (without the “”) This is used to tell the endpoint that we are making an API call and wish to obtain a JSON. 

Finally we define for the outputs that we want to obtain the weather description and temperature. To this end we define two outputs: WeatherCondition and Temperature

For the first one the object path is weather.0.description and for the second variable the path is main.temp


    • Related Articles

    • v 2.1.9

      Release date: 30-05-2021 Security improvements Backend and frontend vulnerabilities fixed 2FA for Microsoft account users introduced Aligned password policy with Microsoft AD  Rest SQL/SQL variables encrypted Enabled (admin) users to make REST/SQL ...
    • Contains

      The contains condition enables you to divert the flow of the conversation if the input contains a word or a number. The rest of the input is not taken into consideration by the Condition block. For example: If ‘yes’ is specified as the specific word, ...
    • v2.0.1

      The list below shows the features that were introduced, changed or removed with the release of v2.0.1. In this version, no bugs worth mentioning were resolved, but UX improvements were made. Features:  Ability to integrate chatbots with Twilio for ...
    • Connectors to third party systems

      Blits can connect your bots to different systems to retrieve and process data that can be used during conversations. We advise all users to use the function builder to build your own connections and integrations via REST or SQL. If more custom, or ...
    • Function block

      What is the Function block The function block will trigger a function that was previously created under the functions tab at the right time in the flow. Hence, function blocks support REST, SQL, Adaptive Cards, Custom-code, and Storage functions. ...