Skip to content
WhatsMarketingDeveloper Hub

Recipes

Patterns that come up in almost every integration. Each recipe uses only what already exists in the API.

Web form → contact → welcome campaign

  1. Your form sends the data to your server (never call the API from the browser: you would expose the key).
  2. The server does POST /contacts with source: "WEBSITE_FORM" and the consent.
  3. If it responds 409 CONTACT_PHONE_EXISTS, use contactId and do PATCH /contacts/{id} to add the campaign tag.
  4. In the dashboard, an automation with the trigger "enters the New lead stage" sends the welcome template. No code is needed for the send.

Syncing with your CRM (HubSpot, Zoho, Pipedrive, Salesforce)

From the CRM to WhatsMarketing: when a contact is created or changed in the CRM, POST /contacts or PATCH /contacts/{id}; store the WhatsMarketing id in a custom field of the CRM so you don't have to search every time.

From WhatsMarketing to the CRM: subscribe to contact.created, contact.updated and contact.stage_changed. Each event carries the contactId and the basic details; request the record if you need more, update the CRM and, if the stage changed to "Customer", move the deal in the CRM.

Tip: tag in WhatsMarketing with the CRM identifier (crm:12345) and filter by tag whenever you need to cross-reference them.

Slack notification when a campaign finishes

Subscribe to campaign.finished. The event carries the campaign id; request the detail and post it with a Slack incoming webhook:

Node.js
app.post('/webhooks/wm', express.raw({ type: 'application/json' }), async (req, res) => {
  if (!verify(req.body.toString(), req.header('X-WM-Signature'), SECRET)) return res.status(401).end();
  res.status(200).end();
  const { event, data } = JSON.parse(req.body);
  if (event !== 'campaign.finished') return;
  const r = await fetch(`https://micuenta.whatsmarketing.es/api/v1/campaigns/${data.campaignId}`, {
    headers: { Authorization: `Bearer ${process.env.WM_API_KEY}` },
  });
  const c = await r.json();
  await fetch(process.env.SLACK_WEBHOOK, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ text: `Campaign "${c.name}" finished: ${c.stats.delivered} delivered, ${c.stats.replied} replies.` }),
  });
});

Launching a campaign from your own system

curl
# 1. Create the draft
curl -X POST $API/campaigns -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"name":"Appointment reminder","phoneNumberId":"…","templateId":"…","variables":{"1":"{{fullName}}"}}'
# 2. Audience by tag
curl -X POST $API/campaigns/$ID/recipients -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" -d '{"tag":"cita-manana"}'
# 3. Cost before sending
curl $API/campaigns/$ID/preview-cost -H "Authorization: Bearer $KEY"
# 4. Send now
curl -X POST $API/campaigns/$ID/send -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" -d '{"when":"now"}'

If preview-cost says wallet.sufficient: false, top up the wallet in the dashboard before sending: the send would respond 400 "Saldo insuficiente en la wallet." (insufficient wallet balance).

No code: n8n, Make and Zapier

Until there are official nodes, use each tool's HTTP node:

  • Authentication: Authorization: Bearer wm_live_… header (in n8n, a "Header Auth" credential).
  • Input: a "Webhook" node receives the events; verify X-WM-Signature with a code node (the example in Webhooks works as-is in n8n).
  • Output: HTTP nodes with the routes from the reference.

Ready-to-import templates (HubSpot, Zoho, Pipedrive, web form, Slack balance alert) will come to the dashboard; we'll announce them in the changelog.