The API node allows you to connect with external services using RESTful API calls. You can specify the endpoint (URL) of the external service you want to communicate with.

Additionally, you can include custom headers to provide necessary information for the request. When making POST, PUT, or PATCH requests, you’ll have to format the data in JSON within the body section. This enables you to send and receive data seamlessly between Botstacks and external services, facilitating actions like creating bookings or accessing information from third-party platforms.

Request

The request section is where you can set your request method and url. The available request methods in the API node are GET, POST', PUT, PATCH, and DELETE. The url field is where you will put the url of your REST api request. For example, you would set the request method to GETand the url tohttps://api.sampleapis.com/coffee/hot` to list receive a list of hot coffee and their ingredients.

Headers

It’s likely that you will need to add headers to your request, such as the Authentication header. You may add as many headers as you need.

Body

In the case where you are calling a POST, PUT, or PATCH endpoint, you may also want to pass along the body. This is in JSON format, so make sure you format it correctly.

Interopolation

All the fields in the API node have string interpolation capabilities. This means you can dynamically generate the url, header values, or data within the request body.

As an example, if we wanted to get a list of hot or cold coffee options based on what the user wants. There are two public/free REST endpoints https://api.sampleapis.com/coffee/hot and https://api.sampleapis.com/coffee/iced. To handle this we can save the the desired type of coffee as a variable called coffee_heat. Then we can use the api node with the request url set to https://api.sampleapis.com/coffee/{coffee_heat}.

Routing

If the response received is 2xx, the Success route will be traversed. The result of the API request is outputted. This means a connected node can reference the results of the api call via {api-x} (You can see the nodes slug in the top-right part of the node).

If any other http code is received, the Error route will be traversed.