Guides
WhatsApp

Click-to-WhatsApp

From the ad to the sale: link a WhatsApp sandbox, publish the ad, simulate the click that becomes a message with referral and send the conversion with the ctwa_clid.

In a click-to-WhatsApp ad, whoever clicks opens a conversation with the business. The first message reaches the WhatsApp webhook with a referral: the ad id (source_id), the ctwa_clid and the ad content. Later, when the conversation becomes a sale, the business sends the event to the Conversions API with the same ctwa_clid, and Meta attributes the sale to the ad.

In Mimicr this cycle spans two simulators: Meta Ads and WhatsApp. They talk to each other once you link them.

bash
curl --request PUT \
  --url https://api.mimicr.dev/v1/meta-ads/whatsapp \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "workspace": "meu-sandbox" }'

The link is explicit: nothing happens on its own at activation. With it, the first Meta Ads Page gets the WhatsApp sandbox's number (whatsapp_number), and GET /v1/meta-ads shows whatsapp.waba_id. To pick another number from the sandbox, send phone_number_id; to unlink, {"workspace": ""}. In the console, the link is on the "Visão geral" tab of Meta Ads.

2. Publish the ad

  • Campaign OUTCOME_ENGAGEMENT (or OUTCOME_SALES, OUTCOME_TRAFFIC, OUTCOME_LEADS).
  • Ad set with destination_type=WHATSAPP, billing_event=IMPRESSIONS, optimization_goal=CONVERSATIONS and promoted_object={"page_id":"<Page with WhatsApp>","whatsapp_phone_number":"<number>"}. A Page without WhatsApp answers 100/2446880.
  • Creative with link: "https://api.whatsapp.com/send" and call_to_action {"type":"WHATSAPP_MESSAGE","value":{"app_destination":"WHATSAPP"}}.

The step-by-step with curl is in Create a campaign. Optionally, link_data.page_welcome_message sets the greeting and the prefilled text (JSON from Meta's visual editor):

json
{
  "type": "VISUAL_EDITOR",
  "version": 2,
  "landing_screen_type": "welcome_message",
  "media_type": "text",
  "text_format": {
    "customer_action_type": "autofill_message",
    "message": {
      "text": "Olá! Quer pedir um botijão?",
      "autofill_message": { "content": "Quero um botijão de 13 kg" }
    }
  }
}

Without it, the greeting is "Hello! Can I get more info on this?".

3. Simulate the click

With the ad approved and active (see Ads and review):

bash
curl --request POST \
  --url https://api.mimicr.dev/v1/meta-ads/actions/ad.click_to_whatsapp \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "ad_id": "120200539998049721", "wa_id": "5511999990000", "name": "Joana" }'
ParameterUse
ad_idRequired. The ad must be a click-to-WhatsApp ad
wa_idNumber of the person who clicks, with country code; default: a new contact
nameName of the new contact
textMessage text; default: the ad's prefilled text or the greeting
placementfacebook (default), instagram or whatsapp_status (no ctwa_clid)
forcetrue clicks even if the ad isn't delivering

Mimicr records the click (one impression and one click in Insights; one conversation started if it's the contact's first with an ad in 7 days), generates the ctwa_clid and injects the message into the WhatsApp sandbox. The messages webhook goes to your WhatsApp application's callback, with the WhatsApp simulator's signature and retry rules:

json
{
  "from": "5511999990000",
  "id": "wamid.HBgN…",
  "timestamp": "1794028120",
  "type": "text",
  "text": { "body": "Quero um botijão de 13 kg" },
  "referral": {
    "source_url": "https://fb.me/3cr4Wqqkvx",
    "source_id": "120200539998049721",
    "source_type": "ad",
    "body": "Botijão em 30 min",
    "headline": "Peça pelo WhatsApp",
    "media_type": "image",
    "image_url": "https://cdn.example.com/botijao.jpg",
    "ctwa_clid": "Af1QftRstEi_g2hY9q_3uEx9Q85TARVV7CN8eZInVC4MEu3Q14…",
    "welcome_message": { "text": "Olá! Quer pedir um botijão?" }
  }
}
  • source_url is https://fb.me/… on Facebook and https://www.instagram.com/p/…/ on Instagram.
  • Video ads carry video_url and thumbnail_url instead of image_url.
  • On whatsapp_status, there's no ctwa_clid.

Wire up your application: store the ctwa_clid with the conversation, and the source_id to know which ad it came from.

The WhatsApp simulator also generates referral on its own: in WhatsApp's /_sim/v1, "referral": true uses a real, active click-to-WhatsApp ad from the linked Meta Ads sandbox, with a recorded ctwa_clid. With the autoCtwa toggle, delivering ad sets generate these messages hour by hour.

4. Send the conversion

When the conversation becomes an order, send the event to the WABA dataset with the same ctwa_clid (see Conversions API):

bash
curl -s "https://meta-ads.mimicr.dev/v27.0/<dataset_id>/events" \
  -H 'Authorization: Bearer <token>' \
  -F data='[{"event_name":"Purchase","event_time":1794028500,"event_id":"order-1001","action_source":"business_messaging","messaging_channel":"whatsapp","user_data":{"ctwa_clid":"Af1Qft…","whatsapp_business_account_id":"<waba_id>","ph":["<sha256 of the phone>"]},"custom_data":{"currency":"BRL","value":120}}]'

The event becomes matched_click (the whatsapp_business_account_id must be the linked WABA's) and the purchase shows up in the ad's Insights: purchase in actions and the value in action_values.

Clocks

Meta Ads and WhatsApp have separate clocks. The click carries the Meta Ads time (that's what counts in Insights and the attribution window); the message carries the WhatsApp sandbox time. If you advance only one of them, the times diverge.

For a website ad, the equivalent action is ad.click_web: it returns the ad's link with ?fbclid=… and a ready fbc (fb.1.<ms>.<fbclid>) to send in user_data.fbc.