How to send a WhatsApp text message through the API

Send a text message with the CRPRO Hub API: request body, 4,096-character limit, preview_url, Idempotency-Key and what the 202 response means.

Sending a plain text message is the first call every WhatsApp integration makes, and it is also where most of the habits that matter later are formed: how the recipient number is written, what the response really means and how a retry is made safe. This tutorial sends a text through the CRPRO Hub endpoint, shows what the Hub accepts and what it rejects, and lists the Meta rules that apply to the text itself.

What does the text send request look like?

Short answer: a POST to /api/v1/channels/{channelId}/messages with a Bearer API key, an Idempotency-Key header and a JSON body made of to, type and text.body. The Hub replies 202 Accepted with a message_id.

The body is deliberately small. The recipient goes in to, the type is the literal string text, and the content sits in a text object. Meta's own Cloud API payload also carries messaging_product and recipient_type; the Hub's schema is strict and rejects unknown fields, so leave those two out when calling the Hub. The API key needs the messages:send scope and is created as described in authentication.

curl -X POST https://crprohub.com/api/v1/channels/CHANNEL_UUID/messages \ -H "Authorization: Bearer hub_pk_EXAMPLE_NOT_REAL" \ -H "Idempotency-Key: order-1042-confirmation" \ -H "Content-Type: application/json" \ -d '{ "to": "5521999999999", "type": "text", "text": { "body": "Your order 1042 has shipped." } }'{ "data": { "message_id": "wamid.EXAMPLE123", "status": "accepted" } }

The message_id is the WhatsApp message id (the wamid). Keep it: it is the key that later status events, reactions and contextual replies refer to.

Which limits apply to the text body?

Short answer: the body must be between 1 and 4,096 characters, and the whole request payload must stay under 256 KiB. Anything outside that range is refused with 400 INVALID_MESSAGE before it reaches Meta.

Meta documents the same ceiling: the body is required and limited to 4,096 characters. The Hub validates the shape locally, so an empty string, a missing text object or an extra field fails fast and synchronously, which is much easier to debug than a failure that arrives later as a webhook. Two further limits are worth building into your client: 60 sends per minute per channel, and 120 requests per minute per organization and credential. Exceeding either returns 429 RATE_LIMITED.

  • to: the recipient, country code first. The Hub strips non-digit characters and then requires 8 to 15 digits with no leading zero.
  • type: must be the literal text for this payload.
  • text.body: 1 to 4,096 characters.
  • text.preview_url: optional boolean, covered below.
  • Idempotency-Key: required header, non-empty, at most 255 characters.

Short answer: set text.preview_url to true and the WhatsApp client tries to render a preview of the first URL in the body. Leave it out, or when no preview can be fetched, the URL shows as a plain clickable link.

Meta's text message reference states that the URL must start with http:// or https://, and that if the body contains several URLs only the first is previewed. The preview is rendered by the client, not by your server, so you cannot guarantee how it looks. The Hub's schema accepts preview_url as an optional boolean and nothing else inside the text object.

{ "to": "5521999999999", "type": "text", "text": { "preview_url": true, "body": "Tracking page: https://example.com/track/1042" } }

Put the URL you want previewed first in the text. If a message has a tracking link and a help link, the preview shows only the first one, so ordering is a product decision rather than a formatting detail.

Why is the Idempotency-Key header required?

Short answer: because a network failure after a successful send is indistinguishable from a failure before it. A stable key lets you retry without sending the customer a duplicate.

Reusing a key with the same body returns the original response instead of sending again. Reusing it with a different body returns 409 IDEMPOTENCY_KEY_REUSED. A missing header is 400 IDEMPOTENCY_KEY_REQUIRED, and a malformed one is 400 IDEMPOTENCY_KEY_INVALID. The practical rule is to derive the key from the business event, such as the order id plus the notification type, and never from a random value generated inside the retry loop. A random key per attempt defeats the whole mechanism.

// Node 20+, no dependencies async function sendText(channelId, to, body, key) { const res = await fetch( `https://crprohub.com/api/v1/channels/${channelId}/messages`, { method: 'POST', headers: { Authorization: `Bearer ${process.env.CRPRO_API_KEY}`, 'Idempotency-Key': key, 'Content-Type': 'application/json', }, body: JSON.stringify({ to, type: 'text', text: { body } }), }, ) if (res.status !== 202) { const err = await res.json().catch(() => ({})) throw new Error(`send failed: ${res.status} ${JSON.stringify(err)}`) } const { data } = await res.json() return data.message_id } await sendText(process.env.CHANNEL_ID, '5521999999999', 'Your order 1042 has shipped.', 'order-1042-shipped')

What does the 202 response actually tell you?

Short answer: that the Hub accepted the message and queued it for Meta. It does not mean the message reached the phone.

Meta says the same about its own API: the synchronous response only indicates that the request was accepted, and delivery progress arrives through webhooks. For the Hub, subscribe an endpoint to the message.status event to learn whether a message moved through sent, delivered, read or failed. The webhooks reference describes the subscription and the payload modes. A message that Meta later refuses, for example because the recipient is outside the 24-hour window and no template was used, shows up as a failed status with an error code, not as an error on the original POST.

This is why a send function should return the message_id and let a separate part of the system track the outcome. Treating 202 as delivery is the most common source of dashboards that report success while customers wait.

When is free-form text allowed?

Short answer: only inside the customer service window, which opens when the customer writes to you and lasts 24 hours from their latest message. Outside it, the first message must be a template.

Meta enforces this rule, and a send that breaks it is reported as a failed status with an error code rather than as an error on the original POST. Your code should therefore know when the customer last wrote. A simple approach is to store the timestamp of each inbound message.received event and check it before choosing between a text and a template. The quickstart walks through the first authenticated request end to end.

What should be checked before text sending goes live?

Short answer: key scope, idempotency key design, status tracking, the window check and rate limit handling. Each of these fails quietly if skipped.

Text is the simplest message type, which makes it the one most often shipped without review. A few checks done once save a lot of debugging later, and none of them takes more than a few minutes. Run them against a test channel with a number you control, then repeat the send call twice to see the idempotent replay with your own eyes.

  • Scope: the API key has messages:send and nothing broader than it needs.
  • Idempotency: the key comes from the business event, is stable across retries and stays under 255 characters.
  • Tracking: the message_id from the 202 is stored next to the record that caused the send.
  • Status: an endpoint subscribed to message.status records failed events together with their error codes.
  • Window: the code knows when the customer last wrote before choosing a text or a template.
  • Limits: sends are paced below 60 per minute per channel, and a 429 triggers a delayed retry with the same key.

Frequently asked questions

Should messaging_product and recipient_type be sent to the Hub?

No. Those fields belong to Meta's Cloud API payload. The Hub's message schema is strict, so a body with unknown fields is refused with 400 INVALID_MESSAGE. Send only to, type and the type-specific object.

Can the to field contain a plus sign or spaces?

The Hub removes non-digit characters before validating, so a formatted number is tolerated, but the documented form is country code plus number, digits only. Sending clean digits avoids depending on that normalization.

What happens when the same Idempotency-Key is sent twice?

With an identical body the Hub returns the original response and does not send a second message. With a different body it answers 409 IDEMPOTENCY_KEY_REUSED. Use a different key for each distinct message.

Can a text message contain formatting or emoji?

The body is a UTF-8 string up to 4,096 characters, so emoji are fine. Formatting markers are interpreted by the WhatsApp client; the Hub does not alter the string.

Fontes

Documentação oficial da Meta, conferida em 31 de outubro de 2026.