### Get All Templates - cURL Example Source: https://docs.smsbox.dev/whatsapp This cURL command demonstrates how to retrieve all message templates associated with a WhatsApp Business Agent. You need to provide the `wabaId`, `phoneId`, and your `APIKEY`. The request method is GET. ```curl curl --request GET \ --url https://api.wababox.net/waba/1.1/json//template/ \ --header 'Authorization: App ' \ --header 'Content-Type: application/json' ``` -------------------------------- ### Get All Templates - Python Example Source: https://docs.smsbox.dev/whatsapp This Python code snippet shows how to fetch all message templates using the SMSBox API. It makes a GET request to the specified endpoint. Ensure you replace the placeholder values for `wabaId`, `phoneId`, and `APIKEY`. ```python import requests url = "https://api.wababox.net/waba/1.1/json/{wabaId}/template/{phoneId}" headers = { "Authorization": "App ", "Content-Type": "application/json" } response = requests.get(url, headers=headers) print(response.json()) ``` -------------------------------- ### Get All Templates - PHP Example Source: https://docs.smsbox.dev/whatsapp This PHP code demonstrates how to fetch all message templates using the SMSBox API. It utilizes cURL to send a GET request to the templates endpoint. Ensure you update the `wabaId`, `phoneId`, and `APIKEY` variables. ```php '; $url = "https://api.wababox.net/waba/1.1/json/{$wabaId}/template/{$phoneId}"; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: App {$apiKey}", "Content-Type: application/json" ]); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); } c_lose($ch); echo $response; ?> ``` -------------------------------- ### Get All Templates - JavaScript Example Source: https://docs.smsbox.dev/whatsapp This JavaScript code uses the `fetch` API to retrieve all message templates from the SMSBox API. Replace the `wabaId`, `phoneId`, and `apiKey` variables with your actual credentials. ```javascript async function getAllTemplates() { const url = `https://api.wababox.net/waba/1.1/json/${wabaId}/template/${phoneId}`; const apiKey = ''; try { const response = await fetch(url, { method: 'GET', headers: { 'Authorization': `App ${apiKey}`, 'Content-Type': 'application/json' } }); const data = await response.json(); console.log(data); } catch (error) { console.error('Error fetching templates:', error); } } ``` -------------------------------- ### Add Tester - cURL Example Source: https://docs.smsbox.dev/rcs Example of adding a tester using cURL to the RCS API. Demonstrates a POST request with the agent ID, API key, and a JSON payload containing the tester's recipient identifier. ```curl curl -X POST \ https://api.rcsbox.net/rcs/1.0/json/{agentId}/add-testers \ -H 'Content-Type: application/json' \ -H 'x-api-key: YOUR_API_KEY' \ -d '{ "recipients": [ "string" ] }' ``` -------------------------------- ### Retrieve File with cURL Source: https://docs.smsbox.dev/whatsapp Example cURL command to retrieve a file. This demonstrates the POST request to the file endpoint, including the API key and the JSON payload with the file ID. ```bash curl -X POST 'https://api.wababox.net/waba/1.1/json/{wabaId}/file/{phoneID}' \ -H 'Authorization: ApiKey YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "file_id": "1234567890" }' ``` -------------------------------- ### Send Image Message Request - cURL Source: https://docs.smsbox.dev/whatsapp Example cURL command to send an image message. This shows the HTTP POST request setup with the necessary authentication and content type headers, along with the image payload. ```curl curl -X POST https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID} \ -H "Authorization: ApiKey YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "recipients": [ "+336XXXXXXXX" ], "contentMessage": { "type": "image", "image": { "link": "https://www.example.com/fr/file.jpeg", "filename": "file.jpeg" } } }' ``` -------------------------------- ### Add Tester - Python Example Source: https://docs.smsbox.dev/rcs Python script to add a tester using the RCS API. It utilizes the `requests` library to send a POST request with the tester's recipient information. ```python import requests url = "https://api.rcsbox.net/rcs/1.0/json/{agentId}/add-testers" headers = { "Content-Type": "application/json", "x-api-key": "YOUR_API_KEY" } payload = { "recipients": [ "string" ] } response = requests.post(url, headers=headers, json=payload) print(response.status_code) print(response.json()) ``` -------------------------------- ### Capabilities Check Request Samples Source: https://docs.smsbox.dev/rcs Samples for making a capabilities check request to the RCS API. Includes payload, cURL, Python, JavaScript, and PHP examples. The request body expects an array of recipients. ```json { "recipients": [ "string" ] } ``` ```shell curl -X POST https://api.rcsbox.net/rcs/1.0/json/{agentId}/capabilities \ -H "Content-Type: application/json" \ -d '{ "recipients": [ "string" ] }' ``` ```python import requests url = "https://api.rcsbox.net/rcs/1.0/json/{agentId}/capabilities" headers = { "Content-Type": "application/json" } data = { "recipients": [ "string" ] } response = requests.post(url, headers=headers, json=data) print(response.json()) ``` ```javascript const url = "https://api.rcsbox.net/rcs/1.0/json/{agentId}/capabilities"; const data = { "recipients": [ "string" ] }; fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => console.log(data)); ``` ```php ['string'] ]); $options = [ 'http' => [ 'header' => "Content-type: application/json\r\n", 'method' => 'POST', 'content' => $data ] ]; $context = stream_context_create($options); $result = file_get_contents($url, false, $context); var_dump($result); ?> ``` -------------------------------- ### Send Sticker Message Request - cURL Source: https://docs.smsbox.dev/whatsapp cURL command example for sending a sticker message. It demonstrates how to configure the HTTP POST request, including authentication, content type, and the JSON payload. ```curl curl -X POST https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID} \ -H "Authorization: ApiKey YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "recipients": [ "+336XXXXXXXX" ], "contentMessage": { "type": "sticker", "sticker": { "link": "https://www.example.com/fr/file.webp", "filename": "file.webp" } } }' ``` -------------------------------- ### Send Sticker Message Request - JavaScript Source: https://docs.smsbox.dev/whatsapp JavaScript example using the fetch API to send a sticker message. This code demonstrates making an asynchronous POST request with appropriate headers and the JSON request body. ```javascript const url = "https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID}"; const apiKey = "YOUR_API_KEY"; const payload = { "recipients": [ "+336XXXXXXXX" ], "contentMessage": { "type": "sticker", "sticker": { "link": "https://www.example.com/fr/file.webp", "filename": "file.webp" } } }; fetch(url, { method: "POST", headers: { "Authorization": `ApiKey ${apiKey}`, "Content-Type": "application/json" }, body: JSON.stringify(payload) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Add Tester - JavaScript Example Source: https://docs.smsbox.dev/rcs JavaScript code snippet for adding a tester via the RCS API using `fetch`. It configures the POST request with the agent ID, API key, and the tester's recipient details in the JSON body. ```javascript const agentId = "YOUR_AGENT_ID"; const apiKey = "YOUR_API_KEY"; fetch(`https://api.rcsbox.net/rcs/1.0/json/${agentId}/add-testers`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey }, body: JSON.stringify({ "recipients": [ "string" ] }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Send Text Message - cURL Example Source: https://docs.smsbox.dev/rcs Example of sending a text message using cURL to the RCS API. It demonstrates the POST request with necessary headers and the JSON payload. ```curl curl -X POST \ https://api.rcsbox.net/rcs/1.0/json/{agentId}/message \ -H 'Content-Type: application/json' \ -H 'x-api-key: YOUR_API_KEY' \ -d '{ "recipients": [ "+336XXXXXXXX" ], "contentMessage": { }, "validity": 720 }' ``` -------------------------------- ### Send Interactive Button Message - cURL Source: https://docs.smsbox.dev/whatsapp Example of sending an interactive button message using cURL. This demonstrates the structure for creating messages with clickable buttons. ```bash curl -X POST https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID} \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "type": "interactive", "interactive": { "type": "button", "header": { "type": "text", "text": { "body": "Message sent via my WhatsApp Business agent." } }, "body": { "text": "string" }, "footer": { "text": "string" }, "action": { "buttons": [ { "type": "reply", "reply": { "id": "string", "title": "string" } } ] } } }' ``` -------------------------------- ### Add Tester - PHP Example Source: https://docs.smsbox.dev/rcs PHP script to add a tester using the RCS API. It uses cURL to perform the POST request, sending the tester's recipient information in JSON format. ```php ["string"] ]; $payload = json_encode($data); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', "x-api-key: {$apiKey}" ]); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); } c_close($ch); echo $response; ?> ``` -------------------------------- ### Send SMS Message with cURL Source: https://docs.smsbox.dev/whatsapp Example cURL command for sending an SMS message using the SMSBox API. This demonstrates the HTTP POST request with necessary headers and the JSON payload. ```bash curl -X POST 'https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID}' \ -H 'Authorization: ApiKey YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "recipients": ["+336XXXXXXXX"], "contentMessage": { "type": "template", "template": { "name": "otp", "language": { "code": "en" }, "components": [ { "type": "body", "parameters": [ { "type": "text", "text": "123456" } ] }, { "type": "button", "sub_type": "url", "index": "0", "parameters": [ { "type": "text", "text": "123456" } ] } ] } } }' ``` -------------------------------- ### Send Reaction Message - Python Source: https://docs.smsbox.dev/whatsapp Python code snippet for sending a reaction message. This example uses the `requests` library to send an emoji reaction to a message. ```python import requests url = "https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID}" headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" } payload = { "recipients": ["+336XXXXXXXX"], "contentMessage": { "type": "reaction", "reaction": { "message_id": "wamid.xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "emoji": "😀" } } } response = requests.post(url, headers=headers, json=payload) print(response.json()) ``` -------------------------------- ### Send Text Message - JavaScript Example Source: https://docs.smsbox.dev/rcs JavaScript code snippet for sending a text message via the RCS API using `fetch`. It includes setting the request method, headers, and the JSON body. ```javascript const agentId = "YOUR_AGENT_ID"; const apiKey = "YOUR_API_KEY"; fetch(`https://api.rcsbox.net/rcs/1.0/json/${agentId}/message`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': apiKey }, body: JSON.stringify({ "recipients": [ "+336XXXXXXXX" ], "contentMessage": {}, "validity": 720 }) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### GET /waba/1.1/json/{wabaId}/template/{phoneId} Source: https://docs.smsbox.dev/whatsapp Retrieve all message templates associated with a WhatsApp Business Agent. This endpoint is useful for managing and reviewing available message templates. ```APIDOC ## GET /waba/1.1/json/{wabaId}/template/{phoneId} ### Description Retrieve all message templates associated with a WhatsApp Business Agent. This endpoint is useful for managing and reviewing available message templates. ### Method GET ### Endpoint https://api.wababox.net/waba/1.1/json/{wabaId}/template/{phoneId} ### Parameters #### Path Parameters - **wabaId** (string) - Required - WhatsApp Business Agent ID - **phoneId** (string) - Required - WhatsApp Business Agent's Phone Number ID ### Request Example ```curl curl --request GET \ --url https://api.wababox.net/waba/1.1/json//template/ \ --header 'Authorization: App ' \ --header 'Content-Type: application/json' ``` ### Response #### Success Response (200) - **response** (object) - Contains response code and description. - **response_code** (string) - "200" - **response_desc** (string) - "Request successfully processed." - **details** (string) - "List of the agent's templates" - **data** (array) - Array of template objects. - **name** (string) - Template name. - **language** (string) - Template language (e.g., "en_US"). - **components** (array) - Template components. - **type** (string) - Component type (e.g., "BODY"). - **parameters** (object or null) - Parameters for the component. - **status** (string) - Template status (e.g., "APPROVED"). - **category** (string) - Template category (e.g., "UTILITY"). - **id** (string) - Unique template ID. #### Response Example ```json { "response": { "response_code": "200", "response_desc": "Request successfully processed." }, "details": "List of the agent's templates", "data": [ { "name": "myTemplate", "language": "en_US", "components": [ { "type": "BODY", "parameters": null } ], "status": "APPROVED", "category": "UTILITY", "id": "xxxxxxxxxxxxxxxx" } ] } ``` #### Error Responses - **400**: Wrong query syntax or missing mandatory field. - **403**: Access to the requested resource has been denied. - **404**: The requested resource was not found. - **405**: The requested method is not supported for the requested resource. - **503**: Service temporarily unavailable. ``` -------------------------------- ### Send Document Message Request - cURL Source: https://docs.smsbox.dev/whatsapp Example of sending a document message using cURL. This demonstrates how to structure the HTTP request with the JSON payload and necessary headers for authentication and content type. ```curl curl -X POST https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID} \ -H "Authorization: ApiKey YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "recipients": [ "+336XXXXXXXX" ], "contentMessage": { "type": "document", "document": { "link": "https://www.example.com/fr/file.pdf", "filename": "file.pdf" } } }' ``` -------------------------------- ### Send OTP Message - cURL Example Source: https://docs.smsbox.dev/whatsapp This cURL command shows how to send an OTP message via the SMSBox API. Replace `{wabaId}`, `{phoneID}`, and `` with your specific details. The request body should contain the `recipients` and `contentMessage` fields. ```curl curl --request POST \ --url https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID} \ --header 'Authorization: App ' \ --header 'Content-Type: application/json' \ --data '{ "recipients": ["+1234567890"], "contentMessage": {...} // OTPTemplateMessage structure }' ``` -------------------------------- ### Send Document Message Request - PHP Source: https://docs.smsbox.dev/whatsapp PHP code example for sending a document message using cURL. This illustrates how to set up the request parameters, headers, and data to interact with the SMSBox API. ```php [ "+336XXXXXXXX" ], "contentMessage" => [ "type" => "document", "document" => [ "link" => "https://www.example.com/fr/file.pdf", "filename" => "file.pdf" ] ] ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: ApiKey " . $apiKey, "Content-Type: application/json" ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } cache { curl_close($ch); } echo $response; ?> ``` -------------------------------- ### Send Text Message - Python Example Source: https://docs.smsbox.dev/rcs Python script to send a text message using the RCS API. It utilizes the `requests` library to make a POST request with the JSON payload. ```python import requests url = "https://api.rcsbox.net/rcs/1.0/json/{agentId}/message" headers = { "Content-Type": "application/json", "x-api-key": "YOUR_API_KEY" } payload = { "recipients": [ "+336XXXXXXXX" ], "contentMessage": {}, "validity": 720 } response = requests.post(url, headers=headers, json=payload) print(response.status_code) print(response.json()) ``` -------------------------------- ### Send Sticker Message Request - PHP Source: https://docs.smsbox.dev/whatsapp PHP code example for sending a sticker message using cURL. This shows how to configure the request, including the target URL, HTTP method, headers, and the JSON data payload. ```php [ "+336XXXXXXXX" ], "contentMessage" => [ "type" => "sticker", "sticker" => [ "link" => "https://www.example.com/fr/file.webp", "filename" => "file.webp" ] ] ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: ApiKey " . $apiKey, "Content-Type: application/json" ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } cache { curl_close($ch); } echo $response; ?> ``` -------------------------------- ### Send Image Message Request - JavaScript Source: https://docs.smsbox.dev/whatsapp JavaScript example using the fetch API to send an image message. This code snippet shows how to make an asynchronous POST request with the required headers and JSON body. ```javascript const url = "https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID}"; const apiKey = "YOUR_API_KEY"; const payload = { "recipients": [ "+336XXXXXXXX" ], "contentMessage": { "type": "image", "image": { "link": "https://www.example.com/fr/file.jpeg", "filename": "file.jpeg" } } }; fetch(url, { method: "POST", headers: { "Authorization": `ApiKey ${apiKey}`, "Content-Type": "application/json" }, body: JSON.stringify(payload) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Send OTP Message - PHP Example Source: https://docs.smsbox.dev/whatsapp This PHP code snippet shows how to send an OTP message using the SMSBox API via cURL. Ensure that the `recipients` and `contentMessage` fields in the payload are correctly formatted according to the OTP template requirements. ```php '; $url = "https://api.wababox.net/waba/1.1/json/{$wabaId}/message/{$phoneId}"; // Assuming OTPTemplateMessage structure is defined elsewhere or inline // Example placeholder for contentMessage: $contentMessage = [ "template_name" => "otp_template", "parameters" => [ ["type" => "text", "text" => "123456"], ["type" => "text", "text" => "5"] ] ]; $payload = [ 'recipients' => ['+1234567890'], 'contentMessage' => $contentMessage ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: App {$apiKey}", "Content-Type: application/json" ]); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); } c_lose($ch); echo $response; ?> ``` -------------------------------- ### Send Read Message Status with cURL Source: https://docs.smsbox.dev/whatsapp Example cURL command to send a read message status update. This includes the necessary endpoint, API key, and the JSON payload containing the message ID and status. ```bash curl -X POST 'https://api.wababox.net/waba/1.1/json/{wabaId}/event/{phoneID}' \ -H 'Authorization: ApiKey YOUR_API_KEY' \ -H 'Content-Type: application/json' \ -d '{ "message_id": "wamid.xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "status": "read" }' ``` -------------------------------- ### Send SMSBOX Incoming Location Message using cURL Source: https://docs.smsbox.dev/rcs Example using cURL to send an incoming location message to the SMSBOX webhook. This demonstrates how to construct the POST request with the appropriate JSON payload and headers. ```shell curl -X POST \ http://your-webhook-url.com/smsbox \ -H 'Content-Type: application/json' \ -d '{ "data": { "type": "location", "latitude": 42.08761, "longitude": 6.0755356, "timestamp": "1719576000" }, "requestType": "incoming_message_location", "agentId": "XXXXXXXXXXXXXX", "agentName": "SMSBOX", "clientId": 12123, "msisdn": "+336XXXXXXXX", "requestProd": "RCS", "requestSubProd": "rcs", "requestDate": "2024-06-01T14:00:00+02:00", "requestUUID": "XXXXXXXXX" }' ``` -------------------------------- ### Text Webhook Payload Sample Source: https://docs.smsbox.dev/rcs An example payload for an incoming text message webhook. This payload contains details about the message, the requesting agent, and the client information. It's used to notify your application of incoming messages. ```json { "data": { "type": "text", "text": "hello smsbox!", "timestamp": "1719576000" }, "requestType": "incoming_message_text", "agentId": "XXXXXXXXXXXXXX", "agentName": "SMSBOX", "clientId": 12123, "msisdn": "+336XXXXXXXX", "requestProd": "RCS", "requestSubProd": "rcs", "requestDate": "2024-06-01T14:00:00+02:00", "requestUUID": "XXXXXXXXX" } ``` -------------------------------- ### Revoke Message - cURL Example Source: https://docs.smsbox.dev/rcs Example of revoking a message using cURL to the RCS API. Demonstrates the POST request with necessary headers and the JSON payload containing recipients and reference. ```curl curl -X POST \ https://api.rcsbox.net/rcs/1.0/json/{agentId}/revoke \ -H 'Content-Type: application/json' \ -H 'x-api-key: YOUR_API_KEY' \ -d '{ "recipients": [ "string" ], "reference": "XXXXXXXXXXXX" }' ``` -------------------------------- ### Send Text Message - cURL Source: https://docs.smsbox.dev/whatsapp Example of sending a text message using cURL to the SMSBOX WhatsApp API. Requires API key authorization. ```bash curl -X POST https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID} \ -H "Authorization: ApiKey YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "recipients": ["+336XXXXXXXX"], "contentMessage": { "type": "text", "text": { "body": "Message sent via my WhatsApp Business agent." } } }' ``` -------------------------------- ### Send OTP Message - Python Example Source: https://docs.smsbox.dev/whatsapp This Python code snippet demonstrates sending an OTP message using the SMSBox API. It uses the `requests` library to post the required data. Ensure you correctly define the `contentMessage` part according to the OTP template specifications. ```python import requests url = "https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID}" headers = { "Authorization": "App ", "Content-Type": "application/json" } # Assuming OTPTemplateMessage structure is defined elsewhere or inline # Example placeholder for contentMessage: content_message = { "template_name": "otp_template", "parameters": [ {"type": "text", "text": "123456"}, {"type": "text", "text": "5"} ] } payload = { "recipients": ["+1234567890"], "contentMessage": content_message } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` -------------------------------- ### Send OTP Message - JavaScript Example Source: https://docs.smsbox.dev/whatsapp This JavaScript code uses the `fetch` API to send an OTP message via the SMSBox API. You need to replace the placeholders for `wabaId`, `phoneId`, and `apiKey`. The `contentMessage` object should follow the structure required for OTP templates. ```javascript async function sendOtpMessage() { const url = `https://api.wababox.net/waba/1.1/json/${wabaId}/message/${phoneID}`; const apiKey = ''; // Example placeholder for contentMessage: const contentMessage = { "template_name": "otp_template", "parameters": [ {"type": "text", "text": "123456"}, {"type": "text", "text": "5"} ] }; const payload = { "recipients": [ "+1234567890" ], "contentMessage": contentMessage }; try { const response = await fetch(url, { method: 'POST', headers: { 'Authorization': `App ${apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); const data = await response.json(); console.log(data); } catch (error) { console.error('Error sending OTP message:', error); } } ``` -------------------------------- ### Send Reaction Message - cURL Source: https://docs.smsbox.dev/whatsapp Example of sending a reaction message using cURL. This shows how to format the request to send an emoji reaction to a specific message. ```bash curl -X POST https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID} \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "recipients": ["+336XXXXXXXX"], "contentMessage": { "type": "reaction", "reaction": { "message_id": "wamid.xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "emoji": "😀" } } }' ``` -------------------------------- ### Send Text Message - PHP Source: https://docs.smsbox.dev/whatsapp PHP code example for sending a text message through the SMSBOX WhatsApp API. Utilizes cURL to make the POST request. ```php ['+336XXXXXXXX'], 'contentMessage' => [ 'type' => 'text', 'text' => [ 'body' => 'Message sent via my WhatsApp Business agent.' ] ] ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Authorization: ApiKey ' . $apiKey, 'Content-Type: application/json' ]); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } else { echo $response; } cert(); ?> ``` -------------------------------- ### Send Interactive List Message - JavaScript Example Source: https://docs.smsbox.dev/whatsapp This JavaScript code illustrates how to send an interactive list message using the SMSBox API. It uses the `fetch` API for making the POST request. Ensure that the API key and IDs are correctly substituted in the request. ```javascript async function sendListMessage() { const url = `https://api.wababox.net/waba/1.1/json/${wabaId}/message/${phoneID}`; const apiKey = ''; const payload = { "type": "interactive", "interactive": { "type": "list", "header": { "type": "text", "text": "Header Text" }, "body": { "text": "Body Text" }, "footer": { "text": "Footer Text" }, "action": { "button": "View More", "sections": [ { "title": "Section 1", "rows": [ { "id": "item1", "title": "Item 1", "description": "Description for Item 1" } ] } ] } } }; try { const response = await fetch(url, { method: 'POST', headers: { 'Authorization': `App ${apiKey}`, 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); const data = await response.json(); console.log(data); } catch (error) { console.error('Error sending message:', error); } } ``` -------------------------------- ### Send Reaction Message - PHP Source: https://docs.smsbox.dev/whatsapp PHP code snippet for sending a reaction message. This example demonstrates how to use cURL to send an emoji reaction to a specified message. ```php ["+336XXXXXXXX"], "contentMessage" => [ "type" => "reaction", "reaction" => [ "message_id" => "wamid.xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "emoji" => "😀" ] ] ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: Bearer " . $apiKey, "Content-Type: application/json" ]); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); } else { echo $response; } c_l( $ch ); ?> ``` -------------------------------- ### Send Text Message - cURL Source: https://docs.smsbox.dev/whatsapp Example of sending a text message using cURL. This demonstrates how to make an HTTP POST request to the API endpoint with the appropriate payload. ```bash curl -X POST https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID} \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "recipients": ["+336XXXXXXXX"], "contentMessage": { "type": "text", "context": { "message_id": "wamid.xxxxxxxxxxxxxxxxxxxxxxxxxxxx" }, "text": { "body": "Reply to a previous message." } } }' ``` -------------------------------- ### Retrieve File with JavaScript Source: https://docs.smsbox.dev/whatsapp JavaScript code to retrieve a file. It uses the `fetch` API to send a POST request with the file ID to the file endpoint. ```javascript const apiKey = "YOUR_API_KEY"; const wabaId = "{wabaId}"; const phoneId = "{phoneID}"; const url = `https://api.wababox.net/waba/1.1/json/${wabaId}/file/${phoneId}`; const headers = { "Authorization": `ApiKey ${apiKey}`, "Content-Type": "application/json" }; const payload = { "file_id": "1234567890" }; fetch(url, { method: "POST", headers: headers, body: JSON.stringify(payload) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Revoke Message - Python Example Source: https://docs.smsbox.dev/rcs Python script to revoke a message using the RCS API. It uses the `requests` library to send a POST request with the revocation details. ```python import requests url = "https://api.rcsbox.net/rcs/1.0/json/{agentId}/revoke" headers = { "Content-Type": "application/json", "x-api-key": "YOUR_API_KEY" } payload = { "recipients": [ "string" ], "reference": "XXXXXXXXXXXX" } response = requests.post(url, headers=headers, json=payload) print(response.status_code) print(response.json()) ``` -------------------------------- ### Send Read Event Request Samples Source: https://docs.smsbox.dev/rcs Samples for sending a read event to the RCS API. Includes payload, cURL, Python, JavaScript, and PHP examples. The request body requires an array of recipients (max 1 item) and the event type 'READ'. ```json { "recipients": [ "string" ], "event": "READ" } ``` ```shell curl -X POST https://api.rcsbox.net/rcs/1.0/json/{agentId}/event \ -H "Content-Type: application/json" \ -d '{ "recipients": [ "string" ], "event": "READ" }' ``` ```python import requests url = "https://api.rcsbox.net/rcs/1.0/json/{agentId}/event" headers = { "Content-Type": "application/json" } data = { "recipients": [ "string" ], "event": "READ" } response = requests.post(url, headers=headers, json=data) print(response.json()) ``` ```javascript const url = "https://api.rcsbox.net/rcs/1.0/json/{agentId}/event"; const data = { "recipients": [ "string" ], "event": "READ" }; fetch(url, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data) }) .then(response => response.json()) .then(data => console.log(data)); ``` ```php ['string'], 'event' => 'READ' ]); $options = [ 'http' => [ 'header' => "Content-type: application/json\r\n", 'method' => 'POST', 'content' => $data ] ]; $context = stream_context_create($options); $result = file_get_contents($url, false, $context); var_dump($result); ?> ``` -------------------------------- ### Send Text Message - PHP Source: https://docs.smsbox.dev/whatsapp PHP code snippet for sending a text message. This example uses cURL to make the HTTP POST request to the SMS Box API. ```php ["+336XXXXXXXX"], "contentMessage" => [ "type" => "text", "context" => [ "message_id" => "wamid.xxxxxxxxxxxxxxxxxxxxxxxxxxxx" ], "text" => [ "body" => "Reply to a previous message." ] ] ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: Bearer " . $apiKey, "Content-Type: application/json" ]); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); } else { echo $response; } c_l( $ch ); ?> ``` -------------------------------- ### Capabilities Check Response Sample (200 OK) Source: https://docs.smsbox.dev/rcs A successful response sample for the capabilities check endpoint. It indicates the request was processed successfully and provides details about recipients, including their submitted number, rewritten number, state, and reason code. For successful requests, it may also include their capabilities. ```json { "response": { "response_code": "200", "response_desc": "Request successfully processed." }, "recipients": [ { "submitted": "+33xxxxxxxxx", "rewrited": "33xxxxxxxxx", "state": "SUCCESS", "reason_code": "REACHABLE", "capabilities": [ "chatBotCommunication", "RICHCARD_STANDALONE" ] } ] } ``` -------------------------------- ### Handle Incoming Message Reaction Webhook Source: https://docs.smsbox.dev/whatsapp This webhook is triggered when a user reacts to a message. It includes details about the reaction, such as the emoji and the message it's associated with. The system should respond with a 200 OK to acknowledge successful data reception. ```json { "data": { "from": "33XXXXXXXXX", "id": "wamid.xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "timestamp": "1719576000", "type": "reaction", "reaction": { "message_id": "wamid.xxxxxxxxxxxxxxxxxxxxxxxxxxxx", "emoji": "👍" } }, "wabaId": "xxxxxx", "phoneId": "xxxxxx", "phoneNumber": "xxxxxx", "clientId": 123456, "requestProd": "WABA", "requestDate": "2024-06-01T14:00:00+02:00", "requestUUID": "xxxxxx", "requestType": "incoming_message" } ``` -------------------------------- ### Send Interactive Button Message - PHP Source: https://docs.smsbox.dev/whatsapp PHP code snippet for sending an interactive button message. This example uses cURL to construct and send the POST request for interactive messages. ```php "interactive", "interactive" => [ "type" => "button", "header" => [ "type" => "text", "text" => [ "body" => "Message sent via my WhatsApp Business agent." ] ], "body" => [ "text" => "string" ], "footer" => [ "text" => "string" ], "action" => [ "buttons" => [ [ "type" => "reply", "reply" => [ "id" => "string", "title" => "string" ] ] ] ] ] ]; $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "Authorization: Bearer " . $apiKey, "Content-Type: application/json" ]); $response = curl_exec($ch); if (curl_errno($ch)) { echo 'Curl error: ' . curl_error($ch); } else { echo $response; } c_l( $ch ); ?> ``` -------------------------------- ### Send Interactive Button Message - Python Source: https://docs.smsbox.dev/whatsapp Python code snippet for sending an interactive button message. This example uses the `requests` library to send messages with predefined button options. ```python import requests url = "https://api.wababox.net/waba/1.1/json/{wabaId}/message/{phoneID}" headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" } payload = { "type": "interactive", "interactive": { "type": "button", "header": { "type": "text", "text": { "body": "Message sent via my WhatsApp Business agent." } }, "body": { "text": "string" }, "footer": { "text": "string" }, "action": { "buttons": [ { "type": "reply", "reply": { "id": "string", "title": "string" } } ] } } } response = requests.post(url, headers=headers, json=payload) print(response.json()) ``` -------------------------------- ### Retrieve File with Python Source: https://docs.smsbox.dev/whatsapp Python script to retrieve a file using the SMSBox API. It sends a POST request containing the file ID to the file endpoint. ```python import requests import json api_key = "YOUR_API_KEY" waba_id = "{wabaId}" phone_id = "{phoneID}" url = f"https://api.wababox.net/waba/1.1/json/{waba_id}/file/{phone_id}" headers = { "Authorization": f"ApiKey {api_key}", "Content-Type": "application/json" } payload = { "file_id": "1234567890" } response = requests.post(url, headers=headers, data=json.dumps(payload)) print(response.status_code) print(response.json()) ```