How to send a WhatsApp message with Node.js
Send text and media messages from Node.js with a single HTTP request, then receive replies on your own webhook. Plain REST and JSON — no SDK, no template approval.
Last updated:
- Node.js
- REST + JSON
- no SDK needed
- webhook replies
// Node.js 18+ (built-in fetch)
const PID = "your-pid";
const PHONE_ID = "your-phone-id";
const TOKEN = "your-token";
const res = await fetch(
`https://api.maytapi.com/api/${PID}/${PHONE_ID}/sendMessage`,
{
method: "POST",
headers: { "x-maytapi-key": TOKEN, "Content-Type": "application/json" },
body: JSON.stringify({
to_number: "1415xxxxx67",
type: "text",
message: "Hello from Node.js!"
})
}
);
console.log(await res.json());What you need
Four things, all available in the console within a few minutes.
-
account
A Maytapi account
Sign up and start the free trial — no card required.
-
phone
A paired number
Scan the QR code with WhatsApp on your phone. Your number keeps working as usual.
-
token
pid and token
Copy them from the token page of the console; phone_id is shown next to your number.
-
Node.js
A Node.js environment
Any recent Node.js version with its standard HTTP client is enough.
Send a text message with Node.js
POST a JSON body to /sendMessage with your token in the x-maytapi-key header. The message is queued on your phone and the response returns immediately.
- ✓to_number in international format, e.g. 1415xxxxx67
- ✓type: text and the message body
- ✓The response contains the message id
curl -X POST "https://api.maytapi.com/api/$PID/$PHONE_ID/sendMessage" \
-H "x-maytapi-key: $TOKEN" \
-H "Content-Type: application/json" \
-d '{"to_number": "1415xxxxx67", "type": "text", "message": "Hello from Node.js!"}'{
"success": true,
"data": {
"chatId": "1415xxxxx67@c.us",
"msgId": "3EB065B353B9493D00C9"
}
}Send an image, video or document
Use the same endpoint with type media and a public file URL or a base64 data URI. Add an optional caption and file name.
- ✓Images, video, audio, PDF and other documents
- ✓Caption in the text field
- ✓Base64 data URIs work as well as URLs
await fetch(`https://api.maytapi.com/api/${PID}/${PHONE_ID}/sendMessage`, {
method: "POST",
headers: { "x-maytapi-key": TOKEN, "Content-Type": "application/json" },
body: JSON.stringify({
to_number: "1415xxxxx67",
type: "media",
message: "https://example.com/invoice-10482.pdf",
text: "Your invoice for order #10482",
filename: "invoice-10482.pdf"
})
});Receive replies with a Node.js webhook
Register a webhook URL once. Incoming messages, delivery and read receipts arrive as JSON; answer through the reply URL included in each event.
- ✓Return 200 quickly, then process the event
- ✓Skip your own messages with fromMe
- ✓Use event.reply to answer in the same chat
await fetch(`https://api.maytapi.com/api/${PID}/setWebhook`, {
method: "POST",
headers: { "x-maytapi-key": TOKEN, "Content-Type": "application/json" },
body: JSON.stringify({ webhook: "https://example.com/maytapi/webhook" })
});import express from "express";
const app = express();
app.post("/maytapi/webhook", express.json(), async (req, res) => {
res.sendStatus(200); // acknowledge first
const event = req.body;
if (event.type !== "message" || event.message.fromMe) return;
await fetch(event.reply, {
method: "POST",
headers: { "x-maytapi-key": TOKEN, "Content-Type": "application/json" },
body: JSON.stringify({
to_number: event.conversation,
type: "text",
message: "Thanks! We received your message."
})
});
});
app.listen(3000);Node.js WhatsApp API FAQ
Ask our support team anything over WhatsApp. Average response time is under 24 hours.
Help center →Is there an official Node.js SDK?
You do not need one. The API is plain REST with JSON, so the standard Node.js HTTP client is enough, as the examples on this page show.
Can I send messages to groups from Node.js?
Yes. Use the group id (ending in @g.us) as to_number; group management endpoints are available on every plan.
Why did my message not arrive?
Check that the phone status is active, then look at the queue and logs in the console. New numbers should be warmed up before sending in volume.
More WhatsApp API features

Get your key, send your first message in ten minutes
No approval, no templates, no card. Every endpoint is open for three days.