Message with parameters, attachments, and with buttons Estimated reading: 4 minutes 206 views Description: Send a template message with dynamic text parameters attachment with buttons message . Endpoint: http://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/messages Replace placeholders: {{key}}: Your API key for authentication.How to create key {{your_domain}}: Your domain URL where the API is hosted. {{phone_number_id}}: The unique identifier of the phone number used for sending messages. Example: { "messaging_product": "whatsapp", "recipient_type": "individual", "to": "91xxxxxxxxxx", "type": "template", "template": { "name": "utility_full_template", "language": { "code": "en" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "12345" } ] }, { "type": "header", "parameters": [ { "type": "image", "image": { "link": "https://chat.pingtochat.com/template_media/1736424548.png" } } ] }, { "type":"BUTTONS", "buttons": [ { "type": "QUICK_REPLY", "text": "Unsubscribe from Promos" }, { "type": "url", "text": "Go to link", "url": "https://chat.pingtochat.com/" } ] } ] } } Field Descriptions messaging_product Description: Indicates the messaging platform being used. Value: "whatsapp" (specific to WhatsApp). recipient_type Description: Defines the type of recipient. Value: "individual" (indicates the message is for an individual). to Description: The recipient’s WhatsApp phone number in international format. Value: "919946371505" (replace with the intended recipient’s phone number). type Description: Specifies the type of message being sent. Value: "template" (indicates this is a template message). template Description: Contains the details of the template message. Fields within template name Description: The unique name of the pre-approved template. Value: "utility_full_template". language Description: Specifies the language in which the template is sent. Fields: code: Description: The language code. Value: "en" (English). components Description: Defines the dynamic parts of the template, such as text, images, and buttons. Fields within components type: body Description: Defines the message body. Fields: parameters: Description: Contains dynamic values to populate the body text. Subfields: type: Description: Type of the parameter. Value: "text" (indicates this is text content). text: Description: The dynamic text content to include in the message. Value: "12345" (can be replaced with relevant dynamic content). type: header Description: Defines the message header, which can contain media (images, videos, or documents) or text. Fields: parameters: Description: Contains the dynamic media or text for the header. Subfields: type: Description: Type of the parameter. Value: "image" (indicates the header contains an image). image: Description: Contains details about the image. Subfield: link: Description: The URL of the image to include in the header. Value: "https://chat.pingtochat.com/template_media/1736424548.png". type: BUTTONS Description: Defines interactive buttons in the message. Fields: buttons: Description: An array of buttons to include in the message. Subfields: For Button 1: Quick Reply type: Description: The type of button. Value: "QUICK_REPLY" (sends a predefined response when clicked). text: Description: The text displayed on the button. Value: "Unsubscribe from Promos". For Button 2: URL type: Description: The type of button. Value: "url" (redirects to a URL when clicked). text: Description: The text displayed on the button. Value: "Go to link". url: Description: The URL the button redirects to. Value: "https://chat.pingtochat.com/". Response A successful request will return an HTTP status code of 200 OK along with the following response structure: { "messaging_product": "whatsapp", "contacts": [ { "input": "91xxxxxxxxxx", "wa_id": "91xxxxxxxxxx", "status_id": "NTg0MTc=" } ], "messages": [ { "id": "M2s4da2y4P", "message_status": "accepted" } ] } Field Descriptions messaging_product: Type: String Description: Indicates the messaging platform. Always returns whatsapp for messages sent via the WhatsApp Business API. contacts: Type: Array Description: Contains information about the message recipient(s). Fields: input: Type: String Description: The phone number input used in the API request (e.g., 91xxxxxxxxxx). wa_id: Type: String Description: The WhatsApp ID associated with the input phone number. status_id: Type: String Description: A unique identifier for the status of the message. messages: Type: Array Description: Contains details about the sent message. Fields: id: Type: String Description: A unique identifier for the message sent (e.g., M2s4da2y4P). message_status: Type: String Description: The status of the message at the time of the response. Example values include: accepted: The message was successfully accepted by the system. Sample codes CURL PHP Java Ruby Python C# Node JS curl –location ‘https://example.com/api/v1.0/phone_number_id/key/messages’ \ –header ‘Content-Type: application/json’ \ –header ‘Authorization: Bearer xxxxxxxxxxx…………..’ \ –header ‘Cookie: XSRF-TOKEN=xxxxxxxxxxx…………..’ \ –data ‘{ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “utility_full_template”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12345” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”:”BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://chat.pingtochat.com/” } ] } ] } }’ ‘<'+'?'+'php'+ ` $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => ‘https://example.com/api/v1.0/phone_number_id/key/messages’, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => ”, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => ‘POST’, CURLOPT_POSTFIELDS =>'{ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “utility_full_template”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12345” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”:”BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://chat.pingtochat.com/” } ] } ] } }’, CURLOPT_HTTPHEADER => array( ‘Content-Type: application/json’, ‘Authorization: Bearer xxxxxxxxxxx…………..’, ‘Cookie: XSRF-TOKEN=xxxxxxxxxxx…………..’ ), )); $response = curl_exec($curl); curl_close($curl); echo $response; ?>;`; OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse(“application/json”); RequestBody body = RequestBody.create(mediaType, “{\r\n \”messaging_product\”: \”whatsapp\”,\r\n \”recipient_type\”: \”individual\”,\r\n \”to\”: \”91xxxxxxxxxx\”,\r\n \”type\”: \”template\”,\r\n \”template\”: {\r\n \”name\”: \”utility_full_template\”,\r\n \”language\”: {\r\n \”code\”: \”en\”\r\n },\r\n \”components\”: [\r\n {\r\n \”type\”: \”body\”,\r\n \”parameters\”: [\r\n {\r\n \”type\”: \”text\”,\r\n \”text\”: \”12345\”\r\n }\r\n \r\n ]\r\n },\r\n {\r\n \”type\”: \”header\”,\r\n \”parameters\”: [\r\n {\r\n \”type\”: \”image\”,\r\n \”image\”: {\r\n \”link\”: \”https://chat.pingtochat.com/template_media/1736424548.png\”\r\n }\r\n }\r\n ]\r\n },\r\n {\r\n \”type\”:\”BUTTONS\”,\r\n \”buttons\”: [\r\n {\r\n \”type\”: \”QUICK_REPLY\”,\r\n \”text\”: \”Unsubscribe from Promos\”\r\n },\r\n \r\n {\r\n \”type\”: \”url\”,\r\n \”text\”: \”Go to link\”,\r\n \”url\”: \”https://chat.pingtochat.com/\”\r\n \r\n }\r\n ]\r\n } \r\n ]\r\n }\r\n}”); Request request = new Request.Builder() .url(“https://example.com/api/v1.0/phone_number_id/key/messages”) .method(“POST”, body) .addHeader(“Content-Type”, “application/json”) .addHeader(“Authorization”, “Bearer xxxxxxxxxxx…………..”) .addHeader(“Cookie”, “XSRF-TOKEN=xxxxxxxxxxx…………..”) .build(); Response response = client.newCall(request).execute(); require “uri” require “json” require “net/http” url = URI(“https://example.com/api/v1.0/phone_number_id/key/messages”) https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Post.new(url) request[“Content-Type”] = “application/json” request[“Authorization”] = “Bearer xxxxxxxxxxx…………..” request[“Cookie”] = “XSRF-TOKEN=xxxxxxxxxxx…………..” request.body = JSON.dump({ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “utility_full_template”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12345” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”: “BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://chat.pingtochat.com/” } ] } ] } }) response = https.request(request) puts response.read_body import requests import json url = “https://example.com/api/v1.0/phone_number_id/key/messages” payload = json.dumps({ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “utility_full_template”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12345” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”: “BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://chat.pingtochat.com/” } ] } ] } }) headers = { ‘Content-Type’: ‘application/json’, ‘Authorization’: ‘Bearer xxxxxxxxxxx…………..’, ‘Cookie’: ‘XSRF-TOKEN=xxxxxxxxxxx…………..’ } response = requests.request(“POST”, url, headers=headers, data=payload) print(response.text) var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, “https://example.com/api/v1.0/phone_number_id/key/messages”); request.Headers.Add(“Authorization”, “Bearer xxxxxxxxxxx…………..”); request.Headers.Add(“Cookie”, “XSRF-TOKEN=xxxxxxxxxxx…………..”); var content = new StringContent(“{\r\n \”messaging_product\”: \”whatsapp\”,\r\n \”recipient_type\”: \”individual\”,\r\n \”to\”: \”91xxxxxxxxxx\”,\r\n \”type\”: \”template\”,\r\n \”template\”: {\r\n \”name\”: \”utility_full_template\”,\r\n \”language\”: {\r\n \”code\”: \”en\”\r\n },\r\n \”components\”: [\r\n {\r\n \”type\”: \”body\”,\r\n \”parameters\”: [\r\n {\r\n \”type\”: \”text\”,\r\n \”text\”: \”12345\”\r\n }\r\n \r\n ]\r\n },\r\n {\r\n \”type\”: \”header\”,\r\n \”parameters\”: [\r\n {\r\n \”type\”: \”image\”,\r\n \”image\”: {\r\n \”link\”: \”https://chat.pingtochat.com/template_media/1736424548.png\”\r\n }\r\n }\r\n ]\r\n },\r\n {\r\n \”type\”:\”BUTTONS\”,\r\n \”buttons\”: [\r\n {\r\n \”type\”: \”QUICK_REPLY\”,\r\n \”text\”: \”Unsubscribe from Promos\”\r\n },\r\n \r\n {\r\n \”type\”: \”url\”,\r\n \”text\”: \”Go to link\”,\r\n \”url\”: \”https://chat.pingtochat.com/\”\r\n \r\n }\r\n ]\r\n } \r\n ]\r\n }\r\n}”, null, “application/json”); request.Content = content; var response = await client.SendAsync(request); response.EnsureSuccessStatusCode(); Console.WriteLine(await response.Content.ReadAsStringAsync()); var request = require(‘request’); var options = { ‘method’: ‘POST’, ‘url’: ‘https://example.com/api/v1.0/phone_number_id/key/messages’, ‘headers’: { ‘Content-Type’: ‘application/json’, ‘Authorization’: ‘Bearer xxxxxxxxxxx…………..’, ‘Cookie’: ‘XSRF-TOKEN=xxxxxxxxxxx…………..’ }, body: JSON.stringify({ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “utility_full_template”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12345” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”: “BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://chat.pingtochat.com/” } ] } ] } }) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });