Node.js Tutorial

Send WhatsApp Messages
with Node.js

A complete guide to sending WhatsApp messages programmatically using Node.js and MazeAPI. No complex setup — just a REST API call.

Up and running
in 3 steps

No dependencies to install, no Meta Business Account needed. Just Node.js and an HTTP client.

1
Sign up & connect your number

Create a free MazeAPI account, add a WhatsApp instance from the dashboard, and scan the QR code with your phone to connect your WhatsApp number.

2
Get your API key

Navigate to API Keys in your dashboard and create a new key. Copy the wa_live_… token — it's shown only once. Store it in an environment variable.

3
Send your first message

Make a single POST request from your Node.js code. The examples below show how with native fetch, axios, and how to receive webhooks with Express.

Ready-to-run Node.js snippets

Copy, paste, and replace the placeholders with your credentials.

Using fetch (Node 18+)

send-whatsapp.js
const API_KEY = 'wa_live_your_key_here';
const INSTANCE_ID = 'your_instance_id';

async function sendWhatsApp(number, message) {
  const res = await fetch(
    `https://www.mazeapi.com/api/v1/instances/${INSTANCE_ID}/messages/text`,
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${API_KEY}`,
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        number,
        text: { body: message },
      }),
    }
  );
  const data = await res.json();
  console.log('Message sent:', data.messageId);
  return data;
}

sendWhatsApp('972501234567', 'Hello from Node.js!');

Using axios

send-whatsapp-axios.js
const axios = require('axios');

const client = axios.create({
  baseURL: 'https://www.mazeapi.com/api/v1',
  headers: {
    Authorization: `Bearer ${process.env.MAZEAPI_KEY}`,
  },
});

// Send a text message
await client.post(
  `/instances/${INSTANCE_ID}/messages/text`,
  {
    number: '972501234567',
    text: { body: 'Hello from axios!' },
  }
);

Receiving webhooks with Express

webhook.js
const express = require('express');
const app = express();
app.use(express.json());

app.post('/webhook', (req, res) => {
  const { event, data } = req.body;
  if (event === 'message.received') {
    console.log('New message from:', data.from);
    console.log('Text:', data.body);
  }
  res.sendStatus(200);
});

app.listen(3000);

Built for Node.js developers

No SDKs to install, no OAuth dance — just standard HTTP that works with every Node.js runtime.

Works with any HTTP client

Native fetch (Node 18+), axios, got, node-fetch — all work out of the box. No custom SDK required.

Real-time webhook delivery

Receive inbound messages as POST events to your Express endpoint. Automatic retries with exponential backoff if your server is down.

Multiple instances per account

Connect several WhatsApp numbers under one API key. Perfect for multi-tenant applications or SaaS products.

Flat pricing, no per-message fees

Send 100 or 100,000 messages for the same monthly price. Predictable costs that scale with your business, not your message volume.

Start sending WhatsApp messages today

Get your API key in minutes. No Meta approval, no setup fees.

Get Started →
✓ No setup fees ✓ Cancel anytime ✓ Full API access from day one