Message with parameter Estimated reading: 3 minutes 58 views Description:Send a template message that includes dynamic text parameters.Endpoint:http://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/messagesReplace the placeholders:{{key}}: Your API key for authentication.How to create key{{your_domain}}: Your API domain.{{phone_number_id}}: The ID linked to your WhatsApp Business API number.Example Payload:{ "messaging_product": "whatsapp", "recipient_type": "individual", "to": "91xxxxxxxxxx", "type": "template", "template": { "name": "utility_template_variable", "language": { "code": "en" }, "components": [ { "type": "header", "parameters": [ { "type": "text", "text": "User_Name" } ] }, { "type": "body", "parameters": [ { "type": "text", "text": "adv45667" } ] } ] } }Field Breakdown:messaging_product: Specifies the messaging product, always "whatsapp". recipient_type: "individual" for single-user messages. to: The recipient’s phone number in E.164 format (e.g., 91xxxxxxxxxx). type: "template" for sending a template message. template:name: The name of the pre-approved template (marketing_newyear_va in this case). language:code: The language code of the template (e.g., en for English). components:type: Specifies the part of the template being populated. Use "body" for main content placeholders. parameters: Contains dynamic data to replace placeholders in the template:type: The type of data (e.g., "text"). text: The value that replaces the placeholder in the template.Dynamic Parameters and PlaceholdersTemplates can include dynamic placeholders represented as variables like {{1}}, {{2}}, etc. Each placeholder is replaced by the corresponding value in the parameters array.Template Example:Template name: utility_template_variableTemplate content:Hi {{1}}, Your Order number {{2}} is 24-oct-2024 deleveredExample:"parameters": [ { "type": "text", "text": "user_name" // Replaces {{1}} }, { "type": "text", "text": "adv45667" // Replaces {{2}} } ] Resulting message:Hi user_name, Your Order number adv45667 is 24-oct-2024 delevered.Response StructureA successful API call returns a 200 OK response with details about the sent message.Example Response:{ "messaging_product": "whatsapp", "contacts": [ { "input": "91xxxxxxxxxx", "wa_id": "91xxxxxxxxxx", "status_id": "ODIxMTc=" } ], "messages": [ { "id": "SD7mtgA4PH", "message_status": "accepted" } ] }Response Details:contacts:input: The phone number from the to field. wa_id: WhatsApp ID of the recipient. status_id: Identifier for the delivery status. messages:id: A unique identifier for the message. message_status: Status of the message, e.g., "accepted".Notes and Best PracticesPre-approved Templates:Templates must be created and approved in the WhatsApp Business Manager. Ensure placeholders ({{1}}, {{2}}, etc.) align with the payload. Dynamic Content:Use the parameters array to customize messages. Include text, media, or buttons as required by your template. Language Codes:Match the language code with the template’s approved language. Full list of ISO 639-1 codes. Testing:Use a sandbox environment to test integrations. Validate payloads and monitor logs for issues. 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 xxxxxx……’ \ –data ‘{ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “utility_b”, “language”: { “code”: “en_us” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12CR007” } ] } ] } } ‘ ‘<'+'?'+'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_b”, “language”: { “code”: “en_us” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12CR007” } ] } ] } } ‘, CURLOPT_HTTPHEADER => array( ‘Content-Type: application/json’, ‘Authorization: Bearer xxxxx…..’ ), )); $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_b\”,\r\n \”language\”: {\r\n \”code\”: \”en_us\”\r\n },\r\n \”components\”: [\r\n {\r\n \”type\”: \”body\”,\r\n \”parameters\”: [\r\n {\r\n \”type\”: \”text\”,\r\n \”text\”: \”12CR007\”\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 xxxxxxx……….”) .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 xxxxxx………” request.body = JSON.dump({ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “utility_b”, “language”: { “code”: “en_us” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12CR007” } ] } ] } }) 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_b”, “language”: { “code”: “en_us” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12CR007” } ] } ] } }) headers = { ‘Content-Type’: ‘application/json’, ‘Authorization’: ‘Bearer xxxxxx…………’ } 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/keymessages”); request.Headers.Add(“Authorization”, “Bearer xxxxxxx………”); 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_b\”,\r\n \”language\”: {\r\n \”code\”: \”en_us\”\r\n },\r\n \”components\”: [\r\n {\r\n \”type\”: \”body\”,\r\n \”parameters\”: [\r\n {\r\n \”type\”: \”text\”,\r\n \”text\”: \”12CR007\”\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 xxxxxxx………..’ }, body: JSON.stringify({ “messaging_product”: “whatsapp”, “recipient_type”: “individual”, “to”: “91xxxxxxxxxx”, “type”: “template”, “template”: { “name”: “utility_b”, “language”: { “code”: “en_us” }, “components”: [ { “type”: “body”, “parameters”: [ { “type”: “text”, “text”: “12CR007” } ] } ] } }) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });