Back to BlogTutorials

WhatsApp API Send Message: Complete Developer Tutorial (2026)

WALYTIC TEAMNOVEMBER 9, 20267 MIN READ

What Does "Send a WhatsApp Message via API" Actually Mean?

The WhatsApp Business API lets you trigger outbound messages directly from your server — order confirmations, appointment reminders, payment alerts — no manual app interaction required. Your backend sends an HTTP POST to a REST endpoint and the message appears in your customer's WhatsApp chat.

You can use Meta's official WhatsApp Cloud API (requires a Meta Business Account and phone number approval) or connect an existing WhatsApp number to a platform like Walytic via QR code. Both approaches expose a standard REST API: POST a JSON payload, get a message delivered.

This tutorial covers every major message type with ready-to-run JavaScript examples. It uses Walytic's REST API, which you can try on a 14-day free trial — no Meta approval required to begin testing.

Prerequisites

Before your first send, you need:

ItemWhere to Get It
Walytic accountapp.walytic.com — 14-day free trial
API keyWalytic dashboard → Settings → API
Instance IDWalytic dashboard → Connections → your number
Recipient phoneOpted-in customer number in E.164 format (`+14155552671`)

Important: Only message customers who have explicitly opted in to receive WhatsApp communications from your business. Sending unsolicited messages violates WhatsApp's policies and risks your number being restricted. See the WhatsApp compliance guide for opt-in best practices.

Step 1: Send a Text Message

The most common WhatsApp API call sends a plain text notification:

JAVASCRIPT
const response = await fetch('https://api.walytic.com/v1/messages', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    instanceId: 'YOUR_INSTANCE_ID',
    to: '+14155552671',
    type: 'text',
    text: { body: 'Hi Sarah, your order #1042 has shipped! Track it: https://track.example.com/1042' },
  }),
});
const result = await response.json();
// { messageId: 'wamid.HBgN...', status: 'queued', to: '+14155552671' }

The response includes a `messageId` you can store and use to track delivery.

Step 2: Send an Image with a Caption

Product photos, receipts, and screenshots can be sent with an optional caption:

JAVASCRIPT
await fetch('https://api.walytic.com/v1/messages', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' },
  body: JSON.stringify({
    instanceId: 'YOUR_INSTANCE_ID',
    to: '+14155552671',
    type: 'image',
    image: {
      url: 'https://cdn.example.com/products/sneaker-blue.jpg',
      caption: 'Your Blue Sneakers (Size 10) are packed and ready to ship!',
    },
  }),
});

Step 3: Send a Document

Invoices, PDFs, and spreadsheets go out as document messages with a visible filename:

JAVASCRIPT
await fetch('https://api.walytic.com/v1/messages', {
  method: 'POST',
  headers: { 'Authorization': 'Bearer YOUR_API_KEY', 'Content-Type': 'application/json' },
  body: JSON.stringify({
    instanceId: 'YOUR_INSTANCE_ID',
    to: '+14155552671',
    type: 'document',
    document: {
      url: 'https://yourapp.com/invoices/INV-2026-042.pdf',
      filename: 'Invoice-2026-042.pdf',
    },
  }),
});

Message Types Reference

TypeTypical Use CaseKey Fields
`text`Notifications, reminders, support replies`text.body`
`image`Product photos, receipts, screenshots`image.url`, `image.caption`
`document`Invoices, PDFs, spreadsheets`document.url`, `document.filename`
`audio`Voice notes`audio.url`
`video`Product demos, tutorials`video.url`, `video.caption`
`location`Store address, delivery pin`location.latitude`, `location.longitude`

Step 4: Check Delivery Status

After sending, poll the status endpoint with the `messageId` from the send response:

JAVASCRIPT
const statusRes = await fetch(
  'https://api.walytic.com/v1/messages/WAMID_HERE/status',
  { headers: { 'Authorization': 'Bearer YOUR_API_KEY' } }
);
const { status, deliveredAt, readAt } = await statusRes.json();
// status: 'read', deliveredAt: '2026-11-09T10:30:02Z'

Messages move through four states: `queued` → `sent` → `delivered` → `read`. For time-critical workflows like payment confirmations, subscribe to webhook events instead of polling — Walytic fires a POST to your endpoint the moment a delivery state changes.

Step 5: Handle Incoming Replies via Webhook

Register a webhook URL in your Walytic dashboard under Settings → Webhooks. Walytic sends a POST to your endpoint for every inbound message:

JAVASCRIPT
// Express.js handler
app.post('/webhook/whatsapp', express.json(), (req, res) => {
  const { event, message } = req.body;
  if (event === 'message.received') {
    console.log('From:', message.from, 'Body:', message.text.body);
    // Auto-reply, update a CRM record, or escalate to a human agent
  }
  res.sendStatus(200);
});

Common Errors and Fixes

Error CodeMeaningFix
`401 Unauthorized`Invalid or expired API keyRegenerate in Settings → API
`404 Not Found`Wrong Instance IDCopy the exact ID from the Connections tab
`422 Unprocessable`Invalid phone number formatUse E.164 format: `+14155552671`
`429 Too Many Requests`Sending too fastAdd a delay between sends; use the broadcast endpoint for bulk lists

What to Build Next

Once single-message sending is working, the most common next integrations are:

  1. Shopify order triggers — Walytic fires WhatsApp messages automatically when an order is created, paid, fulfilled, or cancelled, with no extra backend code on your side.
  2. Scheduled reminders — set appointment or payment reminders to go out 24 hours and 1 hour before each due time.
  3. Team inbox and AI agent — route inbound replies to a shared WhatsApp inbox where your team responds, or hand them to the built-in AI agent with automatic escalation to a human when needed.

For more complex workflows, the n8n node and MCP server let you connect WhatsApp messaging to hundreds of other tools without extra glue code. See the full REST API reference at /api-reference.

Start Sending Today

Sending a WhatsApp message via API is one REST call away. Set up Walytic, grab your API key, and your first message goes out in under five minutes — no Meta approval, no SDK to install.

Start a 14-day free trial — connect your existing WhatsApp number by scanning a QR code and send your first API-triggered message within minutes. Yearly plans start at $48/year.

Ready to Automate WhatsApp?

Start sending bulk messages, automate follow-ups, and build chatbots, all with flat-rate pricing. No per-message fees.