All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 24s
3.1 KiB
3.1 KiB
WhatsApp SMS Service API Documentation
This document describes the REST API for the WhatsApp SMS Service, which acts as a gateway to send WhatsApp messages using MSG91 templates.
Base URL
http://betawhatsapp.tradhox.com/api/
(Or your local/production domain accordingly)
Endpoint: Send WhatsApp Message
Sends a WhatsApp message using a dynamically loaded MSG91 JSON template.
URL: /send/
Method: POST
Content-Type: application/json
Request Body Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
mobile_number |
String | Yes | The recipient's mobile number, including the country code (e.g., "919600494039"). |
otp_code |
String | Yes | The dynamic variable value (e.g., OTP or verification code) to populate in the template. |
template_name |
String | No | The name of the MSG91 template to use. Must match a .json file located in the template jsons/ directory. Defaults to "mobile_number_verification". |
Example Request
curl -X POST http://betawhatsapp.tradhox.com/api/send/ \
-H "Content-Type: application/json" \
-d '{
"mobile_number": "919600494039",
"otp_code": "123456",
"template_name": "mobile_number_verification"
}'
Example Response (Success)
The API passes through the response from MSG91 directly.
Status Code: 200 OK
{
"status": "success",
"message": "Message successfully submitted."
}
Example Response (Failure/Missing Parameters)
Status Code: 400 Bad Request
{
"error": "mobile_number and otp_code are required"
}
Example Response (Template Not Found)
Status Code: 400 Bad Request
{
"status": "error",
"message": "Template custom_promo not found"
}
Adding New Templates
To add support for a new MSG91 template:
- Create a new
.jsonfile in thetemplate jsons/folder. The filename (without.json) will be thetemplate_nameused in the API request. - The JSON file must strictly match the MSG91 payload structure.
- Keep the
toand dynamicvaluefields empty in the template file, as the API service will automatically populate them dynamically at runtime!
Example file (template jsons/mobile_number_verification.json):
{
"integrated_number": "918610694498",
"content_type": "template",
"payload": {
"messaging_product": "whatsapp",
"type": "template",
"template": {
"name": "mobile_number_verification",
"language": {
"code": "en",
"policy": "deterministic"
},
"namespace": null,
"to_and_components": [
{
"to": [""],
"components": {
"body_1": {
"type": "text",
"value": ""
},
"button_1": {
"subtype": "url",
"type": "text",
"value": ""
}
}
}
]
}
}
}