Skip to content

Send WhatsApp Messages

Send messages to your customers via WhatsApp using the official WhatsApp Business API.

Prerequisites

Before sending WhatsApp messages, you must:

  1. Create a WhatsApp Business Account — Register via the dashboard
  2. Verify your business — Submit business verification documents
  3. Set up a phone number — Register a phone number as your sender
  4. Accept opt-in — Recipients must have opted in to receive WhatsApp messages

⚠️ Opt-in Requirement: You must have explicit consent from recipients before sending WhatsApp messages. Sending unsolicited messages violates WhatsApp's policies and may result in account suspension.

Endpoint

POST https://api.galatext.com/api/whatsapp/messages

Headers

HeaderValueRequired
Content-Typeapplication/jsonYes
x-api-keyYour API keyYes

Request Body

ParameterTypeRequiredDescription
phoneNumberstringYesRecipient phone number in E.164 format
typestringYesMessage type: text, image, document, video, template
textobjectConditionalText message body (required when type is text)
imageobjectConditionalImage media object (required when type is image)
documentobjectConditionalDocument media object (required when type is document)
videoobjectConditionalVideo media object (required when type is video)
templateobjectConditionalTemplate message object (required when type is template)
recipientTypestringNoindividual (default) or group

Text Messages

Example Request

bash
curl -X POST https://api.galatext.com/api/whatsapp/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "phoneNumber": "+254712345678",
    "type": "text",
    "text": {
      "body": "Hello! Welcome to our WhatsApp service. How can we help you today?"
    }
  }'
json
{
  "success": true,
  "data": {
    "messageId": "wam_abc123def456",
    "status": "SENT",
    "phoneNumber": "+254712345678",
    "channel": "whatsapp",
    "creditsUsed": 1,
    "creditsRemaining": 499
  }
}

JavaScript (fetch)

js
const response = await fetch('https://api.galatext.com/api/whatsapp/messages', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': process.env.GALATEXT_API_KEY
  },
  body: JSON.stringify({
    phoneNumber: '+254712345678',
    type: 'text',
    text: {
      body: 'Hello! Welcome to our WhatsApp service.'
    }
  })
});

const data = await response.json();

Media Messages

Image

bash
curl -X POST https://api.galatext.com/api/whatsapp/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "phoneNumber": "+254712345678",
    "type": "image",
    "image": {
      "link": "https://your-cdn.com/images/promotion.jpg",
      "caption": "Check out our latest deals!"
    }
  }'

Document

bash
curl -X POST https://api.galatext.com/api/whatsapp/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "phoneNumber": "+254712345678",
    "type": "document",
    "document": {
      "link": "https://your-cdn.com/docs/receipt.pdf",
      "caption": "Your payment receipt",
      "filename": "receipt-june-2025.pdf"
    }
  }'

Video

bash
curl -X POST https://api.galatext.com/api/whatsapp/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "phoneNumber": "+254712345678",
    "type": "video",
    "video": {
      "link": "https://your-cdn.com/videos/tutorial.mp4",
      "caption": "Quick setup tutorial"
    }
  }'

Media Object Fields

FieldTypeRequiredDescription
linkstringYesPublic URL of the media file (HTTPS only)
captionstringNoMedia caption (max 1024 characters)
filenamestringNoFilename (document only, max 240 characters)

Supported media formats:

TypeFormatsMax Size
ImageJPEG, PNG, WEBP5 MB
DocumentPDF, DOC, DOCX, XLS, XLSX, PPT, PPTX100 MB
VideoMP4, 3GPP16 MB

Template Messages

See the Templates documentation for details on creating and managing WhatsApp message templates.

bash
curl -X POST https://api.galatext.com/api/whatsapp/messages \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "phoneNumber": "+254712345678",
    "type": "template",
    "template": {
      "name": "order_confirmation",
      "language": {
        "code": "en"
      },
      "components": [
        {
          "type": "body",
          "parameters": [
            { "type": "text", "text": "Alice" },
            { "type": "text", "text": "ORD-12345" },
            { "type": "text", "text": "KES 2,500" }
          ]
        }
      ]
    }
  }'

Opt-In Requirements

WhatsApp requires that recipients have opted in before you send messages. Methods to collect opt-in:

  • Checkbox on website — Add a WhatsApp opt-in checkbox to your signup forms
  • SMS opt-in — Send a link via SMS for recipients to opt in
  • QR code — Display a QR code that triggers opt-in
  • Existing relationship — Confirm opt-in via existing communication channels

Your opt-in records may be audited by Meta/WhatsApp at any time.

Response

Success

json
{
  "success": true,
  "data": {
    "messageId": "wam_abc123def456",
    "status": "SENT",
    "phoneNumber": "+254712345678",
    "channel": "whatsapp",
    "creditsUsed": 1,
    "creditsRemaining": 499
  }
}

Error

json
{
  "success": false,
  "error": {
    "code": "WHATSAPP_OPT_IN_REQUIRED",
    "message": "Recipient has not opted in to receive WhatsApp messages from this business.",
    "statusCode": 403
  }
}

Error Codes

StatusError CodeDescription
400BAD_REQUESTMalformed request body
401UNAUTHORIZEDMissing or invalid API key
403WHATSAPP_OPT_IN_REQUIREDRecipient has not opted in
403WHATSAPP_NUMBER_NOT_REGISTEREDSender number not registered
422INVALID_MEDIA_URLMedia URL is invalid or inaccessible
429RATE_LIMIT_EXCEEDEDToo many requests

Best Practices

  • Always obtain opt-in before sending messages
  • Use templates for business-initiated conversations
  • Respond quickly to customer messages (24-hour window)
  • Monitor opt-out and respect recipients' preferences
  • Keep media small — Optimize images and videos for WhatsApp

Powered by Galatex Softwares