Skip to content
Meta Business PartnerDeveloper how-to

How to send a WhatsApp message with the API

Sending a WhatsApp message through the API is one HTTPS request: a POST to InfiQ's messages endpoint with your API key and a JSON body in the format Meta's WhatsApp Cloud API uses. This guide sends a text message, reads the response, switches to a template when the 24-hour window is closed, and handles the errors you are likely to meet first.

POST https://api.infiq.in/v1/messages
Endpoint
X-INFIQ-API-KEY header (isk_live_… or isk_test_…)
Authentication
Meta's Cloud API message format, unchanged
Body
200 with the wamid and InfiQ_traceid
Success
Country code + number, no + (919820000001)
Number format
24 hours after the customer's last message
Free-form window

In short

POST a JSON body with messaging_product, to, type and the message object to https://api.infiq.in/v1/messages, with your key in the X-INFIQ-API-KEY header. A 200 response means Meta accepted the message and gives you its ID, the wamid; delivery and read updates arrive later on your webhook. Free-form messages only work within 24 hours of the customer's last message. Outside that window, send an approved template.

Before the first send

Four things need to be in place, one of them a rule about who you may message:

  • A WhatsApp Business number connected to your InfiQ account. InfiQ handles the onboarding with Meta.
  • An API key from Settings → Developers in the dashboard. isk_test_… keys work in the sandbox, which simulates delivery events; isk_live_… keys send for real. Keep the key in an environment variable on your server, never in browser code.
  • The recipient's number in international format: country code and number, with no plus sign or spaces, for example 919820000001.
  • The customer's opt-in to hear from you on WhatsApp, which Meta's policies require before a business messages someone first.

Send a text message

A text message has type text and a text object with the body. Set preview_url to true when the body contains a link and you want WhatsApp to show a preview. Here is the same request in four languages:

curl -X POST https://api.infiq.in/v1/messages \
-H "X-INFIQ-API-KEY: $INFIQ_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "919820000001",
"type": "text",
"text": {
"preview_url": false,
"body": "Hi Ananya! Your order INF-3091 is confirmed."
}
}'

Read the response

A 200 means Meta accepted the message, not that it was delivered. The body is Meta's response unchanged plus InfiQ_traceid, a 128-character ID that InfiQ's support can look up. Store messages[0].id, the wamid: every later status for this message refers to it.

{
"messaging_product": "whatsapp",
"contacts": [
{
"input": "919820000001",
"wa_id": "919820000001"
}
],
"messages": [
{
"id": "wamid.HBgLOTE5ODIwMDAwMDAxFQIAERgSN0YxN0QxRUQ2M0E0M0FBOEQwAA==",
"message_status": "accepted"
}
],
"InfiQ_traceid": "a1b2c3d4e5f60718293a4b5c6d7e8f90…"
}

Outside the 24-hour window, send a template

WhatsApp lets a business send free-form messages only within 24 hours of the customer's last message to it. Outside that window Meta refuses the send with error 131047, and the fix is an approved message template, which can start or restart a conversation at any time. Templates are charged per delivered message by category: in India ₹0.19 for utility and ₹0.94 for marketing.

{
"error": {
"message": "(#131047) Message failed to send because more than 24 hours have passed since the customer last replied.",
"type": "OAuthException",
"code": 131047,
"error_data": {
"messaging_product": "whatsapp",
"details": "Outside the 24h service window — send an approved template instead of free-form."
},
"fbtrace_id": "Cq3Wm1Zx4Nb6Ty"
},
"InfiQ_traceid": "293a4b5c6d7e8f90a1b2c3d4e5f60718…"
}

Handle the first errors

Branch on the HTTP status and Meta's error code, not on the message text:

  • 400: Meta rejected the request, and error.code with error_data.details says why. 100 means a malformed field, 132000 a template variable count that doesn't match, 132001 a template name or language that doesn't exist.
  • 401: the X-INFIQ-API-KEY header is missing or wrong (error type authentication_error).
  • 429: your key sent too many requests. Wait until the Unix time in the X-RateLimit-Reset header, then retry.
  • 500: something failed in InfiQ or at Meta. It is safe to retry with the same Idempotency-Key header, which returns the original result instead of sending the message twice.
curl -X POST https://api.infiq.in/v1/messages \
-H "X-INFIQ-API-KEY: $INFIQ_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: INF-3091-confirmed" \
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "919820000001",
"type": "text",
"text": {
"preview_url": false,
"body": "Hi Ananya! Your order INF-3091 is confirmed."
}
}'

Use one key per logical message, such as the order ID and the event. A retry with the same key never sends a second message.

Find out whether it was delivered and read

Delivery is asynchronous. Register a webhook endpoint in the dashboard and InfiQ posts message.sent, message.delivered, message.read and message.failed events for every message, each carrying the wamid you stored. A failed event carries Meta's error code in metaErrorCode, for example 131026 when the number can't receive the message. The webhooks guide covers the receiver and the signature check.

* Per-message rates for India, ex-GST: marketing, utility and authentication effective 1 July 2026; service messages ₹0.145 since 1 October 2026 after the first 1,000 a month on each WhatsApp number, which are free (all were ₹0 until 30 September 2026). Volume commitments earn discounts — final rate is confirmed on your account; applicable GST extra. Rates for other countries differ (see the international rate table on /pricing).

Get your InfiQ API key

Frequently asked questions

Can I send a WhatsApp message through the API without a template?+
Yes, if the customer has messaged you in the last 24 hours. Inside that customer service window you can send text, media, interactive and other free-form messages. Outside it, the first message must be an approved template, or Meta returns error 131047.
Why did the API return 200 but the customer never got the message?+
A 200 only means Meta accepted the request. Delivery can still fail, for example when the number isn't on WhatsApp or Meta holds back a marketing message, and that arrives later as a message.failed webhook with Meta's code, such as 131026 or 131049.
Is sending messages through the WhatsApp API free?+
No. Meta charges per delivered message by category. In India marketing templates cost ₹0.94, utility ₹0.19 and authentication ₹0.14, and since 1 October 2026 service replies are charged at ₹0.145. InfiQ's plan covers the platform.
Can I send a WhatsApp message with a link to my website?+
Yes. Put the link in the text body and set preview_url to true to show a preview. For a tappable button instead of a raw link, send an interactive cta_url message inside the 24-hour window, or a template with a URL button outside it.