Table of Contents

Send WhatsApp Messages with Landbot API

Pau Sanchez Updated by Pau Sanchez

Media Message Templates for WhatsApp, can be sent via API

Requirements to send WhatsApp Message Templates

1. WhatsApp Business Channel only

Doesn't work in WhatsApp Testing channels

2. User opt-in

Proactive messages with WhatsApp cannot be sent to those without the opt-in

3. Approved WhatsApp Templates

WhatsApp has to validate previously

The API method to Send a template

Here is the url to the dev docs documentation: Link

API Requests Authorization

Landbot Platform API requires the following header for the authorization:

Header

Field

Description

Authorization

Default value: Token :agent_token

Content-Type

Default value: application/json

Find agent_token (API Token)

You can find your :agent_token (API Token) in https://app.landbot.io/gui/settings/account

Bear in mind that it is unique per teammate, and will behave according to the permissions granted to that teammate

Find Template ID

From the Templates section

From the same section where are all the Templates (https://app.landbot.io/gui/channels/whatsapi/templates).

Filter to see only the Approved templates

And you will see a column with the specific ID of the desired templates:

Find Template Language code

Currently the best way to find the template_language code is using the list method of the templates: Link to method

curl --location --request GET 'https://api.landbot.io/v1/channels/whatsapp/templates/' \--header 'Content-Type: application/json' 
\--header 'Authorization: Token XXXXXXXXX'

Find customer id

The customer id is the basic identifier, as templates need to be sent one by one, you will need to specify the customer_id

There are several methods you can use to find the customer id of a WhatsApp user that has done the opt-in:

1. Opt-in request response

If you use the end point for the opt-in of customers, in the response of the request, it will return the id value, that is the customer_id

2. Via API using phone as a filter

curl --location --request GET 'https://api.landbot.io/v1/customers/?search_by=phone&search={{phone number}}&opt_in=true' \--header 'Content-Type: application/json' 
\--header 'Authorization: Token XXXXXXXXX'

3. In the bot from the Analyze section under the column Customer Id

4. From the Inbox section in the top right panel

Request Examples

Here are different examples with the required code you need to send different models of Templates

1. Message Media Template Picture (with parameter) and Body (with parameters)

cURL snippet

curl --location --request POST 'https://api.landbot.io/v1/customers/:customerID/send_template/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXX' \
--data-raw '{
"template_id": 1082,
"template_params": {
"header": { "url":"https://upload.wikimedia.org/wikipedia/commons/6/6e/Mona_Lisa_bw_square.jpeg"
},
"body": {
"params": ["Variable one", "Variable two"]
}, "buttons":[]
},
"template_language": "en"
}'

2. Message Media Template Header (with parameters) and Body (with parameters)

cURL snippet

curl --location --request POST 'https://api.landbot.io/v1/customers/:customerID/send_template/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXX' \
--data-raw '{
"template_id": 1137,
"template_params": {
"header": { "params": ["variable one header"] },
"body": { "params": ["variable one body"] },
"buttons":[]
},
"template_language": "en"
}'

3. Message Media Template Header and Body (with parameters)

cURL snippet

curl --location --request POST 'https://api.landbot.io/v1/customers/:customerID/send_template/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXX' \
--data-raw '{
"template_id": 1074,
"template_params": {
"header": {
"params": []
},
"body": {
"params": ["Variable one", "Variable two","Variable three"]
},
"buttons":[]
},
"template_language": "en"
}
}'

4. Message Media Template with Buttons (Quick reply cannot use parameters)

cURL snippet

curl --location --request POST 'https://api.landbot.io/v1/customers/:customerID/send_template/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXX' \
--data-raw '{
"template_id": 1200,
"template_params": {
"header": {
"params": []
},
"body": {
"params": []
},
"buttons":[]
},
"template_language": "en"
}'

5. Message Media Template with Header (with parameter), Body (with parameters) and Button (with Parameters)

cURL snippet

curl --location --request POST 'https://api.landbot.io/v1/customers/:customerID/send_template/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXX' \
--data-raw '{
"template_id": 1243,
"template_params": {
"header": {
"params": ["variable one"]
},
"body": {
"params": ["variable one","variable two"]
},
"buttons":[]
},
"template_language": "en"
}'

6. Message Media Template with Body (with parameters) and Click to Action (Button with Parameter)

cURL snippet

curl --location --request POST 'https://api.landbot.io/v1/customers/:customerID/send_template/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXX' \
--data-raw '{
"template_id": 1725,
"template_params": {
"header": {
"params": []
},
"body": {
"params": ["variable one"]
},
"buttons":[ {
"params": ["variable_one"]
} ]
},
"template_language": "en"
}'

7. Message Media Template with Header (document) and Body (with parameter)

cURL snippet

curl --location --request POST 'https://api.landbot.io/v1/customers/:customerID/send_template/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXX' \
--data-raw '{
"template_id": 1726,
"template_params": {
"header": { "url": "https://www.domain.com/file.pdf",
"filename": "Nameofthefile"
},
"body": {
"params": ["variable one","variable two"]
},
"buttons":[]
},
"template_language": "en"
}'

Default Agent Assignation, and how to assign it to a bot via API

By default, once a WhatsApp a message has been sent via API, as described before, the user session will be assigned to the Agent which was used the API token:

There are 2 possible approaches that you can use to redirect the user to an automated conversation, right after the first request (Send WhatsApp Message)

Unassign

It will "unassign" the chat from the agent, and after the first interaction from the user. It will be redirected to the first message, of the bot linked to the WhatsApp Channel

Link to docs: https://dev.landbot.io/api/index.html#api-Customers-PutHttpsApiLandbotIoV1CustomersCustomer_idUnassign

cURL snippet

curl --location --request PUT 'https://api.landbot.io/v1/customers/:customerID/unassign/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXX' \
--data-raw ''

Assign to bot (and node)

If you want to assign the user to a specific bot and a specific node, instead of the default first node in of the linked bot to the WhatsApp Channel

Link to docs: https://dev.landbot.io/api/index.html#api-Customers-PutHttpsApiLandbotIoV1CustomersCustomer_idAssign_botBot_id

cURL snippet

curl --location --request PUT 'https://api.landbot.io/v1/customers/:customer_id/assign_bot/:bot_id/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Token XXXXXXXXX' \
--data-raw '{
"launch": false,
"node": "node_id"
}'

Find :bot_id

To find the bot id, go to the bot inside the app, and the number in the url, is the bot id

Find :node_id

To retrieve the node id, in the bot builder, select the node (block) where you want the bot to use, and press right click. An option to copy the node id, will display. Once you click it will set the number in your clipboard

Error Log

Select the WhatsApp Channel, and click on "Error Log", in this section you can find the logs of the errors when you are sending templates

How did we do?

WhatsApp's Message Templates

Audience block

Contact