Message with parameters, attachments, and with buttons Estimated reading: 3 minutes 81 views Description:Send a basic template message with any parameters.Endpoint:http://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/messagesReplace the placeholders:{{your_domain}}: Your API domain. {{phone_number_id}}: The ID linked to your WhatsApp Business API number. {{key}}: Your API key for authentication.How to create keyMethod:POSTHeaders:Content-Type: application/json Authorization: Bearer <your_access_token>Example :{ "messaging_product": "whatsapp", "recipient_type": "individual", "to": "91xxxxxxxxxx", "type": "template", "template": { "name": "marketing_newyear_va_images", "language": { "code": "en" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "User_Name" }, { "type": "text", "text": "Features" } ] }, { "type": "header", "parameters": [ { "type": "image", "image": { "link": "https://chat.pingtochat.com/template_media/1736424548.png" } } ] }, { "type": "FOOTER", "text": "Use the buttons below to visit our website" }, { "type":"BUTTONS", "buttons": [ { "type": "QUICK_REPLY", "text": "Unsubscribe from Promos" }, { "type": "url", "text": "Go to link", "url": "https://developers.pingtochat.com/" } ] } ] } }Key Points in the PayloadComponents:header: Includes an image URL. body: Contains text with placeholders replaced by dynamic values. footer: Simple static text. buttons: Supports two types of buttons:QUICK_REPLY: For quick interactions. URL: Redirects to a specific URL. Parameters:The parameters inside header and body match the placeholders defined in the template. URL Requirements:The URL in the buttons section must be publicly accessible. Template Approval:Templates (e.g., marketing_newyear_va_images) must be pre-approved.ResponseA 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 Descriptionsmessaging_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 seMessages Without Buttonsnt 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 eyJpdiI6IndwTkFXZUdiY3BNdWUwMnhDem04eGc9PSIsInZhbHVlIjoiQ3c2aDYxYWxBQmtRSkVGNllRRGpOUT09IiwibWFjIjoiMzk4ODRlMmY4ZDEzODAyODFjNThlYmQwMzEyMzYyYjUwNjk0NzE3YWU5NzRkOGE4ODE5NWZmYTg3ZDBmNjk0MCIsInRhZyI6IiJ9’ \ –data ‘{ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “marketing_newyear_va_images”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “User_Name” }, { “type”: “text”, “text”: “Features” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”: “FOOTER”, “text”: “Use the buttons below to visit our website” }, { “type”:”BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://developers.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”: “marketing_newyear_va_images”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “User_Name” }, { “type”: “text”, “text”: “Features” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”: “FOOTER”, “text”: “Use the buttons below to visit our website” }, { “type”:”BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://developers.pingtochat.com/” } ] } ] } }’, CURLOPT_HTTPHEADER => array( ‘Content-Type: application/json’, ‘Authorization: Bearer eyJpdiI6IndwTkFXZUdiY3BNdWUwMnhDem04eGc9PSIsInZhbHVlIjoiQ3c2aDYxYWxBQmtRSkVGNllRRGpOUT09IiwibWFjIjoiMzk4ODRlMmY4ZDEzODAyODFjNThlYmQwMzEyMzYyYjUwNjk0NzE3YWU5NzRkOGE4ODE5NWZmYTg3ZDBmNjk0MCIsInRhZyI6IiJ9’ ), )); $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, “{\n \”messaging_product\”: \”whatsapp\”,\n \”recipient_type\”: \”individual\”,\n \”to\”: \”91xxxxxxxxxx\”,\n \”type\”: \”template\”,\n \”template\”: {\n \”name\”: \”marketing_newyear_va_images\”,\n \”language\”: {\n \”code\”: \”en\”\n },\n \”components\”: [\n {\n \”type\”: \”body\”,\n \”parameters\”: [\n {\n \”type\”: \”text\”,\n \”text\”: \”User_Name\”\n },\n {\n \”type\”: \”text\”,\n \”text\”: \”Features\”\n }\n ]\n },\n {\n \”type\”: \”header\”,\n \”parameters\”: [\n {\n \”type\”: \”image\”,\n \”image\”: {\n \”link\”: \”https://chat.pingtochat.com/template_media/1736424548.png\”\n }\n }\n ]\n },\n {\n \”type\”: \”FOOTER\”,\n \”text\”: \”Use the buttons below to visit our website\”\n },\n {\n \”type\”:\”BUTTONS\”,\n \”buttons\”: [\n {\n \”type\”: \”QUICK_REPLY\”,\n \”text\”: \”Unsubscribe from Promos\”\n },\n {\n \”type\”: \”url\”,\n \”text\”: \”Go to link\”,\n \”url\”: \”https://developers.pingtochat.com/\”\n }\n \n ]\n }\n ]\n }\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 eyJpdiI6IndwTkFXZUdiY3BNdWUwMnhDem04eGc9PSIsInZhbHVlIjoiQ3c2aDYxYWxBQmtRSkVGNllRRGpOUT09IiwibWFjIjoiMzk4ODRlMmY4ZDEzODAyODFjNThlYmQwMzEyMzYyYjUwNjk0NzE3YWU5NzRkOGE4ODE5NWZmYTg3ZDBmNjk0MCIsInRhZyI6IiJ9”) .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 eyJpdiI6IndwTkFXZUdiY3BNdWUwMnhDem04eGc9PSIsInZhbHVlIjoiQ3c2aDYxYWxBQmtRSkVGNllRRGpOUT09IiwibWFjIjoiMzk4ODRlMmY4ZDEzODAyODFjNThlYmQwMzEyMzYyYjUwNjk0NzE3YWU5NzRkOGE4ODE5NWZmYTg3ZDBmNjk0MCIsInRhZyI6IiJ9” request.body = JSON.dump({ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “marketing_newyear_va_images”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “User_Name” }, { “type”: “text”, “text”: “Features” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”: “FOOTER”, “text”: “Use the buttons below to visit our website” }, { “type”: “BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://developers.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”: “marketing_newyear_va_images”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “User_Name” }, { “type”: “text”, “text”: “Features” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”: “FOOTER”, “text”: “Use the buttons below to visit our website” }, { “type”: “BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://developers.pingtochat.com/” } ] } ] } }) headers = { ‘Content-Type’: ‘application/json’, ‘Authorization’: ‘Bearer eyJpdiI6IndwTkFXZUdiY3BNdWUwMnhDem04eGc9PSIsInZhbHVlIjoiQ3c2aDYxYWxBQmtRSkVGNllRRGpOUT09IiwibWFjIjoiMzk4ODRlMmY4ZDEzODAyODFjNThlYmQwMzEyMzYyYjUwNjk0NzE3YWU5NzRkOGE4ODE5NWZmYTg3ZDBmNjk0MCIsInRhZyI6IiJ9’ } 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 eyJpdiI6IndwTkFXZUdiY3BNdWUwMnhDem04eGc9PSIsInZhbHVlIjoiQ3c2aDYxYWxBQmtRSkVGNllRRGpOUT09IiwibWFjIjoiMzk4ODRlMmY4ZDEzODAyODFjNThlYmQwMzEyMzYyYjUwNjk0NzE3YWU5NzRkOGE4ODE5NWZmYTg3ZDBmNjk0MCIsInRhZyI6IiJ9”); var content = new StringContent(“{\n \”messaging_product\”: \”whatsapp\”,\n \”recipient_type\”: \”individual\”,\n \”to\”: \”91xxxxxxxxxx\”,\n \”type\”: \”template\”,\n \”template\”: {\n \”name\”: \”marketing_newyear_va_images\”,\n \”language\”: {\n \”code\”: \”en\”\n },\n \”components\”: [\n {\n \”type\”: \”body\”,\n \”parameters\”: [\n {\n \”type\”: \”text\”,\n \”text\”: \”User_Name\”\n },\n {\n \”type\”: \”text\”,\n \”text\”: \”Features\”\n }\n ]\n },\n {\n \”type\”: \”header\”,\n \”parameters\”: [\n {\n \”type\”: \”image\”,\n \”image\”: {\n \”link\”: \”https://chat.pingtochat.com/template_media/1736424548.png\”\n }\n }\n ]\n },\n {\n \”type\”: \”FOOTER\”,\n \”text\”: \”Use the buttons below to visit our website\”\n },\n {\n \”type\”:\”BUTTONS\”,\n \”buttons\”: [\n {\n \”type\”: \”QUICK_REPLY\”,\n \”text\”: \”Unsubscribe from Promos\”\n },\n {\n \”type\”: \”url\”,\n \”text\”: \”Go to link\”,\n \”url\”: \”https://developers.pingtochat.com/\”\n }\n \n ]\n }\n ]\n }\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 eyJpdiI6IndwTkFXZUdiY3BNdWUwMnhDem04eGc9PSIsInZhbHVlIjoiQ3c2aDYxYWxBQmtRSkVGNllRRGpOUT09IiwibWFjIjoiMzk4ODRlMmY4ZDEzODAyODFjNThlYmQwMzEyMzYyYjUwNjk0NzE3YWU5NzRkOGE4ODE5NWZmYTg3ZDBmNjk0MCIsInRhZyI6IiJ9’ }, body: JSON.stringify({ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “marketing_newyear_va_images”, “language”: { “code”: “en” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “User_Name” }, { “type”: “text”, “text”: “Features” } ] }, { “type”: “header”, “parameters”: [ { “type”: “image”, “image”: { “link”: “https://chat.pingtochat.com/template_media/1736424548.png” } } ] }, { “type”: “FOOTER”, “text”: “Use the buttons below to visit our website” }, { “type”: “BUTTONS”, “buttons”: [ { “type”: “QUICK_REPLY”, “text”: “Unsubscribe from Promos” }, { “type”: “url”, “text”: “Go to link”, “url”: “https://developers.pingtochat.com/” } ] } ] } }) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });