Session Message Estimated reading: 2 minutes 85 views A session message in WhatsApp refers to any message exchanged between a business and a customer within a 24-hour messaging window that starts when the customer sends a message to the business. These messages are not pre-approved by WhatsApp and can include free-form text, media, or interactive content.URLhttp://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/simpleMessagesMethodPOSTHeadersContent-Type: application/json Authorization: Bearer <your_access_token>Request PayloadsSending a Text MessageThe payload for sending a plain text message via the WhatsApp API is structured as follows:Example :{ "messaging_product": "whatsapp", "to": "91xxxxxxxxxx", "type": "text", "text": { "body": "Hello!" } } Field Descriptionsmessaging_product: (string) Specifies the messaging product. For WhatsApp, this is always whatsapp. to: (string) The recipient’s phone number in E.164 format. Example: 919880132082. type: (string) The type of message being sent. Use text for plain text messages. text: (object) Contains the message text.body: (string) The text message content. Example: "Hello!".ResponseExample Success ResponseA successful request returns a 200 OK status and a response payload similar to the following:{ "messaging_product": "whatsapp", "contacts": [ { "input": "91xxxxxxxxxx", "wa_id": "91xxxxxxxxxx" } ], "messages": [ { "id": "RfzuNs4qpN" } ] } Field Descriptionsmessaging_product: (string) The messaging product used. Always whatsapp. contacts: (array) Contains information about the recipient.input: (string) The phone number you provided in the request. wa_id: (string) The WhatsApp ID associated with the provided phone number. messages: (array) Contains information about the sent message.id: (string) The unique identifier for the sent message.NotesDomain and Credentials: Replace {{your_domain}}, {{phone_number_id}}, and {{key}} with your API domain, phone number ID, and API key respectively. Rate Limits: Ensure your API calls comply with the rate limits set by WhatsApp to avoid being throttled. Session Window: Text messages can only be sent within a 24-hour window of the last user interaction. Template Pre-Approval: For template messages, ensure they are approved in the WhatsApp Business Manager before use. Language Code Matching: Language codes in templates must match the approved template language. Sample codes CURL PHP Java Ruby Python C# Node JS curl –location ‘https://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/messages’ \ –header ‘Content-Type: application/json’ \ –header ‘Authorization: Bearer xxxxxxxxxxxxx………………….’ \ –data ‘{ “messaging_product”: “whatsapp”, “to”: “91xxxxxxxxxx”, “type”: “text”, “text”: { “body”: “Hello!” } }’ ‘<'+'?'+'php'+ ` $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => ‘https://{{your_domain}}/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”, “to”: “91xxxxxxxxxx”, “type”: “text”, “text”: { “body”: “Hello!” } }’, CURLOPT_HTTPHEADER => array( ‘Content-Type: application/json’, ‘Authorization: Bearer xxxxxxxxxxxxx………………….’ ), )); $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 \”to\”: \”91xxxxxxxxxx\”,\r\n \”type\”: \”text\”,\r\n \”text\”: {\r\n \”body\”: \”Hello!\”\r\n }\r\n}”); Request request = new Request.Builder() .url(“https://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/messages”) .method(“POST”, body) .addHeader(“Content-Type”, “application/json”) .addHeader(“Authorization”, “Bearer xxxxxxxxxxxxx………………….”) .build(); Response response = client.newCall(request).execute(); require “uri” require “json” require “net/http” url = URI(“https://{{your_domain}}/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 xxxxxxxxxxxxx………………….” request.body = JSON.dump({ “messaging_product”: “whatsapp”, “to”: “91xxxxxxxxxx”, “type”: “text”, “text”: { “body”: “Hello!” } }) response = https.request(request) puts response.read_body import requests import json url = “https://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/messages” payload = json.dumps({ “messaging_product”: “whatsapp”, “to”: “91xxxxxxxxxx”, “type”: “text”, “text”: { “body”: “Hello!” } }) headers = { ‘Content-Type’: ‘application/json’, ‘Authorization’: ‘Bearer xxxxxxxxxxxxx………………….’ } response = requests.request(“POST”, url, headers=headers, data=payload) print(response.text) var client = new HttpClient(); var request = new HttpRequestMessage(HttpMethod.Post, “https://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/messages”); request.Headers.Add(“Authorization”, “Bearer xxxxxxxxxxxxx………………….”); var content = new StringContent(“{\r\n \”messaging_product\”: \”whatsapp\”,\r\n \”to\”: \”91xxxxxxxxxx\”,\r\n \”type\”: \”text\”,\r\n \”text\”: {\r\n \”body\”: \”Hello!\”\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://{{your_domain}}/api/v1.0/{{phone_number_id}}/{{key}}/messages’, ‘headers’: { ‘Content-Type’: ‘application/json’, ‘Authorization’: ‘Bearer xxxxxxxxxxxxx………………….’ }, body: JSON.stringify({ “messaging_product”: “whatsapp”, “to”: “91xxxxxxxxxx”, “type”: “text”, “text”: { “body”: “Hello!” } }) }; request(options, function (error, response) { if (error) throw new Error(error); console.log(response.body); });