Today, more than 1.5 billion people in over 180 countries use WhatsApp to stay in touch with friends and family-anytime and anywhere. Businesses all over the world have already been using WhatsApp informally to communicate with customers, whether about product enquiries or transactional updates. WhatsApp Business API is a new way for businesses to better manage such conversations with their customers and also reach new customers who will also value the fast, convenient and private messaging experience.
This guide provides specifications of the Gupshup's Messaging API for WhatsApp Business for the purpose of sending and receiving messages on WhatsApp via a simple REST API through HTTP/HTTPS modes.
This guide is intended for the developers and IT personnel of enterprises who plan to integrate their systems with the Gupshup's Messaging API. Also, this guide is applicable for application(app) of type Access API and those created after 28th January 2020 on our platform. In case you have an app which was created before the said date, please migrate the app to V2
Summary of the topics that will be covered in this guide:
Webhooks handle incoming messages from people who respond to you on WhatsApp including text, location, and media such as pictures and documents as well as the status of the messages you've sent. They are an important channel to deliver, both timely notifications as well as out-of-band errors, and it is thus highly recommended you set one in the application settings.
Inbound messages sent by customers to your WhatsApp Business Phone Number will be sent to your Webhook i.e. customer sends a text message or media attachment on WhatsApp the Gupshup platform registers the event and immediately sends a notification (HTTP POST request) to the Webhook specified in your application settings. Some important notes on Webhook:
1. The webhook should return HTTP_SUCCESS (code: 2xx) with an empty response. Failing to do so within 10 Seconds, we will consider that the notification has failed and we will try again after a short delay.
2. Your webhook should process inbound messages & events asynchronous but acknowledge its reception synchronously & immediately. Best acknowledge time should be less than 100 millisecond, it is understood that there can be a network delay. Hence, recommended is within 500-1000 millisecond. The Greater your response time, the more delayed inbound messages and events you will receive each time.
3. The webhook should accept HTTP header: User-Agent
4. The webhook should accept user event: sandbox-start
5. The webhook should have public access and if for security reason you want to keep it private you are required to whitelist Gupshup's inbound request IPs - please contact devsupport@gupshup.io to get these IPs
Refer below image to locate set Webhook/Callback option in the app's settings. If the callback URL toggle is OFF. You can see incoming messages under Inbound Messages | Events field. Messages and events logged under this field are stored temporary meaning if you refresh the page the logs will be cleared.
There are 5 types of inbound notifications that may be delivered to your webhook, they are:
The above notification types can be categorized in two - Events and Inbound Messages, let us first get familiar with the inbound notification structure:
Inbound payload content type
Content-type
|
application/json |
Parameters/Properties common to all incoming notification
{
"app": "DemoApp",
"timestamp": 1580227766370,
"version": 2,
"type": "user-event"|"template-event"|"message-event"|"message",
"payload": << This varies according to 'type' property value >>
}
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
The name of the Gupshup app to which the customer has sent a message on WhatsApp |
DemoApp |
|
|
string |
The time in unix timestamp when the message sent by the customer was received by Gupshup |
1584898839530 |
|
|
string |
Callback payload version |
2 |
|
|
string |
Inbound events |
user-event |
|
|
object |
The payload object contains information of respective notification type. |
For example: user-event |
In this section we will understand:
1. user-event : These are generated by our platform when some event occurs. For example, the following system events are received when:
- A callback URL is set for an app or while using the proxy command to invoke your app on Gupshup Proxy bot phone number(+917834811114) for testing the app
- An end-user gives consent(Opt-in) to receive notification from a business phone number.
{
"app":"DemoApp",
"timestamp":1580142086287,
"version":2,
"type":"user-event",
"payload":{
"phone":"callbackSetPhone"|"918x98xx21x4",
"type":"sandbox-start"|"opted-in"|"opted-out"
}
}
The payload object
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
The phone number of the customer who has sent the message on WhatsApp, number is in E.164 format |
918x98xx21x4 |
|
|
string |
The type of user-event received on your webhook |
Described in brief below |
The user-event type:
| Type | Description | Sample |
|---|---|---|
| sandbox-start | This event is received when the app is in Sandbox mode and you have set a callback URL |
Content type: application/json{"app":"DemoApp","timestamp":1580142086287,"version":2,"type":"user-event","payload":{"phone":"callbackSetPhone","type":"sandbox-start"}} |
| sandbox-start |
This event is received when the app is in Sandbox mode and you have used Gupshup proxy bot to invoke your App using command Proxy {{App_Name}}
|
Content type: application/json{"app":"DemoApp","timestamp":1580227393386,"version":2,"type":"user-event","payload":{"phone":"918x98xx21x4","type":"sandbox-start"}} |
| opted-in | This event is received when an end user opt-in to receive notification from a business |
Content type: application/json{"app":"DemoApp","timestamp":1584541505908,"version":2,"type":"user-event","payload":{"phone":918x98xx21x4,"type":"opted-in"}} |
| opted-out | This event is received when an end user opt-out from receiving notification from a business |
Content type: application/json{"app":"DemoApp","timestamp":1584541505908,"version":2,"type":"user-event","payload":{"phone":918x98xx21x4,"type":"opted-out"}} |
2. system-events : These are generated by our platform when some event occurs. You can choose to receive these events on your callback URL from the settings in app dashbaord. For example, the following system events are received when:
- A system event of type template is received when the status of template is updated. For example, a submitted template has been approved or rejected.
- A system event of type account is received. For example, when the status of the submitted Phone Number or Display Name for a WABA is updated.
The system events are categorized into two types:
Template-event
{
"app": "jeet20",
"timestamp": 1636986446609,
"version": 2,
"type": "template-event",
"payload":{ "id": "4dacef15-6c04-12db-b393-6190ac567eff", "status": "REJECTED/APPROVED/DELETED/DISABLED", "elementName": "abcd", "languageCode": "en_US", "rejectedReason": "INAVLID_FORMAT" }
}
The payload object
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
It is the unique identifier for a template on the Gupshup platform. You can find the template ID using the API Get template list |
4dacef15-6c04-12db-b393-6190ac567eff |
|
|
string |
The updated status of a template. Possible values are |
|
|
|
string |
The unique name for a template set at during template creation. The |
|
|
|
string |
The langauge of the template. You can refer to the language code and the associated langauge here. |
|
|
|
string |
The reason for template rejection. |
|
Account-events
Account events are received when an event occurs in a specific WABA. For example, when a WhatsApp business policy is voilated by a WABA, or if the messaging tier limit of a WABA is updated.
The account-event types, and their payload objects are as follows:
| Type | Description | Sample |
|---|---|---|
review-event |
This event is received when the submitted WABA is approved or rejected. |
|
status-event |
This event is received when the status of the WABA has changed. |
|
pndn-event |
This event is received when the status of the submitted Phone number/Display Name is updated. |
|
tier-event |
This events notifies you when the quality-related status of a phone number has an update. |
|
3. message-event : These events states the status of the message sent using the send message API to WhatsApp API client(which essentially send out message to the customer). The WhatsApp Business API client will send notifications to inform you of the status of the messages between you and users. When a message is sent successfully, you will receive a notification when the message is sent, delivered, and read. The order of these notifications in your app may not reflect the actual timing of the message status. View the timestamp to determine the timing, if necessary. The notifications you may receive are:
{
"app":"DemoAPI",
"timestamp":1580546677791,
"version":2,
"type":"message-event",
"payload":{
"id":"59f8db90-c37e-4408-90ab-cc54ef8246ad"(Gupshup Message ID)|"gBEGkYaYVSEEAgnZxQ3JmKK6Wvg" (WhatsApp Message ID)
"gsId": "ee4a68a0-1203-4c85-8dc3-49d0b3226a35" (Gupshup Message ID - This property is only applicable for DLR events)
"type":"enqueued"|"failed"|"sent"|"delivered"|"read",
"destination":"91XX985XX10X",
"payload": << This varies according to 'type' property value >>;
}
}
The payload object
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
This is Gupshup Message Id for message-event types: |
59f8db90-c37e-4408-90ab-cc54ef8246ad |
|
|
string |
This is Gupshup Message Id and only present for message-event types: DLR events( |
59f8db90-c37e-4408-90ab-cc54ef8246ad |
|
|
string |
The type of message-event received on your webhook |
Described in brief below |
message-event types
| Type | Description | Sample | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| enqueued |
Message is successfully sent to WhatsApp Business API client Payload object:
|
Content type: application/json{"app":"DemoAPI","timestamp":1580546677791,"version":2,"type":"message-event","payload":{"id":"59f8db90-c37e-4408-90ab-cc54ef8246ad","type":"enqueued","destination":"91XX985XX10X","payload":{"whatsappMessageId":"gBEGkYaYVSEEAgkD7bRi9syGnBk","type":"session"}}} |
||||||||||||||||||||||||||||
| failed |
Message sent by your business failed to send. Reason for failure will be included in the callback Payload object:
|
Content type: application/json{"app":"DemoAPI","timestamp":1580311136040,"version":2,"type":"message-event","payload":{"id":"ee4a68a0-1203-4c85-8dc3-49d0b3226a35","type":"failed","destination":"918x98xx21x4","payload":{"code":1008,"reason":"User is not Opted in and Inactive"}}} |
||||||||||||||||||||||||||||
| sent |
Message was sent to the end-user. Payload object:
|
Content type: application/json{"app":"DemoAPI","timestamp":1580546677791,"version":2,"type":"message-event","payload":{"id":"59f8db90-c37e-4408-90ab-cc54ef8246ad","gsId":"ee4a68a0-1203-4c85-8dc3-49d0b3226a35","type":"sent","destination":"91XX985XX10X","payload":{"ts":1585344475},"conversation":{"id":"532b57b5f6e63595ccd74c6010e5c5c7","expiresAt":1518780636,"type":"FEP/UIC/BIC"},"pricing":{"policy":"CBP/NBP","category":"FEP/UIC/BIC"}}} |
||||||||||||||||||||||||||||
| delivered |
Message sent by your business was delivered to the user's device. Payload object:
|
Content type: application/json{"app":"DemoAPI","timestamp":1585344476683,"version":2,"type":"message-event","payload":{"id":"gBEGkYaYVSEEAgnZxQ3JmKK6Wvg","gsId": "ee4a68a0-1203-4c85-8dc3-49d0b3226a35","type":"delivered","destination":"918x98xx21x4","payload":{"ts":1585344476}}} |
||||||||||||||||||||||||||||
| read |
Message sent by your business was read by the user. Read notifications will only be available for those users that have read receipts enabled. For users that do not have it enabled, you will only receive the delivered notification. For a status to be read, it must have been delivered. In some scenarios, such as when a user is in the chat screen and a message arrives, the message is delivered and read almost simultaneously. In this or other similar scenarios, the delivered notification will not be sent back, as it is implied with that a message has been delivered if it has been read. Payload object:
|
Content type: application/json{"app":"DemoAPI","timestamp":1585344602933,"version":2,"type":"message-event","payload":{"id":"gBEGkYaYVSEEAgnZxQ3JmKK6Wvg","gsId": "ee4a68a0-1203-4c85-8dc3-49d0b3226a35","type":"read","destination":"918x98xx21x4","payload":{"ts":1585344602}}} |
||||||||||||||||||||||||||||
| mistmatch |
This event is only triggered when the destination number provided in the API request does not match the WhatsApp ID. Learn more about the mismatch event here. The mismatch event does not require a subscription and will help you manage user conversations more effectively.
|
Content type: application/json{"app":"DemoApp","timestamp":1638607221146,"version":2,"type":"message-event","payload":{"id":"499a3642-5d41-477f-8bdc-58985e9c6996","type":"mismatch","destination":"5535987654321","payload":{"phone":"553587654321","wa_id":"5593587654321"}}} |
Message failure codes and their reasons:
| Code | Reason |
|---|---|
| 1001 | Last Mapped Bot Details And Sender Details Mismatch |
| 1002 | Number Does Not Exists On WhatsApp |
| 1003 | Unable To Send Message | Check your wallet balance |
| 1004 | Message sending failed as user is inactive for session message and template messaging is disabled |
| 1005 | Message sending failed as user is inactive for session message and template did not match |
| 1006 | Message sending failed as user is inactive for session message and not opted in for template message |
| 1007 | Message sending failed as user is inactive for session message, not opted in for template message and template did not match |
| 1008 | User is not Opted in and Inactive |
| 1010 | Invalid Media Url |
| 1011 | Invalid Media Size |
To know more about WhatsApp Business API Client Error Codes refer here
4. billing-event : The event: billing-event is triggered only when a conversation is billable. For free conversations you will not receive a billing-event.
{
"app": "DemoAPI",
"timestamp":1580546677791,
"version":2,
"type": "billing-event",
"payload":{
"deductions":{
"type": "FEP/UIC/BIC",
"model": "NBP/CBP",
"source": "whatsapp"
},
"references":{
"id":"59f8db90c37e-4408-90ab-cc54ef8246ad",
"gsId":"ee4a68a0-1203-4c85-8dc3-49d0b3226a35",
"conversationId":"532b57b5f6e63595ccd74c6010e5c5c7",
"destination":"91XX985XX10X"
}
}
}
Deductions object description
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
The type of conversation. Possible values:
|
BIC |
|
|
string |
The pricing policy model applied for this message. Possible values:
|
CBP |
|
|
string |
Origin source of the conversation |
|
References object description
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
Unique WhatsApp identifier for a message |
59f8db90c37e-4408-90ab-cc54ef8246ad |
|
|
string |
Unique Gupshup identifier for a message |
ee4a68a0-1203-4c85-8dc3-49d0b3226a35 |
|
|
string |
Unique identifier for a conversation |
532b57b5f6e63595ccd74c6010e5c5c7 |
|
|
string |
Phone number of the user engaged in the conversation. |
91XX985XX10X |
In this section we will understand event: message that you receive on your callback URL. This event states the type of message payload received on your callback URL when a customer sends a message to the registered WhatsApp Business API phone number.
Headers
Content-type
|
application/json |
Parameters/Properties common to all incoming message
{
"app": "DemoApp",
"timestamp": 1580227766370,
"version": 2,
"type": "message",
"payload": {
"id": "ABEGkYaYVSEEAhAL3SLAWwHKeKrt6s3FKB0c",
"source": "918x98xx21x4",
"type": "text"|"image"|"file"|"audio"|"video"|"contact"|"location"|"button_reply"|"list_reply",
"payload": {
//Varies according to the type of payload.
},
"sender": {
"phone": "918x98xx21x4",
"name": "Smit",
"country_code": "91",
"dial_code": "8x98xx21x4"
},
"context": {
"id": "gBEGkYaYVSEEAgnPFrOLcjkFjL8",
"gsId": "9b71295f-f7af-4c1f-b2b4-31b4a4867bad"
}
}
}
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
The name of the Gupshup app to which the customer has sent a message on WhatsApp |
DemoAPI |
|
|
string |
The time in unix timestamp when the message sent by the customer was received by Gupshup |
1584898839530 |
|
|
string |
Callback payload version |
2 |
|
|
string |
Inbound events |
|
|
|
object |
It contains the details of inbound message: |
See payload object for more information. |
|
|
object |
It contains the details of the message sender/end-user/customer: |
See sender object for more information. |
|
|
object |
Optional. |
See context object for more information. |
The payload object
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
The unique WhatsApp message identifier for the inbound message |
ABEGkYaYVSEEAhAt2MgAKjL1qGe88OKyMQfM |
|
|
string |
The phone number of the customer who has sent the message on WhatsApp, number is in E.164 format |
918x98xx21x4 |
|
|
string |
The type of message received from the end user. Depending on 'type', the relevant message object will be received as part of the payload. |
|
|
|
object |
The payload object contains the inbound message content sent by the customer |
See types of incoming message received documentation below |
The sender object
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
The phone number of the end user who has sent the message on WhatsApp, number is in E.164 format |
918x98xx21x4 |
|
|
string |
Name of the end user who has sent the message on WhatsApp |
Smit |
|
|
string |
Get the sender country code |
91 |
|
|
string |
Get the sender dial code |
8x98xx21x4 |
The context object
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
The unique WhatsApp message identifier for the inbound message |
gBEGkYaYVSEEAgnPFrOLcjkFjL8 |
|
|
string |
The unique Gupshup message identifier for the inbound message |
9b71295f-f7af-4c1f-b2b4-31b4a4867bad |
Let us see one by one the types of incoming message received on the Callback URL:
Below is a sample payload when a customer sends a text message on WhatsApp to your business number.
| Headers | Content type: application/json |
||||||||
| Inbound Body | | ||||||||
| The text payload |
|
Users can respond to a specific message in WhatsApp. For the business to understand the context of a message reply, we include the context object. This context object provides the Gupshup message id(property: gsId) of the message to which the customer replied and the WhatsApp message id(property: id) of the original message.
The following is an example of an inbound message that is a reply to a message that business has sent.
| Headers |
Content type: application/json
|
||||||||
| Inbound Body |
| ||||||||
| The text payload |
|
When your customer clicks on a quick reply button, a response is sent to your Webhook URL. Below is an example of the callback format.
For the business to understand the context of a message reply, we include the context object. This context object provides the Gupshup message id(property: gsId) of the message to which the customer replied and the WhatsApp message id(property: id) of the original message. In addition to this payload object provides the button text which the user clicked.
| Headers |
Content type: application/json
|
||||||||||||
| Inbound Body |
| ||||||||||||
| The text payload |
|
Media
When a message with media (image | document | audio | video | sticker) is received, the WhatsApp Business API client will download the media. Once the media is downloaded, a notification is sent to our platform and we which is to your Webhook. This message contains information that identifies the media object and enables you to find and download the object.
Common media payload
| Key | Type | Description | Example |
|---|---|---|---|
|
|
string |
Optional. Only present if specified. |
View Account Balance |
|
|
string |
Filename on the sender's device. |
152445128_APR-20.pdf |
|
|
string |
Media download link |
https://filemanager.gupshup.io/fm/wamedia/Jeet20/68f1e51b-ac53-4dfb-b970-7b9031ed1d3c |
|
|
string |
Mime type of the media. |
application/pdf |
|
|
string |
Media download URL expiry Timestamp |
1624957005482 |
Below is a sample payload when a customer sends an image along with a caption on WhatsApp to your business number. Caption is only present if specified.
| Headers |
Content type: application/json
|
| Inbound Body |
|
Below is a sample payload when a customer sends an audio file or voice message on WhatsApp to your business phone number. In case of voice message the content type is always: audio/ogg; codecs=opus
| Headers |
Content type: application/json
|
| Inbound Body |
|
Below is a sample payload when a customer sends a video file along with a caption on WhatsApp to your business number.
| Headers |
Content type: application/json
|
| Inbound Body |
|
Below is a sample payload when a customer sends a document along with a caption on WhatsApp to your business number. Caption is only present if specified.
| Headers |
Content type: application/json
|
| Inbound Body |
|
Below is a sample payload when a customer sends a sticker on WhatsApp to your business number.
| Headers |
Content type: application/json
|
| Inbound Body |
|
Below is a sample payload when a customer select and submit an item from the list message on WhatsApp to your business number.
| Headers |
Content type: application/json
|
||||||||||||||||||||||||
| Inbound Body |
| ||||||||||||||||||||||||
| List reply payload |
|
Below is a sample payload when a customer select an button from the quick reply message on WhatsApp to your business number.
| Headers |
Content type: application/json
|
||||||||||||||||
| Inbound Body |
| ||||||||||||||||
| List reply payload |
|
Below is a sample payload when a customer shares their location on WhatsApp to your business number.
Please note that Live Location is not a supported message type on WhatsApp Business at the moment.
| Headers |
Content type: application/json
|
||||||||||||
| Inbound Body |
| ||||||||||||
| The location payload |
|
Below is a sample payload when a customer shares a contact card to your business number.
| Headers |
Content type: application/json
|
||||||||||||||||||||||||||||||||||||
| Inbound Body |
| ||||||||||||||||||||||||||||||||||||
| The Contact payload |
|
Included in notifications when a user clicks on an ad that clicks to WhatsApp and sends a message to the business. This object has the ad's information.
| Headers |
Content type: application/json
|
||||||||||||||||||||||||||||
| Inbound Body |
| ||||||||||||||||||||||||||||
| The referral payload |
|
This guide teaches you how to send a session message to a customer using the send message API. Currently, this type of messaging can only be done within 24 hours of the last message sent by the user. If you try to send a message outside the 24-hour window, you get a failure event on your webhook. To understand the User states on our platform, please refer to this article, this will help you to use the API more effectively.
Let us understand the API specification/signature i.e the API Endpoint, Headers, Request body and its Response in details:
To send a message on WhatsApp, the API request is made to the endpoint:
https://api.gupshup.io/sm/api/v1/msg
Sample API Request
curl --location --request POST 'https://api.gupshup.io/sm/api/v1/msg' \
--header 'Cache-Control: no-cache' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a' \
--data-urlencode 'channel=whatsapp' \
--data-urlencode 'source=917834811114' \
--data-urlencode 'destination=918x98xx21x4' \
--data-urlencode 'message={"type": "text","text": "Hi John, how are you?"}' \
--data-urlencode 'src.name=DemoApp' \
--data-urlencode 'disablePreview=false'
Headers
Content-type
|
application/x-www-form-urlencoded |
apikey
|
Your API key here |
Request Body
| Key | Type | Description | Example | Required |
|---|---|---|---|---|
|
|
string |
The channel on which this message must be sent. |
|
Y |
|
|
string |
The phone number of the recipient to whom message is being sent. |
918x98xx21x4 |
Y |
|
|
string |
The WhatsApp Business phone number from whom message will be sent. This number must be the verified number linked to your Gupshup app. |
917834811114 |
Y |
|
|
object |
WhatsApp template message that you want to send to your customers |
See message object documentation below |
Y |
|
|
string |
Your WhatsApp app name |
DemoApp |
Y - for sandbox apps |
|
|
boolean |
By default, the mobile WhatsApp application recognizes URLs and makes them clickable. By default, URL preview is enabled on the platform i.e disablePreview" is |
true |
N |
Common message object parameters
| Key | Type | Description | Example | Required |
|---|---|---|---|---|
|
|
string |
The type of message to be sent to the customer. Depending on 'type', the relevant parameters must be sent as part of the message object.
|
|
Y |
|
|
string |
The hosted URL of the file / audio / video attachment |
https://www.buildquickbots.com/whatsapp/media/sample/audio/sample01.mp3 |
Y |
|
|
string |
Add caption to media messages, applicable to media type = |
Media caption text |
N |
Below is a sample payload when sending a text message on WhatsApp.
- A text message can be a max of 4096 characters long.
- To include a URL preview in the message and make sure the URL begins with http:// or https://.
- A URL to be previewed: hostname is required, IP addresses will not be considered.
- If a text message has multiple URL, the first URL will be only previewed
| API URL | https://api.gupshup.io/sm/api/v1/msg | ||||||||||
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
||||||||||
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" : { "type": "text", "text": "Hi John, how are you?" } |
||||||||||
| Text message object description |
|
WhatsApp supports some formatting in text messages. To format all or part of a message, use these formatting symbols:
| Formatting | Symbol | Example | How message displays on WhatsApp |
|---|---|---|---|
| Bold | Asterisk (*) | Your total is *$10.50*. | Your total is $10.50. |
| Italics | Underscore (_) | Welcome to _WhatsApp_! | Welcome to WhatsApp! |
|
|
Tilde (~) | This is ~better~ best! | This is |
Code
|
Three backticks (```) | ```print 'Hello World';``` | print 'Hello World'; |
Emoji are also supported. List of supported emoji are at https://emojipedia.org/whatsapp/ . Copy the emoji symbol in the text message when sending through API.
Media
Below is a sample payload when sending an image on WhatsApp.
- Supported Content-Types: image/jpeg, image/png
- maximum file size: 5 MB
| API URL | https://api.gupshup.io/sm/api/v1/msg | |||||||||||||||
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
|||||||||||||||
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" : { "type": "image", "originalUrl": "https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg", "previewUrl": "https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg", "caption":"Sample image" } |
|||||||||||||||
| Image message object description |
Images taller than 1.91:1 aspect ratio are cropped vertically. To communicate the crux in such images, plan to present the most important information at the center of the image.
|
Below is a sample payload when sending a document / file on WhatsApp.
- Supported Content-Types: Any valid MIME-type
- maximum file size: 100 MB
| API URL | https://api.gupshup.io/sm/api/v1/msg | ||||||||||
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
||||||||||
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" : { "type": "file", "url": "https://www.buildquickbots.com/whatsapp/media/sample/pdf/sample01.pdf", "filename": "Sample funtional resume" } |
||||||||||
| File message object description |
|
Below is a sample payload when sending an audio file on WhatsApp.
- Supported Content-Types: audio/aac, audio/mp4, audio/amr, audio/mpeg,
audio/ogg; codecs=opus. Note: The base audio/ogg type is not supported.
- maximum file size: 16 MB
| API URL | https://api.gupshup.io/sm/api/v1/msg |
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" : { "type": "audio", "url": "https://www.buildquickbots.com/whatsapp/media/sample/audio/sample01.mp3" } |
Below is a sample payload when sending a video on WhatsApp.
- Supported Content-Types: video/mp4, video/3gpp. Note: Only H.264 video codec and AAC audio codec is supported.
- maximum file size: 16 MB
| API URL | https://api.gupshup.io/sm/api/v1/msg |
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" : { "type": "video", "url":"https://www.buildquickbots.com/whatsapp/media/sample/video/sample01.mp4", "caption":"Sample video" } |
Below is a sample payload when sending a sticker on WhatsApp.
- Each sticker has a transparent background.
- Stickers must be exactly 512x512 pixels.
- Each sticker must be less than 100 KB.
| API URL | https://api.gupshup.io/sm/api/v1/msg |
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" : { "type": "sticker", "url":"http://www.buildquickbots.com/whatsapp/stickers/SampleSticker01.webp" } |
Messages including a menu of up to 10 options. This type of message offers a simpler and more consistent way for users to make a selection when interacting with a business. Below is a sample payload for sending list messages to your end-user.
| API URL | https://api.gupshup.io/sm/api/v1/msg | ||||||||||||||||||||||||||||||
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
||||||||||||||||||||||||||||||
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" : { "type": "list", "title": "title text", "body": "body text", "msgid": "list1", "globalButtons": [ { "type": "text", "title": "Global button" } ], "items": [ { "title": "first Section", "subtitle": "first Subtitle", "options": [ { "type": "text", "title": "section 1 row 1", "description": "first row of first section description", "postbackText": "section 1 row 1 postback payload" }, { "type": "text", "title": "section 1 row 2", "description": "second row of first section description", "postbackText": "section 1 row 2 postback payload" }, { "type": "text", "title": "section 1 row 3", "description": "third row of first section description", "postbackText": "section 1 row 3 postback payload" } ] }, { "title": "second section", "subtitle": "second Subtitle", "options": [ { "type": "text", "title": "section 2 row 1", "description": "first row of second section description", "postbackText": "section 1 row 3 postback payload" } ] } ] } |
||||||||||||||||||||||||||||||
| List message object description |
|
||||||||||||||||||||||||||||||
| globalButtons array description |
|
||||||||||||||||||||||||||||||
| items array description |
|
This type of message offers a quicker way for users to make a selection from a menu when interacting with a business. Reply buttons have the same user experience as interactive templates with buttons.
Below is a sample payload when sending Quick replies message to end-users on WhatsApp.
| API URL | https://api.gupshup.io/sm/api/v1/msg | |||||||||||||||
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
|||||||||||||||
| Request Body |
|
|||||||||||||||
Quick replies content object description
|
Quick replies message body supports - "text" | "image" | "video" | "document". The content object is used to define the Quick replies message body payload. In addition to this we have caption property which is common in the content object and it indicates the footer. The header is an addition to Quick reply messages.
- For type: text, The Header is optional, maximum characters allowed - 20.
- The parameter type, that represents the type of the message and the parameter text, that represents the body of the message are mandatory.
- The Caption which is the footer, is optional, maximum characters allowed - 60.
|
|||||||||||||||
Quick replies options array description
|
A Quick reply Message including up to 3 options
|
Below is a sample payload for sending static location to your end-user.
| API URL | https://api.gupshup.io/sm/api/v1/msg |
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" : { "type": "location", "longitude": 43.43, "latitude": 33.34, "name": "Name of the location", "address": "Postal address" } |
Below is a sample payload for share a contact card with your end-user.
| API URL | https://api.gupshup.io/sm/api/v1/msg |
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" :{ "type": "contact", "contact": { "addresses": [ { "city": "Menlo Park", "country": "United States", "countryCode": "us", "state": "CA", "street": "1 Hacker Way", "type": "HOME", "zip": "94025" }, { "city": "Menlo Park", "country": "United States", "countryCode": "us", "state": "CA", "street": "200 Jefferson Dr", "type": "WORK", "zip": "94025" } ], "birthday": "2012-08-18", "emails": [ { "email": "test@fb.com", "type": "WORK" [ }, { "email": "test@whatsapp.com", "type": "WORK" ], "name": { "firstName": "John", "formattedName": "John Smith", "lastName": "Smith" }, "org": { "company": "WhatsApp", "department": "Design", "title": "Manager" }, "phones": [ { "phone": "+1 (940) 555-1234", "type": "HOME" }, { "phone": "+1 (650) 555-1234", "type": "WORK", "wa_id": "16505551234" } }, "urls": [ { "url": "https://www.facebook.com", "type": "WORK" } ] } } |
The send message API request received by our platform are processed asynchronously hence, you will always get a HTTP_SUCCESS(200 to 299) response range if the API request was made correctly. API response includes an object with a Gupshup message identifier and status as submitted and your webhook will receive message-event which states that your submitted message to WhatsApp API client(which actually sends message to the customer) is enqueued or failed.
{"status":"submitted","messageId":"ee4a68a0-1203-4c85-8dc3-49d0b3226a35"}
The Gupshup message identifier i.e the messageId in the API response, will help to track the messages via the message events i.e. “enqueued”|“failed”|“sent”|“delivered”|“read” received on the webhook.
Template messaging enables a business to send out notification to their customers outside 24 hours window. WhatsApp mandates that notification should be only send to the users who has given consent to receive messages from the business. Keeping this as a default behavior on our platform, template messages can be only sent to users who are marked opt-in. To Mark a user as opt-in use Mark User Opt-in API
We have been receiving queries from our platform users that they are facing issues to send template messages to their end-user. On analysis we found these issues were mostly related to message mismatch with that of the approved template. Hence, a new template messaging API was released to reduce such errors.
This doesn't indicates that the generic API to send both session and template message is deprecated for template messaging, one can still make use of it. Below is the traditional template messaging API:
| API URL | https://api.gupshup.io/sm/api/v1/msg |
| Request Headers |
Content-Type: application/x-www-form-urlencoded apikey: {{Your API Key}} |
| Request Body |
"channel" : "whatsapp", "source" : "917384811114", "destination" : "918x98xx21x4" "src.name":"DemoApp" "message" : { "type": "text", "text": "Hi John, your order is confirmed and will be delivered to you by 15 Feb" } |
Unlike above API, were you are required to send the entire message body with text markers/placeholders. The new template messaging API only takes template id and placeholders value.
Let us understand the API specification/signature i.e the API Endpoint, Headers, Request body and its Response in details:
To send a message on WhatsApp, the API request is made to this endpoint:
http://api.gupshup.io/sm/api/v1/template/msg
Sample API Request
curl --location --request POST 'http://api.gupshup.io/sm/api/v1/template/msg' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'source=917834811114' \
--data-urlencode 'destination=918x98xx21x4' \
--data-urlencode 'template={"id": "c6aecef6-bcb0-4fb1-8100-28c094e3bc6b","params": ["Agent","Local Address","Tracking code"]}'
Headers
Content-type
|
application/x-www-form-urlencoded |
apikey
|
Your account apikey |
Request Body
| Key | Type | Description | Example | Required |
|---|---|---|---|---|
|
|
string |
Your register business Phone number (with country code) registered for WhatsApp Business API |
917834811114 |
Y |
|
|
string |
Destination phone number with country code to whom the Message template has to be sent. |
918x98xx21x4 |
Y |
|
|
Object |
This Object has 2 properties: |
Your approved template is: |
Y |
|
|
object |
This property is used only if you want to send a media - Image, Video, Document(.pdf) and location. |
Image:
|
N |
The send message API request received by our platform are processed asynchronously hence, you will always get a HTTP_SUCCESS(200 to 299) response range if the API request was made correctly. API response includes an object with a Gupshup message identifier and status as submitted and your webhook will receive message-event which states that your submitted message to WhatsApp API client(which actually sends message to the customer) is enqueued or failed.
{
"messageId": "bf70b8c4-a5b9-4acd-b108-512ce704f4dc",
"status": "submitted"
}
The Gupshup message identifier i.e the messageId in the API response, will help to track the messages via the message events i.e. “enqueued”|“failed”|“sent”|“delivered”|“read” received on the webhook.
Sample API request for each message types. These examples are for illustrative purposes only and cannot be used. You must create your own samples and have them approved in order to test.
curl --location --request POST 'http://api.gupshup.io/sm/api/v1/template/msg' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'source=917834811114' \
--data-urlencode 'destination=918x98xx21x4' \
--data-urlencode 'template={"id": "c6aecef6-bcb0-4fb1-8100-28c094e3bc6b","params": ["Agent","Local Address","Tracking code"]}'
curl --location --request POST 'http://api.gupshup.io/sm/api/v1/template/msg' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'source=917834811114' \
--data-urlencode 'destination=918x98xx21x4' \
--data-urlencode 'template={"id": "c6aecef6-bcb0-4fb1-8100-28c094e3bc6b","params": ["Agent","Local Address","Tracking code"]}' \
--data-urlencode 'message={"type":"image","image":{"link":"https://images.pexels.com/photos/248797/pexels-photo-248797.jpeg"}}'
curl --location --request POST 'http://api.gupshup.io/sm/api/v1/template/msg' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'source=917834811114' \
--data-urlencode 'destination=918x98xx21x4' \
--data-urlencode 'template={"id": "c6aecef6-bcb0-4fb1-8100-28c094e3bc6b","params": ["Agent","Local Address","Tracking code"]}' \
--data-urlencode 'message={"type":"video","video":{"link": "https://www.buildquickbots.com/whatsapp/media/sample/video/sample01.mp4"}}'
curl --location --request POST 'http://api.gupshup.io/sm/api/v1/template/msg' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'source=917834811114' \
--data-urlencode 'destination=918x98xx21x4' \
--data-urlencode 'template={"id": "c6aecef6-bcb0-4fb1-8100-28c094e3bc6b","params": ["Agent","Local Address","Tracking code"]}' \
--data-urlencode 'message={"type":"document","document":{"link":"https://www.buildquickbots.com/whatsapp/media/sample/pdf/sample01.pdf","filename": "Sample funtional resume"}}'
curl --location --request POST 'http://api.gupshup.io/sm/api/v1/template/msg' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'source=917834811114' \
--data-urlencode 'destination=918x98xx21x4' \
--data-urlencode 'template={"id": "c6aecef6-bcb0-4fb1-8100-28c094e3bc6b","params": ["Agent","Local Address","Tracking code"]}' \
--data-urlencode 'message={"type":"location","location":{"longitude":"","latitude":""}}'
For an approved media interactive template like this:
Hi {{1}}, Please find the attached bill. For more details please visit our website. | [Visit Website,https://www.gupshup.io/developer/{{1}}]
Where we have placeholder in message body as well as in call to action button, the API request can be:
curl --location --request POST 'http://api.gupshup.io/sm/api/v1/template/msg' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'source=917834811114' \
--data-urlencode 'destination=918x98xx21x4' \
--data-urlencode 'template={"id": "c49ee21d-4d39-452d-a6c1-25b7615e01e4","params": ["John","docs/bot-platform/guide/whatsapp-api-documentation"]}' \
--data-urlencode 'message={"type":"document","document":{"link":"https://www.buildquickbots.com/whatsapp/media/sample/pdf/sample01.pdf","filename": "Sample funtional resume"}}'
For an approved interactive template like this:
You can now view your Account Balance or Mini statement for Account ending with {{1}} simply by selecting one of the options below. | [View Account Balance] | [View Mini Statement]
Where we have placeholder in message body and just postback button, the request will be:
curl --location --request POST 'http://api.gupshup.io/sm/api/v1/template/msg' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'source=917834811114' \
--data-urlencode 'destination=918x98xx21x4' \
--data-urlencode 'template={"id": "c6aecef6-bcb0-4fb1-8100-28c094e3bc6b","params": ["12323XXXX"]}'
This API will help you get a list of all the users interacted with your business phone number and their opt-in status:
Curl request
curl --location --request GET 'https://api.gupshup.io/sm/api/v1/users/{{App_Name}}' \
--header 'apikey: {{Gupshup_Account_APIKey}}'
{
"status": "success",
"users": [
{
"countryCode": "91",
"lastMessageTimeStamp": 1585593959851,
"optinSource": "URL",
"optinStatus": "OPT_IN",
"optinTimeStamp": 1585504095053,
"phoneCode": "8x98xx21x4"
}
]
}
curl --location --request POST 'https://api.gupshup.io/sm/api/v1/app/opt/in/{{App_Name}}' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'apikey: {{Gupshup_Account_APIKey}}' \
--data-urlencode 'user={{User_Mobile_Number}}'
User_Mobile_Number value is a valid phone number with country code. Example: 918x98xx21x4
202
curl --location --request POST 'https://api.gupshup.io/sm/api/v1/app/opt/out/{{App_Name}}' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'apikey: {{Gupshup_Account_APIKey}}' \
--data-urlencode 'user={{User_Mobile_Number}}'
User_Mobile_Number value is a valid phone number with country code. Example: 918x98xx21x4
202
Let us understand this API:
API Endpoint
https://api.gupshup.io/sm/api/v1/template/list/:AppName
Headers
apikey
|
Your account apikey |
API Request
curl --location --request GET 'https://api.gupshup.io/sm/api/v1/template/list/:AppName' \
--header 'apikey: 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a'
API Response
HTTP response code: 200
{
"status": "success",
"templates": [
{
"category": "ACCOUNT_UPDATE",
"createdOn": 1580978917761,
"data": "{{1}} debited with {{2}} on {{3}} for {{4}}.",
"elementName": "common_transaction_2",
"id": "05c82e91-05e5-4d35-b280-2d3d20feda38",
"languageCode": "en_US",
"languagePolicy": "deterministic",
"master": false,
"meta": "{\"example\":\"[Your Bank ac ending with 1245] debited with [Rs. 10000] on [11-Jan-2011] for [ATM cash withdrawal].\"}",
"modifiedOn": 1581966008618,
"status": "APPROVED",
"templateType": "TEXT",
"vertical": "TRANSACTIONS"
},
{
"category": "ISSUE_RESOLUTION",
"createdOn": 1593540550247,
"data": "Hola! Soy {{1}} de Ofisí, recibimos una llamada suya, ¿en qué puedo ayudarle?",
"elementName": "recibimos_llamada",
"id": "072867eb-dd12-46f5-950d-2dd03a7677e5",
"languageCode": "es_MX",
"languagePolicy": "deterministic",
"master": true,
"meta": "{\"example\":\"Hola! Soy [Leon] de Ofisí, recibimos una llamada suya, ¿en qué puedo ayudarle?\"}",
"modifiedOn": 1593627001825,
"status": "APPROVED",
"templateType": "TEXT",
"vertical": "ISSUE RESOLUTION"
}
]
}
Property id is the template id.
curl --location --request GET 'https://api.gupshup.io/sm/api/v2/wallet/balance' \
--header 'apikey: {{Gupshup Account apikey}}'
200
{
"balance": 1313.7675,
"status": "success"
}