Table of Contents

Webhook block (External API REST)

Marco de Vita Updated by Marco de Vita

Prefer watching than reading? No problem, we've got you covered 👇

There may come a time where you need your chatbot to go outside the scope of the bot builder in order to connect it to a third-party service. Maybe you have a CRM you want to connect to your chatbot, you want to pull data from an existing Google Sheet document or you want to update the records on a database.

Landbot has a number of native integrations that let you do just that with a number of services such as AirTable, MailChimp, Zapier and many more. For everything else there's Webhooks!

Thanks to the Webhook block we can send data collected in a bot to external apps or servers, or bring data from outside sources (e.g. API, CRM...etc) to the bot.

Webhook lets your bot perform a series of actions, called RESTful operations, with external webhooks, APIs, or servers that let you pull, modify, add or delete data by using the following HTTP Methods:

  • POST
  • GET
  • PUT
  • PATCH
  • DELETE
  • HEAD
  • CONNECT
  • OPTIONS
  • TRACE

Landbot Webhook blocks do not accept XML, only JSON

URL & Method

In this section, you can set:

  1. The HTTP method used (GET, POST, PUT...)
  2. URL (endpoint) of the external API
Warning: the URL must be an HTTPS:// otherwise you will get an error that will not allow you to save changes.

If you want to make parts of the URL dynamic based on user attributes or inputs, you can insert variables from the picker:

  • Variables will only work in the URL path, not base URL ⟶ domain.com/@{variable} ✅ , @{variable}.domain.com
  • Custom variables will be formatted as @{variable} and system variables as ¿·@variable·?. See below for an example:

If you want to attach parameters to the end of the URL, it's best to set them up in Send Params section.

It's important that the service that your are working with uses proper SSL Certifications, otherwise the Webhook won't work and no error is displayed. If you have your doubts you can check it in this site

Send Params

If you want to attach parameters (e.g.?user=Elon) to the end of a request URL, you can set them up in this section as key-value pairs.

Added parameters will appear in Preview URL in green (NOTE: they won't appear in the URL field where you type)

Customize Headers

Headers in HTTP requests are commonly used for authorization, specifying content type...etc

By default, headers are disabled. If you want to send headers, just switch this section on:

You can set headers as key-value pairs. Once set up, they will be sent in JSON format in an actual request.

  • For example, if key = Accept, value = text/html{"Accept": "text/html"}

The specific headers you need will depend on the API you are connecting. Here are some common examples:

  • Specify content type as JSON format ⟶ Content-Type: application/json
Content-Type depends on the external service you are doing your request. Sometimes, the most common error is that the Content-Type is a different one: { "Content-Type" : "application/x-www-form-urlencoded" } Bear in mind that for this type, all the variables in the body of the requests, must have a value.
  • Authenticate API key ⟶ Authorization: Bearer 1234567ABC
  • Specify user agent ⟶ User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/604.1
Landbot doesn't send User-Agent as a header by default. Please add it if needed.

Customize the body

If you need to send information in the request body instead of the URL, you can add it to this section.

Warning: Request body must be written in JSON format, or you'll see validation errors.

Here is an example of a body formatted correctly in JSON:

{
"email": "@email",
"name": "@name",
"custom-variable":"@customvariable"
}
Variables must be wrapped in quotes ⟶ "@variable"

Test Your Request

You can test whether a request can work properly in this section.

  1. Click on Test the request
  2. It will trigger a real request to your desired API
  3. Response Status Code & Body will appear below the test button

Manually set values for test variables (OPTIONAL)

If your request contains variables, you may want to manually set their values for testing purposes. You can do so in this section before making a test request.

Save Response

You might want to save the response of a request as variables every time it's triggered to:

  • Split bot flow ⟶ E.g. Check a user's record in CRM to check if he is an existing customer.
  • Display data as options in the next step using Dynamic Data block ⟶ E.g. Get up-to-date inventory data from the external database and display them as products for purchase.
  • Store a record ⟶ E.g. Get a user's data from a 3rd-party API, and save it in your own database.

This is the section to do so.

By default, the entire response body will be saved. If you want to save a specific part of the response, you need to

  1. Test Your Request in the previous step first to identify JSON keys.
  2. Select the value you want to save from the dropdown
  1. Save it as a variable. You can break down the response into however many variables as you want.

Webhook Outputs

The webhook block has a green and red output, the green output is for successful calls and the red output means that the call failed due to an unreachable server

Something to keep in mind is that responses such as 'Forbidden', or 'Not found' will go through the green output, for those cases you'll need to use response routing.

Response Routing

If you want to split the flow based on the response status code, you can do so in this section.

Once you've specified all the paths, go to your canvas to set up their subsequent flows.

We currently don't support range routing (feature coming soon). You can only trigger a path by having the exact same status code instead of an entire range, such as 4XX. Responses with no specified path will follow the Default flow.

Every time you change options in the block editor, you will have to re-connect them on canvas.

Need a more practical description of how to use this feature? Check our guide on How to POST, GET and more with your bots.

Domain Variables

Domain variables allows developers to switch predefined base urls, in a simple manner. Instead of typing a specific url for each Webhook block in a static manner, Domain Variables, can be selected from the Domain Variables button below the url:

Once a Domain Variable is set, you can continue the edit adding the rest of the path, even add more Landbot variables

Or if needed, you can always delete the current the current Domain variable and path at once

Domain Variables (Headers)

Domain Variable can also being set up with specific Headers, that will be loaded also to those webhook using such Domain Variable

How to Set Domain Variables

From the Webhook dashboard section (link) you can add, edit and delete Domain Variables:

To create a new Domain Variable, press Create

Fill the data (name, url, and headers)

Change environment (edit a Domain Variables)

If at some point you need to change the values of a Domain Variable because you are changing from development to production for example, instead of changing every webhook, you just need to edit the Domain Variable that is being used. And the changes will be applied automatically, without the need to change anything in your current bots where you are using such Domain Variable

Landbot Public IP

In case you need to whitelist Landbot’s IPs, they are:

  • 34.77.31.159
  • 23.251.142.192

Channel Type compatibility

for Web

This feature is fully compatible.

for WhatsApp

This feature is fully compatible with WhatsApp.

for Messenger

This feature is fully compatible with Messenger.

How did we do?

Webhook Block Dashboard

How to TEST your Http Request (Webhook block)

Contact