WhatsApp Business: Send message with file
Base URL:
POST: https://api.smsgatewayapi.com/v1/whatsapp/send_file
| Parameter | Input | Description | |
|---|---|---|---|
| client_id | API client ID | Developer › API & Webhooks › API credentials | Required |
| client_secret | API client secret | A cs_ credential, shown once when you create it under Developer › API & Webhooks › API credentials | Required |
| message | message | the message to be sent | Partial |
| to | destination number | the number(s) that will receive the message in international format (eg: 324xx, 316xx, ...) | Required |
| sender | sender | The number or name of the sender. A number can't be longer than 14 characters.A name can't be longer than 11 characters and can't contain special characters | Required |
| date | Date and time the message will be sent | Format: yyyy-MM-dd HH:mm. If not provided, the message will be sent as soon as possible | Optional |
| reference | custom reference | String of max. 255 characters | Optional |
| attachment | attachment URL | The URL of the attachment | Required |
| attachment_type | attachment type | The type of the attachment, possible values are 'file', 'image', 'audio' or 'video' | Required |
| template | message template ID | The ID of one of your message templates (tpl_...), see Get message templates. Its text replaces message and, when the template has an attachment, its file replaces attachment and attachment_type. When message is sent as well it is ignored and the response contains a warnings entry. Unknown or foreign IDs return error 150 | Optional |
| test | true/false | The system will check all parameters but will not send a the message (no credits/balance used). | Optional |
| subid | id of a subaccount | If specified, the message will be sent from the subaccount. | Optional |
<?php //PHP - cURL $ch = curl_init(); $url = "https://api.smsgatewayapi.com/v1/whatsapp/send_file"; $client_id = "XXX"; // Your API client ID (required) $client_secret = "YYY"; // Your API client secret (required) $data = [ 'to' => "31681234567", //Receiver (required) 'sender' => "WhatsAppSender" //Sender (required)
'message' => "Hello World", //Message (required)
'template' => "tpl_3520a1ec234dbabe1232def67e858855", //Message template ID (optional, replaces message)
'attachment' => "https://www.smstools.com/assets/images/logo.png", //Attachment URL (required) 'attachment_type' => "image" //Attachment type (required)
]; curl_setopt($ch, CURLOPT_URL, "$url"); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_VERBOSE, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ "X-Client-Id: $client_id", "X-Client-Secret: $client_secret", "Content-Type: application/json", ]); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); $response = curl_exec($ch); ?>
Example request:
{
"message": "Hello world",
"to": "{nr}",
"date":"2024-10-15 15:30",
"sender": "YourWhatsAppBusinessSenderNumber",
"attachment": "https://www.smstools.com/assets/images/logo.png",
"attachment_type": "image"
}
Example response:
{
"messageid": "h2md1ewkyzjkuyn9ak7pryw1evtyw3x"
}