With nearly 3 billion lively customers worldwide, WhatsApp has turn out to be a superb channel for companies seeking to join with their viewers successfully. The WhatsApp Enterprise API takes its performance to the following stage.
The API helps you to ship messages to 1000’s of consumers routinely. You possibly can ship texts, photos, movies, and even interactive messages. It is a good way for companies to ship clients data related to them, proper after they want it. No extra generic mass emails or hoping they see your social media posts.
On this information, we’ll stroll you thru how you can use the WhatsApp API to ship messages. We’ll cowl:
- Organising your WhatsApp Enterprise Platform
- Getting entry tokens
- Sending several types of messages
- Find out how to automate the messaging workflow effectively
Let’s get began then.
Getting Began with the WhatsApp Enterprise Platform
The WhatsApp Enterprise Platform is designed for medium to giant companies to have interaction with clients on a big scale. It allows enterprises to rapidly provoke conversations, ship notifications about help or purchases, supply customized companies, and help clients of their most well-liked communication channels.
Listed below are the three internet hosting choices out there for the WhatsApp Enterprise API:
- Cloud API: Hosted by Meta, this API affords a simple, maintenance-friendly approach for companies to attach with clients. It is the popular alternative for many firms on account of its simplicity, ease of use, and automated scaling.
- On-Premises API: Companies must host this themselves. This feature gives extra management over the infrastructure however requires extra technical sources and upkeep.
- Enterprise Administration API: Important for managing your WhatsApp Enterprise Account settings, belongings, and message templates, this API is critical no matter whether or not you select the Cloud API or the On-Premises API.
💡
Do you know? The Cloud API means that you can ship as much as 1,000 messages per second, whereas the On-Premises API is restricted to 250 messages per second.
To begin utilizing the WhatsApp Enterprise Platform, you will need to create a Meta Developer Account and a enterprise app within the Meta Developer Dashboard. Whereas not obligatory, you’ll be able to arrange a Meta Enterprise Supervisor to prepare and handle your small business belongings, together with your WhatsApp Enterprise Account.
You will additionally must get hold of a devoted telephone quantity for your small business. Then, use that to create a WhatsApp Enterprise Account. Register the quantity by means of the WhatsApp Enterprise app or the API.
Then, add the WhatsApp product to your app within the Meta Developer Dashboard. It will routinely create a take a look at WhatsApp Enterprise Account, a take a look at enterprise telephone quantity, and a set of pre-approved message templates for testing and improvement functions.
To entry sure options, reminiscent of increased messaging limits and the power to ship template messages, you will need to full the Enterprise Verification course of. You have to submit your small business data for assessment within the Meta Enterprise Supervisor.
Necessities of WhatsApp Enterprise Administration API
The WhatsApp Enterprise Administration API is an important a part of the WhatsApp Enterprise Platform. It really works alongside the Cloud API and On-Premises API that will help you handle your WhatsApp Enterprise Account settings, belongings, and entry tokens.
Entry Tokens
Entry tokens are essential for authenticating your API requests. They guarantee safe communication between your utility and the WhatsApp Enterprise Platform.
The Enterprise Administration API helps three kinds of entry tokens:
- System Consumer Entry Tokens: These tokens signify your small business and do not expire. They’re important for Resolution Companions who share credit score strains with their clients. There are two kinds of System Consumer tokens:
- Worker System Customers: For restricted entry to particular WhatsApp Enterprise Accounts.
- Admin System Customers: For full entry to all WhatsApp Enterprise Accounts and belongings.
- Enterprise Integration System Consumer Entry Tokens: These tokens are particular to particular person buyer knowledge and are utilized by Tech Suppliers and Resolution Companions for automated actions with out person enter.
- Consumer Entry Tokens: Typically used for preliminary app testing. They expire rapidly and are much less appropriate for ongoing improvement. This token was used within the take a look at message despatched above.
Creating System Customers and producing Entry Tokens
To create a System Consumer and generate an entry token:

- Go to the Meta Enterprise Suite and discover your small business account.
- Click on the Settings icon and choose “Enterprise settings.”
- Go to “Customers” > “System customers” and click on “Add” to create an admin or worker System Consumer.
- Choose the System Consumer and click on “Generate new token.”
- Select the app and permissions for the token.
- Click on “Generate” to create the entry token.
Producing these entry tokens with the proper permissions is essential for guaranteeing your utility has the mandatory entry. With out that, your utility might encounter errors or be unable to carry out particular actions. It hinders your means to successfully use the WhatsApp Enterprise Platform.
💡
To get a Enterprise Integration System Consumer entry token, you should arrange Embedded Signup utilizing Fb Login for Companies. When a buyer completes the signup course of, you trade the acquired code for the token.
Price Limits
These limits decide the variety of API calls allowed per hour and assist stop abuse or overload of the platform. The precise limits rely upon the kind of name and your WhatsApp Enterprise Account standing. Figuring out these limits and adhering to them helps keep away from potential disruptions.
💡
Tip: All the time maintain your entry tokens safe and by no means share them publicly, as they grant entry to your WhatsApp Enterprise Account.
Understanding entry tokens, how you can create them, and the speed limits will assist you to authenticate your requests and handle your WhatsApp Enterprise Account successfully.
Find out how to Set Up the WhatsApp Cloud API
Companies desire Cloud API over on-premises because it affords a extra simple setup and upkeep course of. Meta hosts the mandatory infrastructure, guaranteeing scalability and reliability. This permits companies to concentrate on constructing their functions and buyer experiences quite than managing servers and infrastructure.
The WhatsApp Cloud API is a cloud-hosted model of the WhatsApp Enterprise Platform. It programmatically allows companies to ship and obtain messages, media, and interactive message templates.
With the cloud API, you’ll be able to simply combine WhatsApp messaging into your small business workflows, like buyer help, order updates, appointment reminders, and functions like CRM and advertising platforms.
To begin utilizing the WhatsApp Cloud API, observe these steps:

1. Create a Meta Developer Account: If you do not have one already, create a Meta Developer Account at builders.fb.com.

2. Create a brand new App: Within the Meta Developer Dashboard, click on on “Create App”, select others, choose “Enterprise” because the app kind. Fill within the required particulars and click on “Create App”.

3. Add the WhatsApp product: In your app’s dashboard, scroll to the “Add a Product” part and click on “Set Up” on the WhatsApp card. You probably have a Meta Enterprise Account (MBA), you may be requested to hyperlink it throughout this course of. If not, you may be guided to create one.

4. Configure your WhatsApp Enterprise Account: As soon as your MBA is linked, you may be taken to the WhatsApp Enterprise Account configuration dashboard.
Right here, you’ll be able to:
- Arrange a take a look at WhatsApp Enterprise Account (free however with utilization limitations)
- Create a take a look at enterprise telephone quantity linked to your WhatsApp Enterprise Account
- Generate pre-approved messaging templates for testing

5. Add a recipient quantity: To ship take a look at messages, you will need to add a legitimate WhatsApp quantity. Go to the App Dashboard, navigate to WhatsApp > API Setup, and below the message-sending part, search for the ‘To’ area to handle your telephone quantity listing. Enter a legitimate WhatsApp quantity and confirm it utilizing the affirmation code despatched through WhatsApp.

6. Ship a take a look at message: Use the pre-approved ‘hello_world’ template to ship a take a look at message to your verified recipient quantity. You are able to do this utilizing the API panel within the dashboard or by working the supplied Python code.
import requests
url = "https://graph.fb.com/v17.0/206324309221106/messages"
headers = {
'Authorization': 'Bearer YOUR_TEMPORARY_ACCESS_TOKEN',
'Content material-Sort': 'utility/json'
}
knowledge = {
"messaging_product": "whatsapp",
"to": "RECEPIENT_PHONE_NUMBER",
"kind": "template",
"template": {
"identify": "hello_world",
"language": {
"code": "en_US"
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.textual content)
On this instance:
- Make sure that your take a look at enterprise quantity is within the ‘From’ area.
- Make sure the recipient’s quantity is chosen within the ‘To’ area. You possibly can ship messages to a number of numbers if added.
The command you may use signifies that you just’re sending a template message, specifying the ‘hello_world’ template. A message just like the one under ought to seem on the recipient’s telephone quantity.

Shifting to Manufacturing
If you’re able to ship messages to your clients, you’ll be able to add an precise enterprise telephone quantity to the API Setup and create an official WhatsApp Enterprise Account. It will permit you to ship messages to your clients with out the restrictions of the take a look at account.
Find out how to Ship Messages Utilizing the WhatsApp Cloud API
The platform additionally helps two kinds of messages: free-form and template messages. Free-form messages permit for extra flexibility however should be despatched inside 24 hours of the client’s final message. It may well embody textual content, photos, movies, paperwork, and clickable parts.
Template messages are pre-approved, standardized codecs that companies can use to ship notifications or buyer care messages to opted-in clients. These messages require person consent and approval from the WhatsApp assessment staff. They’ll embody appointment reminders, delivery data, difficulty decision, or cost updates.
To ship a message utilizing the WhatsApp Cloud API, you should make an HTTP POST request to the /messages endpoint.
POST //messages
The request ought to embody your entry token within the Authorization header and the message payload within the request physique. The message payload has a typical format, with variations relying on the message kind:
{
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "",
"kind": "",
// Particular payload relying on message kind
}
: WhatsApp ID or telephone variety of the recipient (e.g., +16315551234).
: Sort of message (e.g., ‘textual content’, ‘picture’, and so forth.).
The response comprises a message ID, which is useful for sending replies or reactions and checking for unsuccessful requests through the standing code within the response (typical conference the place standing code 200 signifies a profitable name).
{
"messaging_product": "whatsapp",
"contacts": [{
"input": "",
"wa_id": "",
}],
"messages": [{
"id": "",
}]
}
Let’s discover how you can ship several types of messages utilizing the WhatsApp Cloud API.
➡️
To make use of the code, exchange the placeholders within the payload with the suitable contact data.
1. Textual content Messages
Textual content messages are essentially the most primary kind of message you’ll be able to ship utilizing the WhatsApp Cloud API. They comprise plain textual content and may embody formatting and preview URLs.
This is an instance of how you can ship a textual content message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "textual content",
"textual content": {
"preview_url": False,
"physique": "Howdy, it is a textual content message from the WhatsApp Cloud API!"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
is the ID of your WhatsApp Enterprise Account telephone quantity.YOUR_ACCESS_TOKEN
is the entry token you generated in your app.RECIPIENT_PHONE_NUMBER
is the WhatsApp variety of the message recipient.
The message payload consists of the next fields:
messaging_product
: All the time set to'whatsapp'
.recipient_type
: Set to'particular person'
for sending messages to particular person customers.to
: The WhatsApp variety of the message recipient.kind
: The kind of message you are sending, on this case,'textual content'
.textual content
: An object containing the textual content message particulars, together withpreview_url
(set toFalse
to show off hyperlink previews) andphysique
(the precise textual content content material of the message).
2. Response Messages
Response messages permit you to react to a earlier message despatched by a person with an emoji. This function allows you to acknowledge or reply to messages in a fast and expressive approach.
This is an instance of how you can ship a response message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "response",
"response": {
"message_id": "wamid.HBgLM...",
"emoji": "U0001F600"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier instance.kind
is about to'response'
to point that you just’re sending a response message.- The
response
object comprises themessage_id
(ID of the message you are reacting to) and theemoji
you wish to use because the response – on this case, the emoji python code is 😀.
3. Media Messages
Media messages permit you to ship varied kinds of media information, reminiscent of photos, paperwork, audio, or video, to recipients utilizing the WhatsApp Cloud API.
Exchange TYPE
with the suitable media kind (picture
, doc
, audio
, or video
), MEDIA_URL
with the media file URL, and CAPTION
with an elective caption for the media.
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "picture",
"picture": {
"hyperlink": "https://instance.com/picture.jpg",
"caption": "Try this picture!"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.kind
is about to"picture"
to point that you just’re sending a picture message.- The
picture
object comprises thehyperlink
(URL of the picture file) and an electivecaption
for the picture. - If the
picture
object comprises an object, use theID
property to point its ID (which you will need to generate) or location in your public server.
4. Location Messages
Location messages permit you to ship a location’s coordinates to a WhatsApp person.
To ship location messages, make a POST
name to /YOUR_PHONE_NUMBER_ID/messages
and fix a message
object with kind=location
. Then, add a location object.
This is an instance of how you can ship a location message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "location",
"location": {
"latitude": LATITUDE,
"longitude": LONGITUDE,
"identify": "LOCATION_NAME",
"tackle": "LOCATION_ADDRESS"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.LATITUDE
andLONGITUDE
are the coordinates of the situation you wish to ship.LOCATION_NAME
is the identify of the situation.LOCATION_ADDRESS
is the tackle of the situation.- Set
kind
to"location"
to point that you just’re sending a location message. It ought to embodylatitude
,longitude
,identify
, andtackle
.
5. Contact Messages
Contact messages permit you to ship a contact’s data, reminiscent of their identify, telephone quantity, and tackle, to a WhatsApp person.
This is an instance of how you can ship a contact message utilizing Python:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "contacts",
"contacts": [
{
"addresses": [
{
"street": "123 Main St",
"city": "Anytown",
"state": "CA",
"zip": "12345",
"country": "United States",
"country_code": "US",
"type": "HOME"
}
],
"birthday": "1990-01-01",
"emails": [
{
"email": "john.doe@example.com",
"type": "WORK"
}
],
"identify": {
"formatted_name": "John Doe",
"first_name": "John",
"last_name": "Doe"
},
"org": {
"firm": "Instance Inc.",
"division": "Gross sales",
"title": "Gross sales Supervisor"
},
"telephones": [
{
"phone": "+1 (555) 123-4567",
"type": "CELL",
"wa_id": "15551234567"
}
],
"urls": [
{
"url": "https://www.example.com",
"type": "WORK"
}
]
}
]
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- Set
kind
to"contacts"
to point that you just’re sending a contact message. contacts
: An array of contact objects containing contact data, reminiscent ofaddresses
,birthdays
,emails
,names
,org names
,telephone numbers
, andurls
.
6. Interactive Messages
Interactive messages permit you to create extra participating and interactive experiences for customers. The primary kinds of interactive messages are:
a. Record Messages
b. Reply Buttons
c. Messages with CTA (Name-to-Motion) URL Buttons
d. Circulation messages
To ship interactive messages, make a POST name to /YOUR_PHONE_NUMBER_ID/messages and fix a message object with kind=interactive. Then, add an interactive object.
a. Record Messages: Record messages current an inventory of choices for customers to select from.
This is an instance of how you can ship an inventory message utilizing Python:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "interactive",
"interactive": {
"kind": "listing",
"header": {
"kind": "textual content",
"textual content": "Select an choice:"
},
"physique": {
"textual content": "Please choose one of many following choices:"
},
"footer": {
"textual content": "Thanks in your choice!"
},
"motion": {
"button": "Choose",
"sections": [
{
"title": "Section 1",
"rows": [
{
"id": "option1",
"title": "Option 1",
"description": "This is the first option"
},
{
"id": "option2",
"title": "Option 2",
"description": "This is the second option"
}
]
}
]
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- Set
kind
to"interactive"
to point that you just’re sending an interactive message. - Set
interactive.kind
to"listing"
to specify that you just’re sending an inventory message. - The
interactive
object comprises the small print of the listing message, together with theheader
,physique
,footer
, andmotion
(which defines the listing sections and their corresponding rows).
b. Reply buttons: Reply buttons show as much as three buttons with predefined reply choices.
This is an instance of how you can ship reply buttons utilizing Python:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "interactive",
"interactive": {
"kind": "button",
"physique": {
"textual content": "Choose an choice:"
},
"motion": {
"buttons": [
{
"type": "reply",
"reply": {
"id": "option1",
"title": "Option 1"
}
},
{
"type": "reply",
"reply": {
"id": "option2",
"title": "Option 2"
}
}
]
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- Set
kind
to"interactive"
to point that you just’re sending an interactive message. - Set
interactive.kind
to"button"
to specify that you just’re sending reply buttons. - The
interactive
object comprises the small print of the reply buttons, together with thephysique
(button textual content) andmotion
(which defines the reply buttons and their corresponding IDs and titles).
c. Messages with CTA URL Buttons: They permit you to embody clickable buttons that redirect customers to a selected URL.

This is an instance of how you can ship a message with CTA URL buttons utilizing Python:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "interactive",
"interactive": {
"kind": "button",
"physique": {
"textual content": "Click on the button under:"
},
"motion": {
"buttons": [
{
"type": "url",
"url": "https://example.com",
"title": "Visit Website"
}
]
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- Set
kind
to"interactive"
to point that you just’re sending an interactive message. - Set
interactive.kind
to"button"
to specify that you just’re sending CTA URL buttons. - The
interactive
object comprises the small print of the CTA URL buttons, together with thephysique
(button textual content) andmotion
(which defines the URL buttons and their corresponding URLs and titles).
d. Circulation Messages: These messages are designed to information customers by means of a collection of predefined steps or screens. These messages present a extra participating and structured strategy to work together along with your clients.
This is an instance of how you can ship a Circulation Message utilizing the WhatsApp Enterprise API:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "interactive",
"interactive": {
"kind": "move",
"header": {
"kind": "textual content",
"textual content": "Welcome to our Circulation!"
},
"physique": {
"textual content": "Please observe the steps to finish the method."
},
"footer": {
"textual content": "Thanks for utilizing our service."
},
"motion": {
"identify": "move",
"parameters": {
"flow_message_version": "3",
"flow_token": "YOUR_FLOW_TOKEN",
"flow_id": "YOUR_FLOW_ID",
"flow_cta": "Begin",
"flow_action": "navigate",
"flow_action_payload": {
"display": "SCREEN_ID",
"knowledge": {
"key1": "value1",
"key2": "value2"
}
}
}
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
interactive.kind and interactive.motion.identify
should be set to"move"
to point that you just’re sending a Circulation Message.interactive.motion.parameters.flow_token
: This property is a novel token generated by the enterprise to function an identifier for the Circulation.interactive.motion.parameters.flow_id
: This property is a novel ID supplied by WhatsApp for the particular Circulation.interactive.motion.parameters.flow_cta
: This property represents the textual content displayed on the call-to-action (CTA) button, reminiscent of “Signup”. The character restrict for this property is 20 characters, and emojis aren’t allowed.interactive.motion.parameters.flow_action
: This property will be set to both"navigate"
or"data_exchange"
. The default worth is"navigate"
.
7. Sending Quoted Replies
You possibly can ship a message as a reply to a earlier message in a dialog by together with the ID of the earlier message within the context
object of your request payload. This fashion, the recipient will obtain the brand new message with a contextual bubble displaying the content material of the message you are replying to.
💡

This is an instance of how you can ship a reply utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"context": {
"message_id": "wamid.HBgLM..."
},
"kind": "textual content",
"textual content": {
"preview_url": False,
"physique": "It is a reply to a earlier message."
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.MESSAGE_ID_TO_REPLY_TO
is the ID of the message you wish to reply to.context
object ought to embody themessage_id
of the message you wish to reply to.- Set the
kind
of message you are sending (on this case,"textual content"
). textual content
object comprises the textual content message particulars, together withpreview_url
(set tofalse
to show off hyperlink previews) andphysique
(the precise textual content content material of your reply).
➡️
To make use of the code, exchange the placeholders (YOUR_PHONE_NUMBER_ID
, YOUR_ACCESS_TOKEN
, RECIPIENT_PHONE_NUMBER
, MESSAGE_ID_TO_REPLY_TO
) with the suitable values in your use case.
8. Video Messages
Now you can ship video messages to your clients on WhatsApp. The message will show a thumbnail preview of the video together with an elective caption. When the recipient faucets on the preview, the video is loaded and performed inside WhatsApp.
This is an instance of how you can ship a video message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "video",
"video": {
"hyperlink": "https://instance.com/video.mp4",
"caption": "Try this superb video!"
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
YOUR_PHONE_NUMBER_ID
,YOUR_ACCESS_TOKEN
, andRECIPIENT_PHONE_NUMBER
have the identical meanings because the earlier examples.- The
video
object comprises thehyperlink
property, enter the URL of the video file hosted in your server right here. Alternatively, you should utilize theid
property when you have beforehand uploaded the video to WhatsApp’s servers utilizing the Media API. - The
caption
property is elective and means that you can add a caption to the video message. The utmost size of the caption is 1024 characters. - The API helps codecs like 3GPP and MP4, with a most dimension of 16 MB and a video/3gp MIME kind.
- Solely the H.264 video codec and AAC audio codec are supported. The video ought to both have a single audio stream or no audio stream in any respect.
9. Deal with Messages
Deal with messages permit you to simply request a supply tackle from WhatsApp customers. This function is presently out there just for companies based mostly in Singapore and their Singapore clients, and companies based mostly in India and their India clients.
This is an instance of how you can ship an tackle message utilizing Python:
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "RECIPIENT_PHONE_NUMBER",
"kind": "interactive",
"interactive": {
"kind": "address_message",
"physique": {
"textual content": "Please present your supply tackle."
},
"motion": {
"identify": "address_message",
"parameters": {
"nation": "IN",
"values": {
"identify": "John Doe",
"phone_number": "+91XXXXXXXXXX"
}
}
}
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
- Optionally, prefill tackle fields utilizing the
values
parameter. - Set
interactive.kind
to"address_message"
to point that you just’re sending an tackle message. - Present the message textual content within the
physique.textual content
area. - Set the
motion.identify
to"address_message"
. - Specify the
nation
parameter with the ISO code of the nation (e.g., “IN” for India, “SG” for Singapore).
When a person submits an tackle, you’ll obtain a webhook notification containing the small print of the submitted tackle within the response_json
area.
Whereas free-form messages supply flexibility, WhatsApp additionally gives a strategy to ship pre-approved message templates for widespread use instances, which we’ll discover under.
Template Messages
WhatsApp message templates are pre-approved message codecs that companies can use to ship notifications or buyer care messages to customers who’ve opted in. These messages can embody appointment reminders, delivery data, difficulty decision, cost updates, and extra.
Earlier than sending a template message, you should create a template within the WhatsApp Supervisor:
Step 1: Go to Enterprise Supervisor and choose your small business.
Step 2: Open the Menu and click on on “WhatsApp Supervisor”.

Step 3: Click on on “Handle Message Templates”.

You possibly can create message templates in two methods:
- Use one of many pre-approved templates supplied by WhatsApp. You could find an inventory of pre-approved templates right here. These templates are prepared to make use of and don’t want approval.
- Create your personal template with the required framework and submit it for approval by Meta. As soon as authorised, you can begin utilizing your customized template.
Let’s discover a number of examples of sending several types of message templates.
1. Catalog Template Messages
Catalog template messages permit you to showcase merchandise out of your stock in a WhatsApp message. To ship catalog template messages, you should have:
- A list uploaded to Meta. You possibly can create it utilizing this information.
- An e-commerce catalog linked to your WhatsApp Enterprise Account.
Setup: You will first must create a catalog template. Observe this information to create a catalog template in minutes.
Request Syntax: To ship a catalog template message, use the WhatsApp Enterprise Cellphone Quantity > Messages endpoint.
As an example we create a template referred to as summer_sale_catalog.
import requests
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "1605551234",
"kind": "template",
"template": {
"identify": "fashionista_summer_dresses",
"language": {
"code": "en_US"
},
"elements": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Floral Maxi Dress - $79.99"
},
{
"type": "text",
"text": "Bohemian Sundress - $59.99"
},
{
"type": "text",
"text": "Lace Midi Dress - $89.99"
}
]
},
{
"kind": "button",
"sub_type": "CATALOG",
"index": 0,
"parameters": [
{
"type": "action",
"action": {
"thumbnail_product_retailer_id": "SDRSS2023"
}
}
]
}
]
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
- The
template
object specifies the identify of the catalog template (fashionista_summer_dresses
) and the language code (en_US
for English). - The
elements
array comprises threeparameters
, every representing a distinct summer time costume and its worth:- The primary parameter represents the “Floral Maxi Costume” priced at $79.99.
- The second parameter represents the “Bohemian Sundress” priced at $59.99.
- The third parameter represents the “Lace Midi Costume” priced at $89.99.
button
showcases a selected summer time costume from the catalog utilizing thethumbnail_product_retailer_id
set to"SDRSS2023"
.
2. Carousel Template Messages
Carousel templates permit you to ship interactive messages with a number of scrollable playing cards, every containing a picture, textual content, and buttons.
Request Syntax: Just like catalog templates, use the WhatsApp Enterprise Cellphone Quantity > Messages endpoint.
Under is a pattern request for dispatching a carousel template, incorporating a message bubble that wants enter for 2 distinct variables. It consists of two carousel playing cards, every that includes a picture header, and necessitates enter for textual content within the physique and variables related to buttons.
Setup: You will must be sure to create a carousel template first. Observe this information to create a carousel template inside seconds.
Instance Request:
import requests
import json
url = "https://graph.fb.com/v13.0/YOUR_PHONE_NUMBER_ID/messages"
headers = {
"Authorization": "Bearer YOUR_ACCESS_TOKEN",
"Content material-Sort": "utility/json"
}
}
knowledge = {
"messaging_product": "whatsapp",
"recipient_type": "particular person",
"to": "1605551234",
"kind": "template",
"template": {
"identify": "fashionista_summer_carousel",
"language": {
"code": "en_US"
},
"elements": [
{
"type": "header",
"parameters": [
{
"type": "text",
"text": "Fashionista Summer Collection"
}
]
},
{
"kind": "physique",
"parameters": [
{
"type": "text",
"text": "Check out our stunning summer dresses:"
}
]
},
{
"kind": "CAROUSEL",
"playing cards": [
{
"card_index": 0,
"components": [
{
"type": "HEADER",
"parameters": [
{
"type": "IMAGE",
"image": {
"id": "1234567890"
}
}
]
},
{
"kind": "BODY",
"parameters": [
{
"type": "TEXT",
"text": "Floral Maxi Dress"
},
{
"type": "TEXT",
"text": "$79.99"
}
]
},
{
"kind": "BUTTON",
"sub_type": "URL",
"index": 0,
"parameters": [
{
"type": "TEXT",
"text": "floral-maxi-dress"
}
]
}
]
},
{
"card_index": 1,
"elements": [
{
"type": "HEADER",
"parameters": [
{
"type": "IMAGE",
"image": {
"id": "0987654321"
}
}
]
},
{
"kind": "BODY",
"parameters": [
{
"type": "TEXT",
"text": "Bohemian Sundress"
},
{
"type": "TEXT",
"text": "$59.99"
}
]
},
{
"kind": "BUTTON",
"sub_type": "URL",
"index": 0,
"parameters": [
{
"type": "TEXT",
"text": "bohemian-sundress"
}
]
}
]
},
{
"card_index": 2,
"elements": [
{
"type": "HEADER",
"parameters": [
{
"type": "IMAGE",
"image": {
"id": "1357924680"
}
}
]
},
{
"kind": "BODY",
"parameters": [
{
"type": "TEXT",
"text": "Lace Midi Dress"
},
{
"type": "TEXT",
"text": "$89.99"
}
]
},
{
"kind": "BUTTON",
"sub_type": "URL",
"index": 0,
"parameters": [
{
"type": "TEXT",
"text": "lace-midi-dress"
}
]
}
]
}
]
}
]
}
}
response = requests.publish(url, headers=headers, json=knowledge)
print(response.json())
On this instance:
- The
template
object specifies the identify of the carousel template ("fashionista_summer_carousel"
) and the language code ("en_US"
for English). - The
elements
array comprises 4 objects:header
shows the title “Fashionista Summer season Assortment”.physique
gives an introductory message.CAROUSEL
consists of an array ofplaying cards
, every representing a distinct summer time costume.
- Every card has a
card_index
and its personal set ofelements
:HEADER
shows a picture of the costume utilizing thepicture
parameter, theBODY
part exhibits the identify and worth of the costume, and theBUTTON
consists of the URL slug for the particular costume.
For extra data on message templates and their utilization, confer with the WhatsApp Enterprise Platform documentation.
WhatsApp Messaging Workflow
How does all of it translate into a whole messaging workflow? That is what we’ll talk about on this part. Let’s take into account a Whatsapp advertising marketing campaign for instance. The concept is to attempt to automate it utilizing the Whatsapp API in Python.
To start with, we’ll automate the method of extracting every day leads from HubSpot through its API. Automated messages will then be despatched to those leads by means of WhatsApp’s API. Sounds fascinating, proper? Let’s break it down step-by-step.
Please be aware that we’ll be utilizing HubSpot fields to create dynamic messages based mostly on varied attributes.
Step 1: Script to Get Every day Leads from HubSpot
Let’s write a Python script to fetch every day leads from HubSpot utilizing their API. We’ll use a customized area, like Date_Created
, to filter the leads created throughout the final 24 hours.
import requests
from datetime import datetime, timedelta
# HubSpot API particulars
HUBSPOT_API_KEY = 'your_hubspot_api_key'
HUBSPOT_CONTACTS_URL = 'https://api.hubapi.com/crm/v3/objects/contacts'
# Calculate yesterday's date
yesterday = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')
# Question parameters for the API name
params = {
'hapikey': HUBSPOT_API_KEY,
'restrict': 100, # Modify the restrict as wanted
'properties': ['firstname', 'lastname', 'phone', 'email', 'Date_Created'],
'filters': [{
'propertyName': 'Date_Created',
'operator': 'GTE',
'value': yesterday
}]
}
# API name to get contacts
response = requests.get(HUBSPOT_CONTACTS_URL, params=params)
leads = response.json()
# Extract related data
daily_leads = [{'name': f"{lead['properties']['firstname']} {lead['properties']['lastname']}",
'telephone': lead['properties']['phone'],
'electronic mail': lead['properties']['email']}
for lead in leads['results']]
# Print the leads
print(daily_leads)
ask
This script does the next:
- We calculate yesterday’s date utilizing
datetime
andtimedelta
to filter leads created throughout the final 24 hours. - We extract the related data (identify, telephone, electronic mail) from the leads and retailer them within the
daily_leads
listing.
Step 2: Sending Automated Messages through WhatsApp API
Now that we have now the listing of every day leads, let’s ship them customized messages utilizing the WhatsApp API. We’ll create dynamic messages based mostly on the lead’s data from HubSpot, reminiscent of their identify, electronic mail, or some other related knowledge.
import requests
import json
# WhatsApp API particulars
WHATSAPP_API_URL = 'https://graph.fb.com/v18.0/YOUR_PHONE_NUMBER_ID/messages'
ACCESS_TOKEN = 'your_whatsapp_access_token'
# Operate to ship message
def send_whatsapp_message(phone_number, message):
headers = {
'Authorization': f'Bearer {ACCESS_TOKEN}',
'Content material-Sort': 'utility/json'
}
payload = {
'messaging_product': 'whatsapp',
'recipient_type': 'particular person',
'to': phone_number,
'kind': 'textual content',
'textual content': {'physique': message}
}
response = requests.publish(WHATSAPP_API_URL, headers=headers, json=payload)
return response.json()
# Loop by means of the leads and ship messages
for lead in daily_leads:
# Customized message based mostly on HubSpot fields
message = f"Howdy {lead['name']}, we have now thrilling updates for you! Verify your electronic mail at {lead['email']} for extra particulars."
# Ship message
send_response = send_whatsapp_message(lead['phone'], message)
print(f"Message despatched to {lead['name']}: {send_response}")
On this script:
send_whatsapp_message
takes a telephone quantity and a message as enter. This perform sends the message to the desired telephone quantity utilizing the WhatsApp API.- We loop by means of every lead within the
daily_leads
listing. - For every lead, we create a personalised message utilizing the lead’s data from HubSpot, reminiscent of their identify and electronic mail.
- We name the
send_whatsapp_message
perform to ship the customized message to the lead’s telephone quantity.
By combining these two scripts, you’ll be able to automate the method of extracting every day leads from HubSpot and sending them customized messages through WhatsApp. This workflow helps you interact along with your leads promptly and effectively, rising the probabilities of conversion and constructing stronger relationships.
💡
Now, if you happen to’re seeking to automate this workflow with out writing a line of script, you’ll be able to discover no-code options like Nanonets.
Find out how to automate WhatsApp messaging workflow with Nanonets
With Nanonets, you’ll be able to automate your complete WhatsApp messaging workflow utilizing pure language prompts. Merely describe your workflow necessities in plain English, and Nanonets’ clever workflow builder will create the workflow inside seconds.
To get began, you should authenticate your HubSpot and WhatsApp accounts inside Nanonets. As soon as that is executed, you are able to deploy your workflow and make it reside.
Let’s discover a number of extra sensible examples of how you should utilize Nanonets to automate your WhatsApp messaging workflow:
1. Gross sales Lead Notification Workflow
Maintaining observe of each lead and guaranteeing well timed follow-up generally is a daunting job. That is the place this explicit workflow is useful. It means that you can automate lead data seize and use that data to set off notifications throughout completely different platforms.

Apps Concerned: WhatsApp, Salesforce, Google Sheets
Workflow:
- Set off: A possible buyer sends a message to your organization’s WhatsApp quantity expressing curiosity in a services or products.
- Motion 1: The lead’s particulars (identify, contact data, curiosity) are routinely logged into Salesforce below a brand new lead entry.
- Motion 2: The identical data can also be added to a Google Sheet that tracks all incoming leads for additional evaluation and follow-up.
- Motion 3: An automatic introductory message created utilizing a WhatsApp Catalog Template is distributed as a WhatsApp reply.
2. Appointment Reminder and Affirmation Workflow
If you’re a service supplier with a packed schedule, preserving observe of every shopper appointment generally is a actual problem. The Appointment Reminder and Affirmation Workflow takes the effort out of this by automating reminders and confirmations.

Apps Concerned: WhatsApp, Google Calendar, Trello
- Set off: A calendar occasion (appointment) is approaching in Google Calendar (e.g., 24 hours earlier than the scheduled time).
- Motion 1: An automatic reminder message is distributed to the shopper’s WhatsApp quantity, asking for affirmation or rescheduling.
- Motion 2: Upon receiving a affirmation reply from the shopper on WhatsApp, a Trello card is routinely created or up to date in your small business’s venture administration board. It signifies the confirmed appointment.
3. Buyer Help Ticket and Observe-Up Workflow
Managing a excessive quantity of help requests throughout a number of channels will be overwhelming. The next workflow streamlines the help course of by routinely creating tickets, notifying related groups, and guaranteeing immediate follow-up.

Apps Concerned: WhatsApp, Zendesk, Slack, Gmail, Trello
- Set off: A buyer sends a message to your small business’s WhatsApp quantity with a selected key phrase current within the message physique (e.g., “assist” or “help”).
- Motion 1: The message triggers the creation of a brand new help ticket in Zendesk.
- Motion 2: The ticket data, together with the client’s authentic message, is routinely forwarded to a devoted Slack channel (e.g., #customer_support) in your help staff to view and talk about.
- Motion 3: An automatic electronic mail is generated and despatched to your help staff’s Gmail account. It should embody the client’s message and phone particulars for follow-up. This electronic mail additionally comprises a hyperlink to the newly created Zendesk ticket.
- Motion 4: A Trello card is created in a chosen board and listing (e.g., ‘New Tickets’ listing on a ‘Help’ board), capturing the client’s difficulty particulars. This card is used for monitoring the progress of the ticket by means of varied levels of decision.
- Motion 5: As soon as the help ticket is marked as resolved in Zendesk, an automatic message is distributed to the client by means of WhatsApp. It should verify the decision of their difficulty and asking for any additional help.
Some of these automated messaging workflows could make your small business communication extra environment friendly and efficient. Think about with the ability to reply rapidly, maintain observe of essential interactions, and simply handle duties throughout completely different platforms. That is what you are able to do with Nanonets’ no-code workflow automation.