Send a WhatsApp message with cURL: copy-paste commands

Send a WhatsApp template message from the command line with cURL. Check your key, send with a test key first, retry without double-sending, read the status, and a short shell script that handles the errors.

November 15, 2026 · 7 min read

If you want to see a WhatsApp API call work before you write any application code, cURL is the quickest way. This guide gives you the commands in order: check your key, send a template message with a test key (nothing is sent), repeat the call safely, read the message status, and then a short shell script that retries only the errors worth retrying.

SendFromChat is an independent product and is not affiliated with Meta or WhatsApp. It runs on Meta's official WhatsApp Cloud API; you keep your own WhatsApp Business account.

What was tested: every command and the script below were run with cURL 8 in Git Bash on Windows against a small local mock server that follows our REST API reference. They were not run against a live SendFromChat key or Meta, so try them with a test key first. The commands are written for bash or zsh. On Windows, use Git Bash or WSL; quoting in cmd and PowerShell is different and is not covered here.

The short version

  1. Get a template approved.
  2. Create a test key: it runs every check and sends nothing.
  3. POST /messages with an Idempotency-Key header, so a retry never sends twice.
  4. Check the HTTP status and the error.type in the answer before you retry anything.

1. What you need

  • An approved template. A message you start outside a 24-hour conversation window must use a template Meta has approved (how the window works). Approval is usually a matter of minutes (the rules, explained). The examples use a template called order_shipped with the text "Hi {{1}}, your order {{2}} has shipped."
  • A test key (sfc_test_…), created on the dashboard's Developers page. It checks your plan, opt-outs, the template and the 24-hour window, then stops: nothing is sent, saved or counted. Swap in a live key (sfc_live_…) when you are ready.
  • Opt-in. Only message people who agreed to WhatsApp updates (how to collect opt-in).

Keep the key in an environment variable on your machine or server, not in a shared script, a repository or browser code:

export SENDFROMCHAT_KEY=sfc_test_...

2. Check that the key works

curl -sS https://sendfromchat.com/api/v1 \
  -H "Authorization: Bearer $SENDFROMCHAT_KEY"

GET /api/v1 returns your workspace, whether the key is live or test, and the numbers it can send from. A wrong or revoked key returns 401 with "type": "unauthorized". A test key can only send from a connected number, so with no number connected a send returns 409 no_number.

3. Send a template message

curl -sS -i https://sendfromchat.com/api/v1/messages \
  -H "Authorization: Bearer $SENDFROMCHAT_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-4821-shipped" \
  -d '{
    "to": "+491512345678",
    "template": {
      "name": "order_shipped",
      "language": "en_US",
      "variables": ["Ana", "#4821"]
    }
  }'

Four details matter:

  • -i prints the response headers, which is where you will see the status code and, on a repeat, Idempotent-Replayed.
  • to is international format with the country code, such as +491512345678 (phone number format).
  • variables fill {{1}}, {{2}}… in order. An object like {"1": "Ana", "2": "#4821"} works too.
  • Single quotes around the JSON keep the shell from touching # and $. If a value contains a single quote, put the body in a file and use -d @body.json.

With a test key the answer is 200 and includes "status": "test". With a live key it is 202 and looks like this:

{ "id": "wamid.HBgL…", "status": "accepted", "to": "+491512345678", "from": "…", "whatsappAccountId": "…", "type": "template" }

202 accepted means the request was accepted, not that the customer received or read the message. Step 5 shows how to check.

4. Repeat the call without sending twice

Run the same command again with the same Idempotency-Key. A retry with the same key and the same body returns the first response with Idempotent-Replayed: true instead of sending again. Reusing the key with a different body returns idempotency_mismatch.

Derive the key from the event in your system (order-4821-shipped), not from the attempt. A timeout, a re-run job or a double click then gets the first answer back instead of a second message.

5. Other message types

Free-form text, which only delivers within 24 hours of the person's last message to you:

curl -sS https://sendfromchat.com/api/v1/messages \
  -H "Authorization: Bearer $SENDFROMCHAT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to": "+491512345678", "text": "Thanks, we are on it."}'

If the window has closed, the answer is 422 with "type": "window_closed" and a windowOpenUntil time. Send a template instead.

A file from a public https link (the same 24-hour rule applies):

curl -sS https://sendfromchat.com/api/v1/messages \
  -H "Authorization: Bearer $SENDFROMCHAT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"to": "+491512345678", "media": {"url": "https://example.com/brochure.pdf", "filename": "Brochure.pdf", "caption": "Here is the brochure"}}'

More on files in sending a PDF over the WhatsApp API.

6. Read the status

Use the id from a live send (the wamid… value):

curl -sS "https://sendfromchat.com/api/v1/messages/wamid.HBgL..." \
  -H "Authorization: Bearer $SENDFROMCHAT_KEY"

The status moves sent (Meta accepted it) → delivered → read, or ends as failed with the reason. Polling works for a quick check; for a real app, subscribe to webhooks instead (delivery status guide, receiving replies).

7. A small script that retries the right errors

Not every error should be retried. A closed window or an opted-out contact will fail every time; a network timeout or a server error is worth another try, and the idempotency key makes that safe. Save this as send.sh:

#!/bin/sh
# Usage: SENDFROMCHAT_KEY=sfc_test_... ./send.sh order-4821-shipped < body.json
# Exit codes: 0 sent (or accepted), 1 error to fix, 2 WhatsApp's rules (do not retry now).
set -u
IDEM="${1:?usage: send.sh IDEMPOTENCY_KEY < body.json}"
BODY=$(cat)
API="${SENDFROMCHAT_API:-https://sendfromchat.com/api/v1}"
OUT=$(mktemp)
trap 'rm -f "$OUT"' EXIT

attempt=1
while [ "$attempt" -le 3 ]; do
  code=$(curl -sS --max-time 10 -o "$OUT" -w '%{http_code}' \
    -X POST "$API/messages" \
    -H "Authorization: Bearer $SENDFROMCHAT_KEY" \
    -H "Idempotency-Key: $IDEM" \
    -H "Content-Type: application/json" \
    -d "$BODY") || code=000

  case "$code" in
    200|202)
      cat "$OUT"; echo
      exit 0 ;;
    000|5??)
      echo "attempt $attempt: HTTP $code, retrying with the same key" >&2 ;;
    409)
      if grep -q '"request_in_progress"' "$OUT"; then
        echo "attempt $attempt: the same key is still running, retrying" >&2
      else
        cat "$OUT" >&2; echo >&2
        exit 1
      fi ;;
    422|429)
      cat "$OUT" >&2; echo >&2
      exit 2 ;;
    *)
      cat "$OUT" >&2; echo >&2
      exit 1 ;;
  esac
  sleep $((attempt * 2))
  attempt=$((attempt + 1))
done
echo "gave up after 3 attempts" >&2
exit 1

Use it like this:

chmod +x send.sh
./send.sh order-4821-shipped <<'JSON'
{"to": "+491512345678", "template": {"name": "order_shipped", "language": "en_US", "variables": ["Ana", "#4821"]}}
JSON

What it does with each answer:

HTTP status Meaning The script
200, 202 Test run or accepted Prints the answer, exits 0
no answer, 5xx Network or server problem Retries up to 3 times with the same key
409 request_in_progress The same key is still being processed Retries
409 no_number No connected number Stops, exit 1
422 WhatsApp's rules: opted_out, window_closed, template_not_approved, whatsapp_rejected Stops, exit 2: log it and move on
429 warmup_limit A new number reached today's cap Stops, exit 2: retry later
429 rate_limited Over the per-minute request limit Stops, exit 2: wait the Retry-After seconds, then retry
400, 401, 402, 403, 404 Fix the request, the key or the plan Stops, exit 1

warmup_limit applies to brand-new numbers, which are capped at 50, 100, then 200 template sends a day for the first three days. The full error table is in the REST API reference.

Two limits of the script: it sends one message per run, and it does not wait for delivery. For a list of recipients, loop over it with a different idempotency key for each person (order-4821-shipped, order-4822-shipped, …), and keep your own record of who has been sent. The same idea in a language of your choice: Python, Node.js, PHP and Laravel.

Costs, in plain terms

Two separate things: SendFromChat's flat monthly plan (from $19), and Meta's per-message charge, which Meta bills to your own WhatsApp Business account at its published rates, with no markup from us. Rates depend on the message category and the recipient's country; see WhatsApp API pricing.

A note for EU and UK customers

SendFromChat stores data in Mumbai, India. Transfers from the EU and UK are covered by the Standard Contractual Clauses and the UK Addendum in our Data Processing Agreement, and the sub-processors are listed publicly. Read it before you decide; our GDPR guide covers consent, opt-out and records on your side.

Try it

Start the 30-day free trial (no card), connect a number, create a test key and run the command in step 3. If you would rather not write the call yourself, ask your AI assistant: SendFromChat connects to Claude and ChatGPT, and with Claude Code it can write the integration for your language (Claude Code guide). Weighing other routes? See SendFromChat vs Twilio and using Meta's Cloud API directly.

Do this from your AI assistant

SendFromChat connects Claude, ChatGPT, Cursor or any MCP client to the WhatsApp Business API — templates, bulk sends, inbox, chatbots and sequences, just by asking. 30 days free, no card.

Start free