post https://partner.gupshup.io/partner/app//template/msg
Use this API to send messages with Template ID
Note:
- In case of Carousel template, the postback texts are added to the Cards of the Carousel template.
- If the template has a quick reply button, then the postback texts can be added to the Callback URL.
Parameters
Key | Description | Required/Optional | Type | Value |
---|---|---|---|---|
Authorization | Access Token for the application | Required | String | {{PARTNER_APP_TOKEN}} |
appId | Unique Identifier for Gupshup App | Required | String | {{APP_ID}} |
source | Phone number to send a message from. Required phone Number With Country Code | Required | Integer | 91891056XXXX |
src.name | App name | Required | String | Appname1 |
sandbox | Should be a boolean value | Optional | Boolean | false |
destination | Phone number of the customer to send the message to. Required phone Number With Country Code. | Required | Integer | 918286836XXX |
template | MPM Template For the MPM template, params must include all params including a product ID (which is to be used as a thumbnail (last in the list)). For MPM template messages template section must be provided with valid Ids template={ "id":"3b9bf65b-979c-44d3-a269-dec2f20c4e52", "params":[ "zqc2qfz5fm" ], "mpm":{ "sections":\[{ "title":"Products", "products":[ "zqc2qfz5fm" ] }, { "title":"Products2", "products":[ "xyli96fcbn" ] }] } } Catalog Template The catalog template is only supported on CAPI. For catalog template Params should contain the productId which will be sent as thumbnail for the catalog (Must be the last element in templateParams list). LTO Template When the template type is LTO, we can specify the expiration period. {"id":"{template_id}","params":["template_params_list"],"expiration":{expiration_time_in_UNIX_timestamp_in_milliseconds}} | Optional | String | {"id": "007b7c0e-fc8d-4698-a9a8-3938151dd5da","params": ["monday","2020-12-20","apps"]} |
src.name | App name, whose appId used while creating template | Required | String | GupshupDevAssistant01 |
message | For the carousel, message JSON along with the media id/link will also contain the postbackTexts here index is the button index (starts from 0) and text is the postback text for that button.{ "type": "carousel", "cardHeaderType": "\<IMAGE/VIDEO>", "cards": \[ { "id/link": "\<image_id or image_link/video_id or video_link>", "postbackTexts":[{"index":0,"text":"hello"}] }, ] } | Optional | String | { "type": "carousel", "cardHeaderType": "IMAGE", "cards": \[ { "link": "<https://fastly.picsum.photos/id/13/2500/1667.jpg?hmac=SoX9UoHhN8HyklRA4A3vcCWJMVtiBXUg0W4ljWTor7s">, "postbackTexts": [ { "index": 1, "text": "hello" } ] }] |
postbackTexts | Add Postback Text for quick reply button[ { "index": 3, // button index starts from 0 "text": "hello" //postback text for the button } ] | Optional | String | [{"index":4,"text":"hello"},{"index":5,"text":"hey"}] |
channel | Messaging channel to send message on. | Optional | String | |
Token | Your app token, please refer Get access token api to get the token from partner documentation. | Required | String | sk_61b3021c97xxx4370b341f8baaae0xxxx |
Sample Request
curl --location '{{partner_base_url}}/partner/app/{{APP_ID}}/template/msg' \
--header 'Connection: keep-alive' \
--header 'Authorization: {{PARTNER_APP_TOKEN}}' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'channel=whatsapp' \
--data-urlencode 'source={{SOURCE_NUMBER}}' \
--data-urlencode 'sandbox=false' \
--data-urlencode 'destination={{DESTINATION_NUMBER}}' \
--data-urlencode 'template={"id": "{{TEMPLATE_ID}}","params":[]' \
--data-urlencode 'src.name={{APP_NAME}}' \
--data-urlencode 'message={{MESSAGE}}' \
--data-urlencode 'postbackTexts=[{"index":4,"text":"Hello"}]'
Sample Response
{
"status": "submitted",
"messageId": "b****acb-3***-4***-98**-64*****ea9**"
}
Expected Response on Callback
{
"app": "{{app_name}}",
"timestamp": 1716900845926,
"version": 2,
"type": "message",
"payload": {
"id": "wamid.HBgMOTE4ODg4OTk4NTQ1FQIAEhgUM0EzODA1NkE2OENBNEFGQjFFQjkA",
"source": "{{phone_number}}",
"type": "quick_reply",
"payload": {
"text": "Yes",
"type": "button",
"postbackText": "hello"
},
"sender": {
"phone": "{{phone_number}}",
"name": "{{name}}",
"country_code": "91",
"dial_code": "{{phone_number}}"
},
"context": {
"id": "3847e304-2b9f-4cef-a72d-29aca93f95ce",
"gsId": "3d749fe7-36fb-44b6-8209-f79efed697f9",
"forwarded": false,
"frequently_forwarded": false
}
}
}
Status Codes
Status Code | Response | Comment |
---|---|---|
Success | ||
200 | { "status": "submitted", "messageId": <messageId> } | |
Error | ||
400 | { "message": "Invalid Destination", "status": "error" } | If the destination is missing. |
400 | { "message": "Invalid App Details", "status": "error" } | If the source is missing or app details are not found"If the source is unavailable or the application details cannot be found. |
500 | { "status": "error", "message": "Internal server error. Please try again later and If Issue still persist than contact Gupshup Dev Support" } | For any Internal Error |