post
https://api.gupshup.io/wa/api/v1/template/msg
cURL
curl --location '{{api_front_base_url}}/wa/api/v1/template/msg' \
--header 'apikey: {{apiKey}}' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'channel=whatsapp' \
--data-urlencode 'source={{source phone number}}' \
--data-urlencode 'destination={{destination phone number}}' \
--data-urlencode 'src.name={{app_name}}' \
--data-urlencode 'template={"id":"<template_id>","params":[<list_of_template_parameters>]}' \
--data-urlencode 'message={{message}}' \
--data-urlencode 'postbackTexts=[{"index":<qr_btn_index>,"text":"<postback_text>"}]'
- Include the message object in the curl above only if the template has media.
Refer image, video and document template docs to get the corresponding message payloads.* Omit the postbackTexts parameter in the curl above if the template doesn’t have quick reply buttons, or if it has but there’s no need for postback text support.
Request Parameters
| Parameter | Location | Type | Description | Example |
|---|---|---|---|---|
| apikey | Header | string | Your account API key | 2xxc4x4xx2c94xxxc2f9xx9d43xxxx8a |
Form Parameters (Request Body)
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| source | string | Yes | Sender WhatsApp Number | 919163xxxxx3 |
| src.name | string | Yes | App name that the source number belongs to | DemoApp |
| destination | string | Yes | Receiver WhatsApp Number | 917839xxxxx3 |
| template | object | Yes | Contains template id and list of template parameters, including the coupon code | See below for detailed structure |
| message | object | No | Optional; required for media templates | See below for detailed structure |
| postbackTexts | array | No | List of objects containing postback text details | See below for detailed structure |
| channel | string | No | Messaging Platform Name |
template object structure:
template object structure:| Field | Type | Description | Example |
|---|---|---|---|
| id | string | Template ID | template_id |
| params | array | List of template parameters; MUST include the coupon code value in order | ["125OFF"] |
message object structure:
message object structure:| Field | Type | Description | Example |
|---|---|---|---|
| type | string | Type of message | image / video / document |
| image | object | Image object containing id / link | See below for detailed structure |
| video | object | Video object containing id / link | See below for detailed structure |
| document | object | Document object containing id / link | See below for detailed structure |
image object structure:
image object structure:| Field | Type | Description | Example |
|---|---|---|---|
| link | string | Media URL of the image | "<image_media_url>" |
| id | string | Media ID of the image | "<image_media_id>" |
video object structure:
video object structure:| Field | Type | Description | Example |
|---|---|---|---|
| link | string | Media URL of the video | "<video_media_url>" |
| id | string | Media ID of the video | "<video_media_id>" |
document object structure:
document object structure:| Field | Type | Description | Example |
|---|---|---|---|
| link | string | Media URL of the document | "<document_media_url>" |
| id | string | Media ID of the document | "<document_media_id>" |
| filename | string | Name of the document file to be shown; optional | "temp.pdf" |
postbackTexts object structure:
postbackTexts object structure:| Field | Type | Description | Example |
|---|---|---|---|
| index | integer | Button index (0-based) | 0 |
| text | string | Postback text for the button | hello |
Status Codes
| Status Code | Description | Response Body |
|---|---|---|
| 202 | Success response | { "messageId": "message id", "status": "success" } |
| 400 | Error response; in case of bad request | { "message": "Invalid Destination", "status": "error" } |
| 401 | Error response; in case of authentication failure | { "message": "Authentication Failed", "status": "error" } |
