Send a WhatsApp Message
Sends a free-form message to a WhatsApp recipient: text, one image, video or document, or a file with a caption. Free-form messages are restricted to Meta's 24-hour customer-service window — the customer must have messaged the agent within the last 24 hours. For sends outside the window, use Send Template instead.
Which endpoint do I call?
POST to /v1/whatsapp/messages over HTTPS. The endpoint requires the whatsapp:send scope on your API key — see Authentication for how scopes work.
POST /v1/whatsapp/messages
What does the request look like?
curl -X POST https://api.mojeeb.app/v1/whatsapp/messages \
-H "Authorization: Bearer mk_live_YOUR_KEY_HERE" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: reply-to-ticket-9001" \
-d '{
"agent_id": "12345678-1234-1234-1234-123456789012",
"from": "+15557654321",
"to": "+15551234567",
"text": { "body": "Thanks for reaching out! How can I help?" }
}'
What goes in the request body?
Two required fields, the recipient, and the message: text.body, media_url or both. The agent and from together identify which WhatsApp number you're sending from. The recipient is exactly one of to (their phone) or recipient_username (their WhatsApp username).
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | UUID | Yes | The agent to send from. Must be authorized for this API key. |
from | E.164 string | Yes | The WhatsApp business number to send from. Must match an active WhatsApp connection on the agent. |
to | E.164 string | One of to or recipient_username | Recipient's phone, e.g. +15551234567. |
recipient_username | string | One of to or recipient_username | Recipient's WhatsApp username, e.g. sara.k or @sara.k, for a customer who hides their number. See How do I message a customer by WhatsApp username? |
text.body | string | Without media_url | The message text; with media_url, the file's caption. Its length limit is in the reference. |
media_url | string | Without text | One file to send: an https link Mojeeb downloads, or the url of a Mojeeb upload of the agent. See How do I send an image, video or document? |
How do I message a customer by WhatsApp username?
Send recipient_username instead of to. WhatsApp lets people hide their phone number behind a username, and Meta has no way to look a username up, so Mojeeb finds it among the customers who have already messaged the agent: on the from number first, then on the agent's other numbers in the same WhatsApp Business Account. A username that never messaged the agent is refused with 422 recipient_not_found, and nothing is sent.
curl -X POST https://api.mojeeb.app/v1/whatsapp/messages \
-H "Authorization: Bearer mk_live_YOUR_KEY_HERE" \
-H "Content-Type: application/json" \
-d '{
"agent_id": "12345678-1234-1234-1234-123456789012",
"from": "+15557654321",
"recipient_username": "sara.k",
"text": { "body": "Thanks for reaching out! How can I help?" }
}'
The leading @ is optional and letter case doesn't matter. Send to or recipient_username, never both: neither is 422 recipient_required, and both is 422 recipient_conflict. The response's to is the customer's phone when Mojeeb has it, and null for a customer known only by username; recipient_username echoes the username you sent.
How do I send an image, video or document?
Add media_url: one file, as an https link Mojeeb downloads (from a public address, without redirects) or, for a file that isn't online, the url of a Mojeeb upload of the agent. text.body becomes optional and is the file's caption. A video is re-encoded for WhatsApp, so videos also count against a budget of 10 a minute per key: past it, the send is refused with 429 video_send_rate_limited and a Retry-After. The kinds and sizes a file may be are in the reference.
curl -X POST https://api.mojeeb.app/v1/whatsapp/messages \
-H "Authorization: Bearer mk_live_YOUR_KEY_HERE" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: invoice-1042" \
-d '{
"agent_id": "12345678-1234-1234-1234-123456789012",
"from": "+15557654321",
"to": "+15551234567",
"media_url": "https://example.com/files/invoice-1042.pdf",
"text": { "body": "Here is your invoice." }
}'
Mojeeb reads the file before it queues the send, so a link that can't be read, a file a message can't carry, or a url that names no upload of the agent is refused with 422 media_url_invalid and nothing is sent. The 24-hour window applies to a file as it does to text.
Which optional headers should I send?
Two are worth knowing about — both improve reliability and traceability without changing what gets sent.
| Header | Purpose |
|---|---|
Idempotency-Key | Make retries safe. See Idempotency. |
X-Correlation-ID | Custom trace id we'll honor when valid and reflect in the response; see Errors for the rules. |
What does a success response look like?
HTTP 202 Accepted with the message object: its id, status: "queued", the agent_id, the recipient (to, and recipient_username when you sent one), type: "text" (with a file too), and created_at. Every field, with an example, is in the reference for this endpoint, rendered from the API's own contract so it is never out of date.
The 202 means the message is queued for delivery. Use the returned id with Get Message Status to track delivery.
What can go wrong?
The standard error envelope is returned. Common codes are below; branch on code (stable) — never on message (may be reworded). The full catalog is on the Errors page.
code | HTTP | When |
|---|---|---|
invalid_request_body | 422 | Required field missing — param names which |
invalid_phone_number | 422 | to isn't valid E.164 |
recipient_required | 422 | Neither to nor recipient_username was sent |
recipient_conflict | 422 | Both to and recipient_username were sent; send one |
recipient_not_found | 422 | No customer with recipient_username has messaged the agent's WhatsApp numbers on this account |
invalid_from_phone | 422 | from isn't valid E.164 |
from_phone_not_found_for_agent | 422 | from doesn't match any active WhatsApp connection — available_phones lists what would work |
media_url_invalid | 422 | media_url can't be read, isn't a file a message carries, or names no upload of the agent |
agent_not_authorized | 403 | API key isn't allowed to use this agent |
insufficient_scope | 403 | API key lacks whatsapp:send |
rate_limit_exceeded | 429 | Per-key budget hit — see Rate Limits |
video_send_rate_limited | 429 | The key sent 10 videos this minute; retry after Retry-After |
What about the 24-hour window?
WhatsApp Business rules require free-form messages, text or files, to be sent inside the 24-hour customer-service window — the customer must have messaged the agent within the last 24 hours. Outside this window, Meta will reject delivery even though Mojeeb accepts the request and returns a 202.
If you send free-form outside the window, the immediate response is still 202 (we accept and queue), but the message will transition to status: "failed" with a populated failed_at once Meta rejects delivery. Poll Get Message Status to see this happen. A failed send is retried a few times, so wait a couple of minutes before treating failed as final; see Is failed final?
For sends outside the window, use a pre-approved template instead — templates can be sent at any time.
Common questions
Can I send media (images, audio, documents)?
Images, videos and documents, yes: one file per message with media_url, from a link or a Mojeeb upload; see How do I send an image, video or document? Other kinds, such as audio, aren't sent through the API.
What's the maximum body length?
The exact limit is in the reference for this endpoint; it matches WhatsApp's own limit. Longer bodies are rejected with invalid_request_body.
Does the API check whether the recipient is inside the 24h window?
No — Meta enforces the window, not us. The API accepts your request and queues the send; if Meta rejects on delivery, you'll see status: "failed" on the message status lookup.
Can the same number send to itself?
You can't send to your own business number — Meta rejects this at the platform level. The send returns 202 from us but failed on status lookup.