Table of Contents

How to Use the Webhook Block in Landbot: A Beginner's Guide

Abby Updated by Abby

If you already know how to use REST API or if you're looking for something more advanced check out our article for advanced users here

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

Landbot’s native integrations (like Airtable, Mailchimp, and Google Sheets) cover many common use cases.

But when you need to connect to other systems—whether it’s your CRM, a custom database, or an internal tool—the Webhook Block provides the flexibility to integrate with (almost) any REST API

What is a webhook?

In Landbot the webhook block is a REST API block, it allows you to send, receive, update, or delete data in third parties and receive a response that can be used in the flow.

If you're looking for polling and getting realtime updates to your hook you may want to check out MessageHooks

In this article we'll explain how to use an API while we go through each part of the webhook block with a real example, you can follow along with the weather API we'll be using - it's free but you need to sign up to get an API key

How do APIs work?

Here's a graphic to get an idea, just replace 'CLIENT' with 'Webhook block' 😉

API Basics

Term Definition
API key A unique passcode of letters and numbers that grants access to an API
Endpoint The digital location where an API receives requests about its resources (the url)
Request method Uses HTTP methods (GET, POST, PUT, DELETE) to tell the API what you want it to do
Parameters Adds extra information, such as variables to the endpoint and is used to filter the response
Request body Some APIs require data to be in JSON format, in that case we will use the request body
API call Process of a client (the webhook block) making an API request to a server
Status code A number code that appears in the body of an API response that tells you if your request was successful or not
API server Authenticates and processes API requests before delivering an appropriate response
API response A response generated by the API server and returned to the client (the webhook block)

API keys

Like a password, an API key is a string of letters and numbers that serves as a unique access code or authentication token. You'll need one to access most APIs. It's a security measure to help track and control API usage, so only authorized users or applications can access the data. Similar to how you need a password to access your apps, you need an API key to access APIs.

This will usually go in the Header section of the webhook. The key as well as the value format (Bearer vs Token) will depend on the API you are connecting to

In our weather example we'll toggle off Customize Headers, since our API key is going in the Parameter section, however this isn't very common.

Endpoints

An endpoint is where an API connects with another application, usually in the form of a specific URL or web address. Endpoints serve as the location for where requests are received and responses to those requests are sent. They're a clear and standardized way for users to work with APIs.

Our weather example endpoint looks like this:

If you're following along with the weather API you'll notice an HTTP error, the webhook only accepts HTTPS, so we'll just add an S after HTTP and it will work correctly

If you're not a heavy user you can ignore the 'Set Domain Fields' button, otherwise you can find more information here

Request methods

To communicate what you want to accomplish via the API endpoint, you need to make a request. There are four specific HTTP methods you can use:

  • GET: This is used to retrieve specific data from the API.
  • POST: This tells the API you want to add, or post, new data to the server. 
  • PUT: This is used to update (overwrite) existing resources on the API. 
  • DELETE: This is used to delete existing data from the server. 

You'll notice there are more methods, however these are used for testing purposes and are for very advanced users

Parameters

Parameters define how an API request should be processed. They act like filters or modifiers, telling the API exactly what data you want or how to handle your request.

How these are set up, and which parameters you can use will depend on the API, as each API is set up differently

In our example the parameters are - key (our API key) and q with the value of the city where we want to check the weather

Request body

Some APIs will require us to send the data in JSON format, to do this we can use the request body

Imagine we collected the user name, email and phone number and we want to send all of that to our CRM, here's how we can do that:

When adding variables to the webhook block they should be added like this: "@field", they will be sent in their original format, meaning if the variable is an integer even though we add the quoatation marks, it will still be sent as an integer

So if we have the variable @name it should be added in the webhook as: "@name"

Our weather example doesn't require us to send data in JSON format so we'll toggle this off

API calls

An API call is the process of making a request, the API retrieving the data you requested, and then getting a response from the API. The only thing you have to do is make the request using one of the above HTTP methods.

In Landbot we'll do this by clicking 'Test the request', if we're testing a request that has parameters, they will need to be manually added in this section for the test

For our weather example we'll add the @city variable to test

Status codes

With every request you make, you'll receive a status code. This three-digit number tells you whether or not your request was successful. The first number in the code represents the category of the status. If the code starts with a 2, your request was successfully processed. If the code starts with a 4, something went wrong. Status codes allow you to understand the outcome of your request and figure out your next move based on the response.

Saving the API response

By default the webhook block saves the entire API response (you'll still need to add a variable to store it), unless we're testing the flow we rarely want to save the entire response

After we've tested the request we can click on the purple banner (we can only click after testing) and save the part that is useful for us

In our example I'll just save the current weather, we don't need to display any extra information

FAQS & Troubleshooting

Is this compatible with all channels?
Yes! You can use the webhook block in all channels (in WhatsApp you need to have a number integrated to test)
What if the response takes longer than 30 seconds?
If your API takes longer than 30 seconds to respond you make need to make the request in a third-party, here's an example of how you can do that
Why am I getting a 500 error?
If your API request is working correctly outside of Landbot, but you are getting a 500 error inside of Landbot it may be because you haven't created a channel yet, for WhatsApp and APIChatbots you need to have a channel to test the webhook block
How can I send files?
When a user uploads a file in the flow Landbot stores the file and returns the url where the file is hosted as the variable, unfortunately it's not possible to send the file itself, but you can send the url where the file is hosted
How do I add a listener?
The webhook block does not have listening capabilities, if you are waiting for an event in a third party you will need to trigger an API call to Landbot when that event occurs, here's an example
How can I connect to chatgpt?
We have several tutorials! Check them out here
Why am I not getting a response from Make/Zapier?
Automations happening outside of Landbot usually take more than 30 seconds to complete, if you need the data from the automation to continue the flow you can check this article
How can I display the data from the webhook as buttons?
If you'd like to display the data from the webhook as buttons you'll need the Dynamic Data block
My bot flow is stopping at the webhook block
Do you have a date type variable saved? That may be why! Webhooks don't currently support date type variables
If that's not it, make sure the red output is also connected to the flow!
How can I debug the API response?
Besides checking the logs we've found the easiest way to debug is adding a message block after the webhook containing all of the variables sent in the webhook as well as a second message block containing the entire webhook response, this gives an overall view of what is happening
Why can't I use the Landbot API inside the webhook?
This is a security measure, if you have a specific use-case where you need to use the API in the flow reach out to our support team! There may be other ways to achieve what you want

Was this article helpful?

Webhook Block Dashboard

Contact