Sending Messages (Sandbox)

Send text and media messages to WhatsApp conversations via the REST API.

Sandbox numbers

This page covers POST /v1/messages/send, which takes your account key (pk_) and is the send endpoint for sandbox numbers. To send on your customers' own numbers with an App key (ak_), see Sending messages.

Send outbound WhatsApp messages through the PipesBot REST API. You can send text, images, audio, video, documents, and stickers — either by referencing a media ID, providing a URL, or sending base64 data inline.

All send operations use the same endpoint:

POST /v1/messages/send
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json

Sending text

{
  "conversationId": "conv_xyz789",
  "text": "Thanks for reaching out! We'll get back to you shortly."
}

Response

{
  "success": true,
  "messageId": "wamid.abc123...",
  "conversationId": "conv_xyz789"
}

Sending media

Include a media field to send media. PipesBot auto-detects the input mode based on the value.

Using a media ID

Reference a previously received or uploaded file by its 21-character media ID. The file keeps its 48-hour TTL and can be reused across multiple sends.

{
  "conversationId": "conv_xyz789",
  "media": "aBcDeFgHiJkLmNoPqRs1t",
  "caption": "Here's that photo"
}

Using a URL

Provide an HTTP or HTTPS URL and PipesBot fetches the file for you (HTTPS strongly recommended). Private and internal addresses are blocked (SSRF protection).

{
  "conversationId": "conv_xyz789",
  "media": "https://example.com/files/report.pdf",
  "caption": "Monthly report"
}

Using base64

Send file data inline as a base64-encoded string. The mimeType field is required.

{
  "conversationId": "conv_xyz789",
  "media": "iVBORw0KGgoAAAANSUhEUg...",
  "mimeType": "image/png",
  "fileName": "screenshot.png",
  "caption": "See attached"
}

Request fields

FieldTypeDescription
conversationIdstringRequired. Target conversation ID
textstring?Text content (max 4096 chars, non-empty when present). Used as caption for media messages if caption is absent
mediastring?Media ID, HTTP(S) URL, or base64 data. Either text or media must be provided
mimeTypestring?MIME type. Required for base64 mode
fileNamestring?File name. Optional, used for base64 mode
captionstring?Media caption (max 1024 chars). Takes precedence over text

Uploading media

Upload media independently before sending. This is useful when you want to reuse the same file across multiple messages or conversations.

POST /v1/media/upload
Authorization: Bearer YOUR_API_KEY

Multipart file upload

curl -X POST https://api.pipes.bot/v1/media/upload \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@photo.jpg"

JSON with URL

curl -X POST https://api.pipes.bot/v1/media/upload \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/files/photo.jpg" }'

JSON with base64

curl -X POST https://api.pipes.bot/v1/media/upload \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "data": "iVBORw0KGgo...", "mimeType": "image/png", "fileName": "chart.png" }'

Upload response

{ "mediaId": "aBcDeFgHiJkLmNoPqRs1t" }

Use the returned mediaId in the media field of the send endpoint. Uploaded media expires after 48 hours.

Supported media types

WhatsApp enforces format and size limits per media type:

TypeMax sizeAccepted formats
Image5 MBimage/jpeg, image/png
Audio16 MBaudio/aac, audio/mp4, audio/mpeg, audio/amr, audio/ogg
Video16 MBvideo/mp4, video/3gpp
Sticker500 KBimage/webp
Document100 MBAny MIME type

Files that don't match a specific media type (image, audio, video, sticker) are sent as documents.

24-hour service window

WhatsApp enforces a 24-hour messaging window. You can only send outbound messages within 24 hours of the customer's last inbound message. After the window expires, the API returns:

{ "error": "Service window expired...", "code": "SERVICE_WINDOW_EXPIRED" }

The window resets each time the customer sends a new message.

BYON numbers are exempt. The 24-hour window check is skipped entirely for conversations on BYON numbers — you can send to them at any time.

Conversations with no inbound yet. If a conversation has never received an inbound message, the send is rejected with 403 SERVICE_WINDOW_EXPIRED and the message "No inbound messages received in this conversation".

Daily limit (sandbox numbers)

You can send 5 messages per day from each sandbox number you've activated. The count is per account and number, so other accounts on the same shared number don't use up yours. It resets at 00:00 UTC, the same on every plan. Receiving messages is unlimited. BYON numbers have no daily limit.

The limit applies to sandbox sends with your account key (pk_): POST /v1/messages/send, POST /v1/messages/passthrough and WebSocket whatsapp_reply frames.

What counts. Every send that WhatsApp accepts counts as one: text, media, reactions and any passthrough payload. A reply split into several WhatsApp messages counts once per message. These don't count:

  • Requests rejected before they reach WhatsApp (validation errors, a closed 24-hour window, the 60 requests/minute rate limit)
  • Sends that WhatsApp rejects
  • System messages sent by PipesBot, such as the activation confirmation

Why. Since 1 October 2026, Meta charges for service messages (replies inside the 24-hour window). Sandbox numbers belong to PipesBot's WhatsApp Business Account and are shared by many accounts, so PipesBot pays for the replies sent from them. That's why sending is capped. For more volume, connect your own number with BYON.

Daily limit headers

Sandbox sends over HTTP include these headers on every response that reaches the limit check (successful sends and 429s). Requests rejected earlier, such as a 404 or 403, don't carry them:

HeaderDescription
X-Daily-LimitSends allowed per day (5)
X-Daily-RemainingSends left today, after this one
X-Daily-ResetUnix timestamp (seconds) of the next 00:00 UTC

If the counter is temporarily unavailable, the send goes through and these headers are omitted.

When you hit the limit

The API returns 429 with the code DAILY_LIMIT_REACHED and a Retry-After header with the seconds until 00:00 UTC:

{
  "error": "Daily send limit reached for this sandbox number (5/day). Resets at 00:00 UTC. For more volume, connect your own number: https://docs.pipes.bot/docs/byon",
  "code": "DAILY_LIMIT_REACHED"
}

POST /v1/messages/passthrough returns the same error in its own format:

{
  "error": {
    "code": "DAILY_LIMIT_REACHED",
    "message": "Daily send limit reached for this sandbox number (5/day). Resets at 00:00 UTC. For more volume, connect your own number: https://docs.pipes.bot/docs/byon"
  }
}

Don't retry before the reset. This code is different from RATE_LIMITED, which clears within a minute.

Over WebSocket, a blocked whatsapp_reply comes back as a reply_status event with data.success: false and data.code: "DAILY_LIMIT_REACHED". data.error carries the same message text as the HTTP error. WebSocket has no headers.

Rate limits

Rate limiting applies only to the message-send endpoints (POST /v1/messages/send, plus POST /v1/messages/app/send and POST /v1/messages/passthrough). Each is limited to 60 requests per minute per API key. The media upload/download endpoints are not rate-limited.

Rate-limit headers are returned only on the send endpoints:

HeaderDescription
X-RateLimit-LimitMaximum requests per window (60)
X-RateLimit-RemainingRequests remaining in this window
X-RateLimit-ResetUnix timestamp when window resets

Exceeding the limit returns 429 Too Many Requests. The limiter is in-memory per server instance (it resets on restart and is not shared across instances).

Error reference

StatusCodeDescription
400INVALID_REQUESTMissing required fields or invalid input
400INVALID_MEDIAUnsupported MIME type or file exceeds size limit
400INVALID_URLURL blocked by SSRF protection
400FETCH_FAILEDCould not fetch media from URL
400UPLOAD_FAILEDMedia upload failed while processing the request
401UNAUTHORIZEDMissing or invalid API key
403FORBIDDENConversation or media belongs to another tenant
403SERVICE_WINDOW_EXPIREDLast inbound message is older than 24 hours
404NOT_FOUNDConversation or media ID not found
410MEDIA_EXPIREDReferenced media expired (48-hour TTL) or the stored file is missing from storage
429RATE_LIMITEDToo many requests, retry after reset
429DAILY_LIMIT_REACHEDSandbox number sent 5 messages today; retry after 00:00 UTC
500META_UPLOAD_FAILEDFailed to upload media to WhatsApp
500UPLOAD_FAILEDMedia record lookup failed after upload
500SEND_FAILEDWhatsApp rejected the message

UPLOAD_FAILED is intentionally reused across two paths: it returns 400 when media processing fails during the request, and 500 when the media record can't be found after a successful upload. Branch on the HTTP status, not the code alone, to tell them apart.

Complete examples

Send a text reply

const response = await fetch("https://api.pipes.bot/v1/messages/send", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    conversationId: "conv_xyz789",
    text: "Thanks for your message!",
  }),
});

const result = await response.json();
console.log("Sent:", result.messageId);

Forward a received image with a new caption

// msg.media.mediaId from a received whatsapp_message event
const response = await fetch("https://api.pipes.bot/v1/messages/send", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    conversationId: "conv_xyz789",
    media: msg.media.mediaId,
    caption: "Forwarding this image",
  }),
});

Upload then send to multiple conversations

// Upload once
const uploadRes = await fetch("https://api.pipes.bot/v1/media/upload", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    url: "https://example.com/promo-banner.jpg",
  }),
});

const { mediaId } = await uploadRes.json();

// Send to multiple conversations
for (const convId of conversationIds) {
  await fetch("https://api.pipes.bot/v1/messages/send", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      conversationId: convId,
      media: mediaId,
      caption: "Check out our latest offer!",
    }),
  });
}

Receive an image and send it back processed

ws.on("message", async (raw) => {
  const event = JSON.parse(raw.toString());
  if (event.type !== "whatsapp_message") return;

  const msg = event.data;

  if (msg.type === "image" && msg.media && !msg.media.unavailable) {
    // Download the original
    const imageBuffer = await downloadMedia(msg.media.mediaId, API_KEY);

    // Process (your logic)
    const processed = await addWatermark(imageBuffer);

    // Send back as base64
    await fetch("https://api.pipes.bot/v1/messages/send", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        conversationId: msg.conversationId,
        media: processed.toString("base64"),
        mimeType: "image/jpeg",
        caption: "Here's your watermarked image",
      }),
    });
  }
});

On this page