Step 1 of 5Make the campaign link

Send campaign links via WhatsApp Business API templates

After this guide, your server sends an approved WhatsApp marketing template whose button opens the right screen in your app, and each tap shows up in Analytics under WhatsApp and your campaign.

On this page 7
  1. 1. Make the campaign link
  2. 2. Create a template with a dynamic URL button
  3. 3. Send it to customers who opted in
  4. 4. Use one link per campaign or segment
  5. 5. Read the results
  6. Common errors
  7. Next steps
Time
About 40 minutes, plus Meta's template review
You need
A WhatsApp Business Platform (Cloud API) account with a business phone number and an access token, a Strait secret key, and customers who opted in to WhatsApp messages
Works on
Any server. Code for Node 18+, Python 3.8+ and PHP 8.1+. The links work for Android and iPhone users.

WhatsApp only lets a business start a chat with a template: "Template messages are the only type of message that can be sent to WhatsApp users outside of a customer service window", and only templates with APPROVED status can be sent (Meta: Template fundamentals). This recipe puts a Strait link in the template's URL button, so one approved template can carry a different link for each campaign. Meta's API details below are quoted from Meta's docs as of October 2026; check the linked pages before you go live.

Create a link whose destination carries the campaign's UTM tags. The tags tell Analytics the channel and campaign, and title, description and imageUrl set the preview when the link is shared in a chat:

Terminal
curl https://strait.link/v1/links \
  -H "Authorization: Bearer $SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "slug": "diwali",
    "longUrl": "https://shop.example.com/sale/diwali?utm_source=whatsapp&utm_campaign=diwali-2026",
    "title": "Diwali sale",
    "description": "Up to 40% off lights and gifts",
    "imageUrl": "https://shop.example.com/img/diwali.jpg"
  }'

Then check what a tap from WhatsApp's browser does, without counting a tap:

Terminal
curl "https://strait.link/v1/simulate?url=https%3A%2F%2Fhilltop.strait.link%2Fdiwali&ua=whatsapp-android" \
  -H "Authorization: Bearer $SECRET_KEY"

You should see: "shortUrl": "https://hilltop.strait.link/diwali" from the first call, and "inAppBrowser": "whatsapp" with your link's slug from the second.

2. Create a template with a dynamic URL button

A URL button can end in one variable. Meta's rules for URL buttons: "Templates are limited to two URL buttons", the URL "Supports 1 variable, appended to the end of the URL string", the URL is "2000 characters maximum" and the button label is "25 characters maximum" (Meta: Template components). Set the button URL to your link domain followed by {{1}}, and the slug becomes the variable:

Terminal
curl "https://graph.facebook.com/v23.0/$WABA_ID/message_templates" \
  -H "Authorization: Bearer $WHATSAPP_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "festive_sale",
    "language": "en",
    "category": "MARKETING",
    "parameter_format": "positional",
    "components": [
      {
        "type": "body",
        "text": "Hi {{1}}, our festive sale is live. Tap below to open it in the app.",
        "example": { "body_text": [["Asha"]] }
      },
      {
        "type": "buttons",
        "buttons": [
          {
            "type": "url",
            "text": "Open the sale",
            "url": "https://hilltop.strait.link/{{1}}",
            "example": ["https://hilltop.strait.link/diwali"]
          }
        ]
      }
    ]
  }'

This follows Meta's custom marketing template request. Use your WhatsApp Business account ID as WABA_ID and the Graph API version your Meta app uses. You can create the same template in WhatsApp Manager instead.

You should see: {"id": "…", "status": "PENDING", "category": "MARKETING"}, then the template turning Active (APPROVED) in WhatsApp Manager once Meta has reviewed it.

3. Send it to customers who opted in

Meta requires opt-in before you message anyone: businesses "are required to obtain opt-in permission" and must name the business people are opting in to (Meta: Get opt-in for WhatsApp). Send the template with the Messages API. The button's parameters hold only the slug, not the whole URL:

Node: send-template.mjs
// Node 18+. WHATSAPP_TOKEN and PHONE_NUMBER_ID come from your Meta app.
export async function sendCampaign(to, firstName, slug) {
  const res = await fetch(`https://graph.facebook.com/v23.0/${process.env.PHONE_NUMBER_ID}/messages`, {
    method: 'POST',
    headers: { Authorization: `Bearer ${process.env.WHATSAPP_TOKEN}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({
      messaging_product: 'whatsapp',
      recipient_type: 'individual',
      to, // e.g. '919876543210'
      type: 'template',
      template: {
        name: 'festive_sale',
        language: { code: 'en' },
        components: [
          { type: 'body', parameters: [{ type: 'text', text: firstName }] },
          { type: 'button', sub_type: 'url', index: '0', parameters: [{ type: 'text', text: slug }] },
        ],
      },
    }),
  });
  if (!res.ok) throw new Error(`WhatsApp send failed: HTTP ${res.status} ${await res.text()}`);
  return res.json();
}
Python: send_template.py
import os

import requests


def send_campaign(to: str, first_name: str, slug: str) -> dict:
    res = requests.post(
        f"https://graph.facebook.com/v23.0/{os.environ['PHONE_NUMBER_ID']}/messages",
        headers={"Authorization": f"Bearer {os.environ['WHATSAPP_TOKEN']}"},
        json={
            "messaging_product": "whatsapp",
            "recipient_type": "individual",
            "to": to,  # e.g. "919876543210"
            "type": "template",
            "template": {
                "name": "festive_sale",
                "language": {"code": "en"},
                "components": [
                    {"type": "body", "parameters": [{"type": "text", "text": first_name}]},
                    {"type": "button", "sub_type": "url", "index": "0", "parameters": [{"type": "text", "text": slug}]},
                ],
            },
        },
        timeout=30,
    )
    res.raise_for_status()
    return res.json()
PHP: send-template.php
<?php
// Plain PHP with ext-curl. In Laravel: Http::withToken($token)->post($url, $payload).

function sendCampaign(string $to, string $firstName, string $slug): array
{
    $payload = [
        'messaging_product' => 'whatsapp',
        'recipient_type' => 'individual',
        'to' => $to, // e.g. '919876543210'
        'type' => 'template',
        'template' => [
            'name' => 'festive_sale',
            'language' => ['code' => 'en'],
            'components' => [
                ['type' => 'body', 'parameters' => [['type' => 'text', 'text' => $firstName]]],
                ['type' => 'button', 'sub_type' => 'url', 'index' => '0', 'parameters' => [['type' => 'text', 'text' => $slug]]],
            ],
        ],
    ];
    $ch = curl_init('https://graph.facebook.com/v23.0/' . getenv('PHONE_NUMBER_ID') . '/messages');
    curl_setopt_array($ch, [
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => [
            'Authorization: Bearer ' . getenv('WHATSAPP_TOKEN'),
            'Content-Type: application/json',
        ],
        CURLOPT_POSTFIELDS => json_encode($payload, JSON_THROW_ON_ERROR),
    ]);
    $response = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    if ($response === false || $status >= 300) {
        throw new RuntimeException("WhatsApp send failed: HTTP $status $response");
    }
    return json_decode($response, true, 512, JSON_THROW_ON_ERROR);
}

You should see: a response with "messages": [{"id": "wamid.…", "message_status": "accepted"}], and on your own opted-in test phone a message whose Open the sale button goes to https://hilltop.strait.link/diwali.

The template stays the same; only the slug changes. For a new campaign, make a new link and send its slug. To compare segments, make one link per segment (diwali-new, diwali-repeat) with the batch API and a different utm_campaign on each. Slugs are letters, digits, _ and - only, so they never need the percent-encoding Meta asks for on special characters in URL button values.

You should see: each segment's link in Dashboard → Links, and the right slug in each message's button.

5. Read the results

Open Dashboard → Analytics and pick diwali-2026 in the Campaign filter. Taps count under the WhatsApp channel because of the utm_source on the destination, and taps inside WhatsApp's own browser are labelled WhatsApp anyway. On Android, someone without the app goes through Google Play and lands on the sale screen on the first launch (on iPhone, when you switch on install matching). To react in your own systems, subscribe to link.clicked and install.matched webhooks.

You should see: your test tap under channel WhatsApp and campaign diwali-2026, and, on a phone with the app, the sale screen opening.

Common errors

  • The button opens https://hilltop.strait.link/https://…. You sent the full URL as the button parameter. Send only the slug; the template already holds the domain.
  • The template is rejected or the send fails with a parameter error. The variable must be the last thing in the button URL, and every {{1}} needs an example value when you create the template. Check the template's status in WhatsApp Manager before sending.
  • Taps show up as Direct, not WhatsApp. The link's destination has no utm_source, and the tap opened outside WhatsApp's browser. Keep utm_source=whatsapp on the destination, as in step 1.

Next steps