WhatsApp Access API documentation API docs now available in: Portuguese, German, Russian and Spanish


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:

  1. Set Webhook/Callback URL
  2. Inbound Message and Events
  3. Outbound Message
  4. Miscellaneous APIs

Set Webhook/Callback URL


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

In case you are facing issues to set Webhook please refer to this FAQ to know the procedure to troubleshoot.

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.
Sandbox Image


Inbound Message and Events


There are 5 types of inbound notifications that may be delivered to your webhook, they are:

  1. user-event
  2. system-event
  3. message-event
  4. billing-event
  5. message


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

app

string

The name of the Gupshup app to which the customer has sent a message on WhatsApp

DemoApp

timestamp

string

The time in unix timestamp when the message sent by the customer was received by Gupshup

1584898839530

version

string

Callback payload version

2

type

string

Inbound events
user-event|message-event|message

user-event

payload

object

The payload object contains information of respective notification type.
Each payload is described in brief in the later part of the documentation

For example: user-event

{"phone":"918x98xx21x4","type":"sandbox-start"}

Events


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

phone

string

The phone number of the customer who has sent the message on WhatsApp, number is in E.164 format

918x98xx21x4

type

string

The type of user-event received on your webhook
Must be one of these: sandbox-start, opted-in, opted-out

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:

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.
Possible values: APPROVED, REJECTED

{ "app": "jeet20", "timestamp": 1636986446609, "version": 2, "type": "account-event", "payload": { "type": "review-event", "payload": { "status": "APPROVED", "actionDate": "January 31,2021" } } }

status-event

This event is received when the status of the WABA has changed.
Possible values: ACCOUNT_VIOLATION: The WABA has been disabled/banned due to policy violation, additionally, the reason for the violation is also received. ACCOUNT_VERIFIED: When an app of type of Embed is updated from Sandbox to Live.
Learn more about policy violation here.

{ "app": "jeet20", "timestamp": 1636986446609, "version": 2, "type": "account-event", "payload": { "type": "status-event", "payload": { "status": "ACCOUNT_VIOLATION", "violation_type": "GAMBLING" } } }

pndn-event

This event is received when the status of the submitted Phone number/Display Name is updated.
Possible values: INVALID_FORMAT, NAME_END_CLIENT_VIOLATION, NAME_FORMAT_UNACCEPTABLE, NAME_NOT_CONSISTENT, NAME_INDIVIDUAL_ISSUE, and NAME_ENDCLIENT_NOTRELATED

{ "app": "jeet20", "timestamp": 1636986446609, "version": 2, "type": "account-event", "payload": { "type": "pndn-event", "payload": { "status": "approved/rejected", "rejectedReason": "INVALID_FORMAT" } } }

tier-event

This events notifies you when the quality-related status of a phone number has an update.
Possible values for events: ONBOARDING, UPGRADE, DOWNGRADE, UNFLAGGED, and FLAGGED.
The current tier limit where this account is and the new tier if it has been updated. Possible values are: TIER_1K, TIER_10K, and TIER_100K.

{ "app": "jeet20", "timestamp": 1636986446609, "version": 2, "type": "account-event", "payload": { "type": "tier-event", "payload": { "event": "onboarding/upgrade/downgrade /unflagged/flagged", "oldLimit": "TIER_10K", "currentLimit": "TIER_100K" } } }

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

id

string

This is Gupshup Message Id for message-event types: enqueued and failed
For the DLR events(sent|delivered|read|mismatch) it is always WhatsApp Message ID

59f8db90-c37e-4408-90ab-cc54ef8246ad
OR
gBEGkYaYVSEEAgnZxQ3JmKK6Wvg

gsId

string

This is Gupshup Message Id and only present for message-event types: DLR events(sent|delivered|read)

59f8db90-c37e-4408-90ab-cc54ef8246ad

type

string

The type of message-event received on your webhook
Must be one of these: enqueued, failed, sent, delivered, read

Described in brief below

message-event types

Type Description Sample
enqueued Message is successfully sent to WhatsApp Business API client
Payload object:
Key Type Description Example

whatsapp
MessageId

string

WhatsApp message id generated while sending a message to an end-user on WhatsApp

gBEGkYaYVSEEA
gkD7bRi9syGnBk

type

string

Indicated the type of messaging

session

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:
Key Type Description Example

code

string

Failure/exception code

1002

reason

string

Message failure reason with respect to the error code

Number Does Not Exists On WhatsApp

See message failure code and reasons table below for further description of the failure.
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:
Key Type Description Example

ts

Number

TimeStamp of the event

1585344475

id

string

Unique ID for a conversation.

532b57b5f6e63595ccd74c6010e5c5c7

expiresAt

Number

Conversation expiration timestamp in seconds

1518780636

type

string

The type of conversation. Possible values:

  • FEP (Free entry point)
  • UIC (User-initiated conversation)
  • BIC (Business-initiated conversation)

UIC

policy

string

The pricing policy applied for this message. Possible values:

  • CBP (Conversation based pricing)
  • NBP (Notification based pricing)

CBP

category

string

The pricing category. Possible values:

  • FEP
  • UIC
  • BIC

UIC

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:
Key Type Description Example

ts

Number

TimeStamp of the event

1585344476

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:
Key Type Description Example

ts

Number

TimeStamp of the event

1585344602

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.
Key Type Description Example

wa_id

Number

WhatsApp ID of the destination number

5593587654321

phone

Number

Dialable number/given destination number

553587654321

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

type

string

The type of conversation. Possible values:

  • FEP (Free entry point)
  • UIC (User-initiated conversation)
  • BIC (Business-initiated conversation)

BIC

model

string

The pricing policy model applied for this message. Possible values:

  • CBP (Conversation based pricing)
  • NBP (Notification based pricing)

CBP

source

string

Origin source of the conversation

whatsapp

References object description

Key Type Description Example

id

string

Unique WhatsApp identifier for a message

59f8db90c37e-4408-90ab-cc54ef8246ad

gsId

string

Unique Gupshup identifier for a message

ee4a68a0-1203-4c85-8dc3-49d0b3226a35

conversationId

string

Unique identifier for a conversation

532b57b5f6e63595ccd74c6010e5c5c7

destination

string

Phone number of the user engaged in the conversation.
Phone Number will be in E.164 format.

91XX985XX10X

Inbound Message


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

app

string

The name of the Gupshup app to which the customer has sent a message on WhatsApp

DemoAPI

timestamp

string

The time in unix timestamp when the message sent by the customer was received by Gupshup

1584898839530

version

string

Callback payload version

2

type

string

Inbound events
user-event|message-event|message

message

payload

object

It contains the details of inbound message:
1. WhatsApp message id,
2. Message sender phone number with country code,
3. Type of message sent by the end-user/customer
4. Content of the message sent by the end-user/customer

See payload object for more information.

sender

object

It contains the details of the message sender/end-user/customer:
1. Phone number
2. Name of the sender

See sender object for more information.

context

object

Optional.
This object will only be included when someone replies to one of your messages. Contains information about the content of the original message, such as the Gupshup ID and WhatsApp ID of the message.

See context object for more information.

The payload object

Key Type Description Example

id

string

The unique WhatsApp message identifier for the inbound message

ABEGkYaYVSEEAhAt2MgAKjL1qGe88OKyMQfM

source

string

The phone number of the customer who has sent the message on WhatsApp, number is in E.164 format

918x98xx21x4

type

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.

Must be one of these: text, image, file, audio, video, contact, location.

text

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

phone

string

The phone number of the end user who has sent the message on WhatsApp, number is in E.164 format

918x98xx21x4

name

string

Name of the end user who has sent the message on WhatsApp

Smit

country_code

string

Get the sender country code

91

dial_code

string

Get the sender dial code

8x98xx21x4

The context object

Key Type Description Example

id

string

The unique WhatsApp message identifier for the inbound message

gBEGkYaYVSEEAgnPFrOLcjkFjL8

gsId

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:

Text

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
{ 
  "app": "DemoApp", 
  "timestamp": 1580227766370,   
  "version": 2, 
  "type": "message",    
  "payload": {  
    "id": "ABEGkYaYVSEEAhAL3SLAWwHKeKrt6s3FKB0c",   
    "source": "918x98xx21x4",   
    "type": "text", 
    "payload": {    
      "text": "Hi"  
    },  
    "sender": { 
      "phone": "918x98xx21x4",  
      "name": "Smit",   
      "country_code": "91", 
      "dial_code": "8x98xx21x4" 
    }   
  } 
}
The text payload
Key Type Description Example

text

string

Message text

Hi

Customer replied to a business message

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
{
  "app": "DemoApp",
  "timestamp": 1590854464792,
  "version": 2,
  "type": "message",
  "payload": {
    "id": "ABEGkYaYVSEEAgo-sMx1DoUoQJRW",
    "source": "918x98xx21x4",
    "type": "text",
    "payload": {
      "text": "hi"
    },
    "sender": {
      "phone": "918x98xx21x4",
      "name": "Smit",
      "country_code": "91",
      "dial_code": "8x98xx21x4"
    },
    "context": {
      "id": "gBEGkYaYVSEEAgnPFrOLcjkFjL8",
      "gsId": "9b71295f-f7af-4c1f-b2b4-31b4a4867bad"
    }
  }
}
The text payload
Key Type Description Example

text

string

Message text

Hi

Customer clicked on a Quick Reply template message button

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
{
  "app": "DemoApp",
  "timestamp": 1590854464792,
  "version": 2,
  "type": "message",
  "payload": {
    "id": "ABEGkYaYVSEEAgo-sMx1DoUoQJRW",
    "source": "918x98xx21x4",
    "type": "text",
    "payload": {
      "text": "View Account Balance",
      "type": "button"
    },
    "sender": {
      "phone": "918x98xx21x4",
      "name": "Smit",
      "country_code": "91",
      "dial_code": "8x98xx21x4"
    },
    "context": {
      "id": "gBEGkYaYVSEEAgnPFrOLcjkFjL8",
      "gsId": "9b71295f-f7af-4c1f-b2b4-31b4a4867bad"
    }
  }
}
The text payload
Key Type Description Example

text

string

Button title

View Account Balance

type

string

Which interactive message type was clicked

button

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

caption

string

Optional. Only present if specified.
The provided caption for the media.

View Account Balance

name

string

Filename on the sender's device.

152445128_APR-20.pdf

url

string

Media download link

https://filemanager.gupshup.io/fm/wamedia/Jeet20/68f1e51b-ac53-4dfb-b970-7b9031ed1d3c

contentType

string

Mime type of the media.

application/pdf

urlExpiry

string

Media download URL expiry Timestamp

1624957005482

Image

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
{   
  "app": "DemoApp", 
  "timestamp": 1580227895991,   
  "version": 2, 
  "type": "message",    
  "payload": {  
    "id": "ABEGkYaYVSEEAhAE0dyndiP9cVlr4hC5xU64",   
    "source": "918x98xx21x4",   
    "type": "image",    
    "payload": {    
      "caption": "Sample image",    
      "url": "https://filemanager.gupshup.io/fm/wamedia/DemoApp/546af999-825e-485b-bf54-4a3323824cca",  
      "contentType": "image/jpeg",  
      "urlExpiry": 1624956794816    
    },  
    "sender": { 
      "phone": "918x98xx21x4",  
      "name": "John",   
      "country_code": "91", 
      "dial_code": "8x98xx21x4" 
    }   
  } 
}   
Audio

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
{   
  "app": "DemoApp", 
  "timestamp": 1580228104661,   
  "version": 2, 
  "type": "message",    
  "payload": {  
    "id": "ABEGkYaYVSEEAhC8Sqz6bdT95X8wgVH28wz8",   
    "source": "918x98xx21x4",   
    "type": "audio",    
    "payload": {    
      "url": "https://filemanager.gupshup.io/fm/wamedia/DemoApp/eae8a65a-b3ec-4085-94a6-3738338835fc",  
      "contentType": "audio/ogg; codecs=opus",  
      "urlExpiry": 1624956864635    
    },  
    "sender": { 
      "phone": "918x98xx21x4",  
      "name": "John",   
      "country_code": "91", 
      "dial_code": "8x98xx21x4" 
    }   
  } 
}   
Video

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
{   
  "app": "DemoApp", 
  "timestamp": 1580228336953,   
  "version": 2, 
  "type": "message",    
  "payload": {  
    "id": "ABEGkYaYVSEEAhDHMK-ctBQwqxyKoMbKcxES",   
    "source": "918x98xx21x4",   
    "type": "video",    
    "payload": {    
      "caption": "Sample video",    
      "url": "https://filemanager.gupshup.io/fm/wamedia/DemoApp/9f5ff20a-d14f-47ea-b336-754756a8b950",  
      "contentType": "video/mp4",   
      "urlExpiry": 1580833136954    
    },  
    "sender": { 
      "phone": "918x98xx21x4",  
      "name": "John",   
      "country_code": "91", 
      "dial_code": "8x98xx21x4" 
    }   
  } 
}   
Document

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
{   
  "app": "DemoApp", 
  "timestamp": 1580228523976,   
  "version": 2, 
  "type": "message",    
  "payload": {  
    "id": "ABEGkYaYVSEEAhCzqobr15BdMPcRup1fIXAJ",   
    "source": "918x98xx21x4",   
    "type": "file", 
    "payload": {    
      "caption": "Document caption",    
      "name": "samplefile.pdf", 
      "url": "https://filemanager.gupshup.io/fm/wamedia/DemoApp/b6e4e360-be01-4ffa-8928-84b8f40dd2eb",  
      "contentType": "application/pdf", 
      "urlExpiry": 1624957181122    
    },  
    "sender": { 
      "phone": "918x98xx21x4",  
      "name": "Smit",   
      "country_code": "91", 
      "dial_code": "8x98xx21x4" 
    }   
  } 
}   
Sticker

Below is a sample payload when a customer sends a sticker on WhatsApp to your business number.

Headers Content type: application/json
Inbound Body
{
  "app": "DemoApp",
  "timestamp": 1580228523976,
  "version": 2,
  "type": "message",
  "payload": {
    "id": "ABEGkYaYVSEEAhCzqobr15BdMPcRup1fIXAJ",
    "source": "918x98xx21x4",
    "type": "sticker",
    "payload": {
      "url": "https://filemanager.gupshup.io/fm/wamedia/DemoApp/32030cb2-68de-4c3c-a795-c4647fd4a9c7",
      "contentType": "image/webp",
      "urlExpiry": 1624957279044
    },
    "sender": {
      "phone": "918x98xx21x4",
      "name": "John",
      "country_code": "91",
      "dial_code": "8x98xx21x4"
    }
  }
}
Interactive Messages
Customer replied to a List message

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
{
  "app": "DemoApp",
  "timestamp": 1580228523976,
  "version": 2,
  "type": "message",
  "payload": {
    "id": "ABEGkYaYVSEEAhCzqobr15BdMPcRup1fIXAJ",
    "source": "918x98xx21x4",
    "type": "list_reply",
    "payload": {
            "title": "section 1 row 1",
            "id": "list1",
            "reply":"section 1 row 1 1",
            "postbackText":"section 1 row 1 postback payload",
            "description": "first row of first section description"
        },
    "sender": {
      "phone": "918x98xx21x4",
      "name": "John",
      "country_code": "91",
      "dial_code": "8x98xx21x4"
    },
    "context": {
        "id": "gBEGkYaYVSEEAgnPGGVYGg1uNU4",
        "gsId": "cbdafe39-1023-42a7-89d6-6c01a3388bb5"
    }
  }
}
List reply payload
Key Type Description Example

title

String

Returns the section title

section 1 row 1

id

String

Returns the developer defined message id i.e the custom id(alpha-numeric) sent while making the API request for list message

list1

reply

String

Returns the title of the line item submitted from a section along with the index of the list item

section 1 row 1 1

postbackText

String

Returns the developer defined postback payload for a particular line item in the list

section 1 row 1 postback payload

description

String

Returns the description of the submitted line item

first row of first section description

Customer replied to a Quick Reply button

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
{
  "app": "DemoApp",
  "timestamp": 1580228523976,
  "version": 2,
  "type": "message",
  "payload": {
    "id": "ABEGkYaYVSEEAhCzqobr15BdMPcRup1fIXAJ",
    "source": "918x98xx21x4",   
    "type": "button_reply", 
    "payload": {    
            "title": "First",   
            "id": "qr1",    
            "reply":"First 1"   
        },  
    "sender": { 
      "phone": "918x98xx21x4",  
      "name": "John",   
      "country_code": "91", 
      "dial_code": "8x98xx21x4" 
    },  
    "context": {    
        "id": "gBEGkYaYVSEEAgkvE0f1ZkfXX78",    
        "gsId": "123b0fb2-0620-493b-8f7e-5a1ceb6d8c58"  
    }   
  } 
}   
List reply payload
Key Type Description Example

title

String

Returns the button title

First

id

String

Returns the developer defined message id i.e the custom id(alpha-numeric) sent while making the API request for quick reply message

qr1

reply

String

Returns the title of the button clicked along with the index of the button

First 1

Other Messages
Location

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
{   
  "app": "DemoApp", 
  "timestamp": 1580228767338,   
  "version": 2, 
  "type": "message",    
  "payload": {  
    "id": "ABEGkYaYVSEEAhCIxTq7KXQIqby1Uo-IO7_E",   
    "source": "918x98xx21x4",   
    "type": "location", 
    "payload": {    
      "longitude": "72.8552172",    
      "latitude": "19.1453658"  
    },  
    "sender": { 
      "phone": "918x98xx21x4",  
      "name": "Smit",   
      "country_code": "91", 
      "dial_code": "8x98xx21x4" 
    }   
  } 
}   
The location payload
Key Type Description Example

latitude

Number

Latitude of location being sent.

19.1453658

longitude

Number

Longitude of location being sent.

72.8552172

Contact Card

Below is a sample payload when a customer shares a contact card to your business number.

Headers Content type: application/json
Inbound Body
{
  "app": "DemoApp",
  "timestamp": 1584898884710,
  "version": 2,
  "type": "message",
  "payload": {
    "id": "ABEGkYaYVSEEAhD9cTZVyPlOGYZJOnviI7OJ",
    "source": "918x98xx21x4",
    "type": "contact",
    "payload": {
      "contacts": [
        {
          "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"
            }
          ],
          "emails": [
            {
              "email": "test@fb.com",
              "type": "WORK"
            },
            {
              "email": "test@whatsapp.com",
              "type": "WORK"
            }
          ],
          "ims": [

          ],
          "name": {
            "first_name": "Dev",
            "formatted_name": "Dev Support",
            "last_name": "Support"
          },
          "org": {
            "company": "Dev Support"
          },
          "phones": [
            {
              "phone": "+91 77383 05433",
              "type": "Mobile"
            }
          ],
          "urls": [
            {
              "url": "https://www.facebook.com",
              "type": "WORK"
            }
          ]
        }
      ]
    },
    "sender": {
      "phone": "918x98xx21x4",
      "name": "Smit",
      "country_code": "91",
      "dial_code": "8x98xx21x4"
    }
  }
}
The Contact payload
Key Type Description Example

addresses

Array

Full contact address(es). This field can contain street, city, state, zip, country, country_code, and type fields.

{ "city": "Menlo Park", "country": "United States", "countryCode": "us", "state": "CA", "street": "1 Hacker Way", "type": "HOME", "zip": "94025" }

birthday

YYYY-MM-DD formatted string

Contact's birthday.

1990-07-21

emails

Array

Contact email address(es). This field can contain the email and type parameters

{ "email": "test@fb.com", "type": "WORK" }

ims

Array

Messaging contact information. This field contains the service and user_id parameters

name

Array

Full contact name. This field can contain the first_name, middle_name, last_name, formatted_name, name-prefix, and name_suffix parameters

{ "first_name": "Dev", "formatted_name": "Dev Support", "last_name": "Support" }

org

Array

Contact organization information. This field can contain the company, department, and title parameters

{ "company": "Dev Support" }

phones

Array

Contact phone number(s). This field can contain the phone, wa_id, and type parameters

[ { "phone": "+91 77383 05433", "type": "Mobile" } ]

urls

Array

Contact URL(s). This field can contain the url and type parameters

[ { "url": "https://www.facebook.com", "type": "WORK" } ]

Referral

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
{
    "app": "DemoApp",
    "timestamp": 1624350395531,
    "version": 2,
    "type": "message",
    "payload": {
        "id": "ABEGkZlpNARoAgo6v1b-zBR7EnX3",
        "source": "918x98xx21x4",
        "type": "text",
        "payload": {
            "text": "I saw this on Facebook..."
        },
        "sender": {
            "phone": "918x98xx21x4",
            "name": "Smit",
            "country_code": "91",
            "dial_code": "8x98xx21x4"
        },
        "referral": {
                "body": "Test post payload",
                "headline": "Demo Gupshup ad",
                "image": {
                    "id": "6a35b528-429d-4fe3-953d-536ef0397ece"
                },
                "source_id": "951242428775548",
                "source_type": "post",
                "source_url": "https://fb.me/2oNXGTsjn"
        }
    }
}
The referral payload
Key Type Description Example

headline

String

Headline used in the ad that generated the message.

Demo Gupshup ad

body

String

Body from the ad that generated the message.

Test post payload

source_type

String

The type of the ad?s source. Currently, supported values are ad and post.

post

source_id

String

Facebook ID for an ad or a post

951242428775548

source_url

String

The url that leads to the ad. Opening this url takes you to the ad viewed by your user.

https://fb.me/2oNXGTsjn

image and video

Object

Optional
The image or video that the user saw and clicked.

{ "id": "6a35b528-429d-4fe3-953d-536ef0397ece" }

Outbound Message


Session messaging

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:

API Endpoint

To send a message on WhatsApp, the API request is made to the endpoint:

https://api.gupshup.io/sm/api/v1/msg

API Request

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

channel

string

The channel on which this message must be sent.

whatsapp

Y

destination

string

The phone number of the recipient to whom message is being sent.

918x98xx21x4

Y

source

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 This is our proxy number

Y

message

object

WhatsApp template message that you want to send to your customers

See message object documentation below

Y

src.name

string

Your WhatsApp app name

DemoApp

Y - for sandbox apps

N - for Live apps

disablePreview

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 false and to disable a URL preview, set "disablePreview" parameter as true in the request body.

Make sure the URL begins with http:// or https://. A hostname is required, IP addresses are not matched.

true

N

Common message object parameters

Key Type Description Example Required

type

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.

Must be one of: text, image, file, audio, video, location, contact, sticker, list, quick_reply

Text

Y

url

string

The hosted URL of the file / audio / video attachment

https://www.buildquickbots.com/whatsapp/media/sample/audio/sample01.mp3

Y

caption

string

Add caption to media messages, applicable to media type = image|video|file

Media caption text

N


Send text message

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
Key Type Description Example Required

text

string

The text message to be sent to the customer, in case of type=text

Hello World!

Y

Formatting Options

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!
Strike-through Tilde (~) This is ~better~ best! This is better best!
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


Send Image message

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.
Key Type Description Example Required

originalUrl

string

The public URL of the hosted image. Only to be sent for type = image

https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg

Y

previewUrl

string

The public URL of the hosted image thumbnail. Only to be sent for type = image

https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg

Y


Send document/file message

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
Key Type Description Example Required

filename

string

Name of the file

Sample functional resume

Y


Send Audio message

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"
}

Send Video message

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"
}

Send Stickers

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"
}

Interactive Messages

Send List Messages

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
Key Type Description Example Required

title

string

Text for the header. Maximum of 60 characters. Formatting allows emojis, but not markdown

title text

Y

body

string

message body - The body content of the message can be maximum of 1024 characters. Emojis and markdown are supported. Links are supported.

body text

Y

msgid

string

Its a developer defined message id for a specific list message. This id will be received with the message-event when the customer replies to that specific list message. Its a special feature provided by our platform, this helps developer to set context of a reply for use-cases like chatbots.

list1

N

globalButtons

Array

Although its an array, only 1 Global button can be added to the list.

[ { "type": "text", "title": "Global button" } ]

Y

items

Array

Element in this array are sections in the list. There is a minimum of 1 and maximum of 10 elements in the list

[{ "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" } ] }]

Y

globalButtons array description
Key Type Description Example Required

type

string

Only text type is support

text

Y

title

string

The title of the global button. It cannot be an empty string and must be unique within the message. Maximum of 20 characters. Does not allow emojis or markdown.

Global button

Y

items array description
Key Type Description Example Required

title

String

This property is used to set the title of a section in a list

first Section

Y

options

Array

Contains a list of items in an section.
An item can be created using below parameters:
1. type : text (It's the only type supported)
2. title : section 1 row 1 - (It's the title of the item in the list. Maximum length: 24 characters)
3. description : section 1 row 1 (Optional. It's the description of the item in the list. Maximum length: 72 characters)
4. postbackText : section 1 row 1 postback payload (Optional. It's the custom payload that a developer can receive when a particular item in the list is submitted by the customer.)

[{ "type": "text", "title": "section 1 row 1", "description": "first row of first section description", "postbackText": "section 1 row 1 postback payload" }]

Y

Send Quick replies

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
Text Payload Media Payload for image | video | document
"channel=whatsapp",
         "source=917834811114",
         "destination=918X7X733X59",
         "src.name=app_name,
         "message" : {
         "type":"quick_reply",
         "msgid":"qr1",
         "content":{ "type":"text", "header":"this is the header", "text":"this is the body", "caption":"this is the footer" },
         "options":[ { "type":"text", "title":"First" }, { "type":"text", "title":"Second" }, { "type":"text", "title":"Third" } ]}
"channel=whatsapp",
         "source=917834811114",
         "destination=918X7X733X59",
         "src.name=app_name,
         "message" : {
         "type":"quick_reply",
         "msgid":"qr1",
         "content":{ "type":"image", "text":"this is the body", "url":"https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg", "caption":"this is the footer" },
         "options":[ { "type":"text", "title":"First" }, { "type":"text", "title":"Second" }, { "type":"text", "title":"Third" } ]}
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.
Key Type Example

type

text

{"type":"text", "header":"this is the header", "text":"this is the body", "caption":"this is the footer"}

type

image

{"type":"image", "url":"https://www.buildquickbots.com/whatsapp/media/sample/jpg/sample01.jpg", "text":"this is the body", "caption":"this is the footer"}

type

document

{"type": "file", "url": "https://www.buildquickbots.com/whatsapp/media/sample/pdf/sample01.pdf", "text":"this is the body", "filename": "Sample file", "caption":"this is the footer"}

type

video

{"type": "video", "url":"https://www.buildquickbots.com/whatsapp/media/sample/video/sample01.mp4", "text":"this is the body", "caption":"Sample video"}

Quick replies options array description A Quick reply Message including up to 3 options
Key Type Description Example Required

type

string

Describes the button type. Current supported type is text postback

text

Y

title

string

Button title. It cannot be an empty string and it must be unique within the message. Maximum of 20 characters. Does not allow emojis or markdown.

First

Y


Other Messages
Send location message

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"
}

Send Contact Card

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"
                     }
               ]
         }
}

API Response

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


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" : {
        "isHSM":"true", //It's Optional. Template messaging has to be enabled from App settings
        "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:

API Endpoint

To send a message on WhatsApp, the API request is made to this endpoint:

http://api.gupshup.io/sm/api/v1/template/msg

API Request

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

source

string

Your register business Phone number (with country code) registered for WhatsApp Business API

917834811114 This is our Sandbox number. Please use your approved Business number instead.

Y

destination

string

Destination phone number with country code to whom the Message template has to be sent.

918x98xx21x4

Y

template

Object

This Object has 2 properties:
1. id => It's Id of your approved template. You can get the ids of the template from the Template list API given below in this guide.
2. params => This consists of placeholders in your templates.

Your approved template is:

Good news! Your order has just been sent and is currently on its way to be delivered as quickly as possible. {{1}} will deliver your package to your address on {{2}}. With this Track & Trace code, you can continue to follow your order to your doorstep {{3}}. We hope you enjoy your new product!

Template id is c6aecef6-bcb0-4fb1-8100-28c094e3bc6b

Then the payload is:

{"id": "c6aecef6-bcb0-4fb1-8100-28c094e3bc6b","params": ["Agent","Local Address","Tracking code"]}

Y

message

object

This property is used only if you want to send a media - Image, Video, Document(.pdf) and location.

Image: { "type": "image", "image": { "link": "" } }
Video: { "type": "video", "video": { "link": "" } }
Document: { "type": "document", "document": { "link": "" } }
Location: { "type": "location", "location": { "longitude": "", "latitude":"" } }

N

API Response

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.

Send Text
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"]}'

Media


Send Image
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"}}'
Send Video
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"}}'
Send Document
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"}}'
Send Location
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":""}}'

Interactive Messages


Call to action

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"}}'
Quick replies

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"]}'

Miscellaneous APIs


Get Opt-in User list

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

API Request

curl --location --request GET 'https://api.gupshup.io/sm/api/v1/users/{{App_Name}}' \
--header 'apikey: {{Gupshup_Account_APIKey}}'

API Response

{
  "status": "success",
  "users": [
    {
      "countryCode": "91",
      "lastMessageTimeStamp": 1585593959851,
      "optinSource": "URL",
      "optinStatus": "OPT_IN",
      "optinTimeStamp": 1585504095053,
      "phoneCode": "8x98xx21x4"
    }
  ]
}

Mark User Opt-in


Businesses are required to obtain opt-in before sending proactive notifications to customers. Businesses can obtain opt-in in a multitude of ways, both on and off WhatsApp. This API is really helpful to take user Opt-in from your website, interactive voice response (IVR) flows or in a WhatsApp thread, etc.

API Request

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

API Response Code

202

Mark User Opt-out


If a customer wants to unsubscribe or opt-out from receiving notification. Business can use this API to do the same

API Request

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

API Response Code

202

Get Template list


This API can be used for various purposes, for instance, if you have submitted a template for WhatsApp review, you can programmatic track the status of the template. It can be also utilized to get the template id generated out platform for each template submitted for WhatsApp review - template id is necessary to utilize template messaging API.

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.

Check Wallet balance

API Request

curl --location --request GET 'https://api.gupshup.io/sm/api/v2/wallet/balance' \
--header 'apikey: {{Gupshup Account apikey}}'

API Response Code

200

API Response Body

{
    "balance": 1313.7675,
    "status": "success"
}