Send msg With Template ID

Use this API to send messages with Template ID

📘

Note:

  1. In case of Carousel template, the postback texts are added to the Cards of the Carousel template.
  2. If the template has a quick reply button, then the postback texts can be added to the Callback URL.

Parameters

KeyDescriptionRequired/OptionalTypeValue
AuthorizationAccess Token for the applicationRequiredString{{PARTNER_APP_TOKEN}}
APP IDUnique Identifier for Gupshup AppRequiredString{{APP_ID}}
sourcePhone number to send a message from.

Required phone Number With Country Code
RequiredInteger91891056XXXX
src.nameApp nameStringRequiredAppname1
sandboxShould be boolean valueBooleanOptionalfalse
destinationPhone number of the customer to send the message to.

Required phone Number With Country Code.
RequiredInteger918286836XXX
templateMPM 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}}
OptionalString{"id": "007b7c0e-fc8d-4698-a9a8-3938151dd5da","params": ["monday","2020-12-20","apps"]}
src.nameApp name, whose appId used while creating templateRequiredStringGupshupDevAssistant01
messageFor 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"}] }, ] }
OptionalString{ "type": "carousel", "cardHeaderType": "IMAGE", "cards": \[ { "link": "<https://fastly.picsum.photos/id/13/2500/1667.jpg?hmac=SoX9UoHhN8HyklRA4A3vcCWJMVtiBXUg0W4ljWTor7s">, "postbackTexts": [ { "index": 1, "text": "hello" } ] }]
postbackTextsAdd Postback Text for quick reply button
[ { "index": 3, // button index starts from 0 "text": "hello" //postback text for the button } ]
OptionalString[{"index":4,"text":"hello"},{"index":5,"text":"hey"}]
channelMessaging channel to send message on.OptionalStringwhatsapp
TokenYour app token, please refer Get access token api to get the token from partner documentation.RequiredStringsk_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 CodeResponseComment
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
Language
Click Try It! to start a request and see the response here!