wapi.kz: WhatsApp attribution and API
v0.5.1WhatsApp with ad attribution: which ad, link or site brought each chat, and did it sell
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
send_message Send WhatsApp message
Send a WhatsApp message from a connected number: text, image (image_url, JPEG/PNG/WebP), file (file_url), voice message (voice_url — MP3/M4A/WAV/OGG, converted to a WhatsApp voice message), video (video_url — MP4; MOV/WebM are converted), location, contact card or poll. Size — up to the WhatsApp limit (2 GB). to — recipient: phone digits with country code (77011234567) or a chat_id from get_messages / list_groups: …@c.us (personal), …@lid (hidden number), …@g.us (a group the number is a member of; at most 100 group messages per day per number). With an attachment, text is the cap…
| Parameter | Type | Description |
|---|---|---|
contact | object | Send a contact card (vCard) instead of text |
file_url | string | File URL (https://…) |
filename | string | File name for file_url |
from | string | Which number to use: number id (from list_numbers) or phone. Can be omitted if the account has only one number. |
idempotency_key | string | Any unique string (e.g. a UUID) — a retry with the same key within 24 h does not send twice |
image_url | string | Image URL (https://…) |
location | object | Send a location instead of text |
mark_read | boolean | Mark the chat's incoming messages as read before sending (default true) |
poll | object | Send a poll instead of text |
reply_to | number | string | Quote a message: its id from get_messages (or wa_message_id). The reply goes to that message's chat and number |
text | string | Message text or attachment caption |
to | string | Recipient: phone digits with country code, or chat_id (…@c.us, …@lid, …@g.us). Optional with reply_to |
typing | boolean | Show "typing…" before a text message (default true) |
video_url | string | Video URL (https://…) |
voice_url | string | Audio URL for a voice message (https://…) |
react_message React to a message
React to a message with an emoji (or remove the reaction with an empty emoji). message_id — id from get_messages (or wa_message_id). Works for incoming and own messages.
| Parameter | Type | Description |
|---|---|---|
emoji * | string | One emoji, e.g. 👍; empty string removes the reaction |
message_id * | number | string | id from get_messages or wa_message_id |
edit_message Edit own message
Edit the text of your own text message (WhatsApp allows it within 15 minutes after sending).
| Parameter | Type | Description |
|---|---|---|
message_id * | number | string | id from send_message / get_messages |
text * | string | New text |
delete_message Delete own message for everyone
Delete your own message for everyone in WhatsApp (within about 2 days after sending). The record stays in the history with deleted_at.
| Parameter | Type | Description |
|---|---|---|
message_id * | number | string | id from send_message / get_messages |
list_groups List WhatsApp groups
WhatsApp groups the number is a member of: id (chat_id for send_message to), name, participants count, admins_only (only admins can write), is_admin. The list is cached for 5 minutes.
| Parameter | Type | Description |
|---|---|---|
from | string | Which number to use: number id (from list_numbers) or phone. Can be omitted if the account has only one number. |
get_group Get group participants
One group of the number and its participants: jid, phone (null if hidden), name, admin.
| Parameter | Type | Description |
|---|---|---|
group * | string | Group chat_id (…@g.us) from list_groups |
from | string | Which number to use: number id (from list_numbers) or phone. Can be omitted if the account has only one number. |
list_numbers List WhatsApp numbers
The account's WhatsApp numbers: id (for the from parameter), phone, whether it is connected (connected), status (active / paused — balance ran out).
get_messages Get message history
Latest messages from the log (incoming and outgoing, newest first). source: contact — written by the other party, phone — sent by a person from the phone, api/mcp — sent by a program. chat — the other party's phone or chat_id, to get a single conversation. Messages with a file have media {id, kind, mimetype, filename, size, url} (the link is valid for 15 minutes; get a fresh one with get_media). name — contact name or group name, author — who wrote in a group. type location / contact / poll / call — parsed content in details (coordinates and map link; names and phones from contac…
| Parameter | Type | Description |
|---|---|---|
chat | string | The other party's phone (77011234567) or chat_id |
from | string | Which number to use: number id (from list_numbers) or phone. Can be omitted if the account has only one number. |
limit | number | How many messages, default 20, max 100 |
get_media Get media file link
A message's file (photo, video, voice message, document, sticker) by media.id from get_messages: type, name, size and a fresh download link (valid for 15 minutes).
| Parameter | Type | Description |
|---|---|---|
id * | number | media.id from get_messages |
create_export Export chats and files (ZIP)
Build a ZIP archive: files and chat history (messages.json + messages.csv) for a period. Built in the background (usually minutes) — get_export returns the status and the link. At most 2 at a time and 10 per day.
| Parameter | Type | Description |
|---|---|---|
chat | string | Only this chat: the other party's phone or chat_id |
from | string | Which number to use: number id (from list_numbers) or phone. Can be omitted if the account has only one number. |
include_media | boolean | Include files (default: yes) |
since | string | From date (2026-10-01 or ISO) |
until | string | To date (exclusive) |
get_export Get export status
Export status (queued, running, done, failed, expired), progress and the archive link when ready (the link is valid for 15 minutes — request it again; the archive is kept for 24 hours).
| Parameter | Type | Description |
|---|---|---|
id * | number | id from create_export |
get_balance Get account balance
Account balance in tenge (KZT), the daily charge (330 ₸ per active number) and how many days it will last.
get_limits Get sending limits and trust score
The number's limits for today and its trust score (0–100): how many messages, and first messages to new people, can still be sent.
| Parameter | Type | Description |
|---|---|---|
from | string | Which number to use: number id (from list_numbers) or phone. Can be omitted if the account has only one number. |
check_number Check if a phone has WhatsApp
Check whether a phone number is on WhatsApp before sending. phone — digits with country code (77011234567). Limit: 200 checks per day per number.
| Parameter | Type | Description |
|---|---|---|
phone * | string | Phone number, digits only, with country code |
from | string | Which number to use: number id (from list_numbers) or phone. Can be omitted if the account has only one number. |
get_status Get account status
Summary: numbers (connected or not) and balance.
add_number Add a WhatsApp number (paid; first one free for an hour)
Add a WhatsApp number to the account — PAID: 330 ₸ (KZT) per day; the first day is charged immediately (refunded automatically if the human deletes the number within 10 minutes without linking WhatsApp), then daily until the number is deleted. FREE TRIAL: an account without payments and with less than 330 ₸ gets its first number as a 60-minute trial (trial: true, trial_ends_at in the response; nothing is charged; limits: 20 outgoing actions (messages, reactions, edits, deletes), 20 number checks, first messages to at most 3 new people, no groups, files up to 5 MB — error code trial_lim…
| Parameter | Type | Description |
|---|---|---|
confirm | boolean | true — the human agreed to the charge |
label | string | Number name for your own reference: "Sales", "Abay Ave clinic" |
connect_number Connect a number (QR or pairing code)
Link WhatsApp to a wapi number (or reconnect it if it dropped). With phone — a pairing code like ABCD-EFGH: the human opens WhatsApp → Linked devices → Link a device → "Link with phone number instead" and enters the code (the most convenient option for an agent; at most 4 codes per 10 minutes). Without phone — a QR image: scan it in WhatsApp → Linked devices (the QR lives ~20 s — request it again). Check the status afterwards with list_numbers (WORKING = connected); poll no more than once every 5–10 seconds.
| Parameter | Type | Description |
|---|---|---|
from * | string | The number in wapi: id from list_numbers or from the add_number response (not the phone being linked — that goes in phone) |
phone | string | Phone of this WhatsApp, digits with country code (77011234567) — returns a pairing code instead of a QR |
set_webhook Set webhook URL
Set the webhook URL (https) where wapi immediately sends events: message (incoming, with a lead field; location, contact cards and polls parsed into wapi.details), message.out (sent by a person from the phone), message.ack (delivered/read), session.status (connection; on FAILED the reason is in wapi.reason: banned, logged_out, self), message.reaction, message.edited, message.revoked, call.received / call.accepted / call.rejected, poll.vote, group.v2.* (group join/leave/participants/update), lead.created / lead.updated. The contract version is in the X-Wapi-Webhook-Version header (2); skip unkn…
| Parameter | Type | Description |
|---|---|---|
from | string | Number: id (from list_numbers) or phone |
url | string | null | https://… or null — remove |
get_analytics Lead source analytics: ads → chats → sales
End-to-end WhatsApp attribution: ad spend → leads → sales for a period — shows which ad, link or website brought each WhatsApp chat and whether it turned into a sale. group — row breakdown: campaign (campaigns), adset (ad sets), ad (ads), source (source: meta_ctwa — Meta click-to-WhatsApp ads, link:<utm_source> — tracking links, organic — people who wrote on their own), link (tracking links: clicks and leads), day (by day), device (the person's device: ios — iPhone, android, web — computer, unknown). Each row: spend — spend in the ad account currency, spend_kzt — in tenge…
| Parameter | Type | Description |
|---|---|---|
from | string | WhatsApp number: number id (from list_numbers) or phone. Can be omitted — then all numbers of the account (for a number key — its number). |
group | string | Breakdown, default campaign |
sales_by | string | lead (default) — sales of leads who wrote in the period; sale — sales marked in the period (by won_at) |
since | string | From date, inclusive: 2026-11-01 (Almaty day). Default — 30 days ago. |
until | string | To date, inclusive: 2026-11-06. Default — today. |
list_leads List leads with their source
Leads — people who wrote to a WhatsApp number for the first time, each with the source that brought the chat: channel = ctwa (Meta click-to-WhatsApp ad: ad.ad_id, adset_id, campaign_id, ad text and link), link (tracking link wapi.kz/go/…: click.utm_*, fbclid, gclid), organic (came on their own). match_method — how the chat was matched to the link: hidden_code (invisible marker in the text), visible_code, time_window (by time after the click). stage — stage, value — sale amount, won_at — sale date (when it was marked as a sale). won_since/won_until — only sales marked in that rang…
| Parameter | Type | Description |
|---|---|---|
ad | string | Ad id |
adset | string | Ad set id |
campaign | string | Meta campaign id |
channel | string | Source: ctwa, link, organic |
cursor | number | next_cursor from the previous response |
from | string | WhatsApp number: number id (from list_numbers) or phone. Can be omitted — then all numbers of the account (for a number key — its number). |
limit | number | How many, default 50, max 500 |
phone | string | Customer phone, digits |
since | string | From date/time (2026-11-01 or ISO) |
stage | string | Stage: new — new, qualified — qualified (a target customer), won — sale, lost — lost. |
until | string | To date/time (exclusive) |
won_since | string | Sales marked from this date/time (won_at; 2026-11-01 — start of the Almaty day, or ISO) |
won_until | string | Sales marked before this date/time (exclusive; a date is the start of that Almaty day) |
get_lead Get lead details and source
Lead card: source (ad or link), first message, device, first reply (first_reply), stage and amount; conversation — the chat from the log: messages, incoming, outgoing, last_at, incoming_after_reply (how many messages the person sent after our first reply — whether the conversation continued), outgoing_after_reply; all touches (repeat visits from ads/links; raw holds the raw ad data, and the first touch has first_message — the raw first WhatsApp message without files or keys) and the stage history (who changed it and when).
| Parameter | Type | Description |
|---|---|---|
id * | number | Lead id from list_leads |
update_lead Mark lead status or sale
Change a lead's stage and/or record a sale. The lead — by id or by the customer's phone (their latest lead is used). Examples: "sale of 45,000 ₸ to customer 77011234567" → phone=77011234567, stage=won, value=45000; "they bought on November 20" → won_at=2026-11-20; "the customer is qualified" → stage=qualified; "lost" → stage=lost. A stage, amount or sale date change is sent as a lead.updated event to the number's webhook.
| Parameter | Type | Description |
|---|---|---|
currency | string | Currency of the amount: KZT (default), USD, RUB… |
from | string | WhatsApp number: number id (from list_numbers) or phone. Can be omitted — then all numbers of the account (for a number key — its number). |
id | number | Lead id (or phone) |
note | string | Note on the lead |
phone | string | Customer phone, digits with country code (or id) |
stage | string | Stage: new — new, qualified — qualified (a target customer), won — sale, lost — lost. |
value | number | Sale amount, integer (in tenge if currency is not set) |
won_at | string | Sale date: 2026-11-20 (Almaty day) or ISO time; default — when the sale is marked. Not in the future and not before the lead first wrote |
list_links List tracking links
Tracking links wapi.kz/go/<code>: where they lead (from — number id, phone), first message text, default utm, number of clicks and leads. url — the link for ads, bio, QR; snippet — script code for a website (routes the site's WhatsApp buttons through this link with utm and fbclid).
| Parameter | Type | Description |
|---|---|---|
archived | boolean | Include archived links |
from | string | WhatsApp number: number id (from list_numbers) or phone. Can be omitted — then all numbers of the account (for a number key — its number). |
create_link Create a tracking link to WhatsApp
Create a tracking link to a WhatsApp number — to see which ad, post or website brought each chat: the person taps → lands in WhatsApp with prefilled text that carries an invisible click marker — and their first message is matched to the click (utm, fbclid, gclid). Without the marker (the person erased the text) — matching by time: a new chat within 15 minutes after the click. Returns url (for ads, bio, QR), wa_url and a snippet for the website. Example: name="Instagram bio", text="Hello! I'd like to book", utm_source=instagram.
| Parameter | Type | Description |
|---|---|---|
from | string | WhatsApp number: number id (from list_numbers) or phone. Can be omitted — then all numbers of the account (for a number key — its number). |
name | string | Name for your own reference: "Instagram bio", "Website button" |
text | string | First message text (empty — a default "Hello!" in Russian) |
utm_campaign | string | |
utm_content | string | |
utm_medium | string | |
utm_source | string | |
utm_term | string | |
visible_code | boolean | Append a visible code like #K7F2 to the text — a fallback matching method (default: no) |
get_link_clicks Get tracking link clicks
Tracking link clicks (newest first): time, IP, geo (country, region, city), device, OS, browser or app (Instagram, TikTok…), source, language, visitor (visitor; returning — clicked before), utm, fbclid/gclid, website page, and the lead the click was matched to (lead: id, phone, stage; null — the person did not write). lead=none — clicked but did not write on WhatsApp. Without code — clicks on all links of the account (or of number from), each with the link code and name.
| Parameter | Type | Description |
|---|---|---|
code | string | Link code (from list_links); empty — all links |
from | string | WhatsApp number: number id (from list_numbers) or phone. Can be omitted — then all numbers of the account (for a number key — its number). |
lead | string | any — only those who started a chat, none — clicked but did not write |
limit | number | How many, default 200, max 1000 |
since | string | From date/time |
until | string | To date/time |
get_link_stats Get tracking link stats
Tracking link click stats for a period — which sources, campaigns and pages bring WhatsApp chats and sales: clicks, unique clicks, visitors and returning visitors, how many reached a WhatsApp chat (leads, conversion %), sales and revenue, clicks without a lead, median minutes from click to message, bots; by day and breakdowns by: country, city, device, os, browser (and apps), source, lang, utm_source, utm_campaign, link, hour. code — one link, without code — all links of the account (or of number from).
| Parameter | Type | Description |
|---|---|---|
code | string | Link code (from list_links); empty — all links |
from | string | WhatsApp number: number id (from list_numbers) or phone. Can be omitted — then all numbers of the account (for a number key — its number). |
since | string | From day 2026-11-01 (Almaty time, inclusive); default — 30 days |
top | number | Rows in each breakdown, default 20, max 100 |
until | string | To day, inclusive |
set_number_leads Set lead tracking start for a number
Turn counting of organic leads on a number on or off: when on, every new contact who came without an ad or link becomes a lead (organic). Existing contacts do not become leads. Leads from ads and links are always counted.
| Parameter | Type | Description |
|---|---|---|
enabled * | boolean | true — count, false — do not count |
from | string | Number id or phone (can be omitted for a number key) |
list_ad_accounts List connected ad accounts
Connected Meta ad accounts (Facebook / Instagram ads) and the connections to them. For each ad account: id (for the account parameter), external_id (act_…), name, currency, enabled — whether it is synced, synced_at — when data was last fetched, error — what went wrong, capi_enabled — whether conversions are sent to Meta (beta). A connection has status: active, expired (the token expired — the human needs to reconnect the ad account at wapi.kz/app/integrations). An ad account can only be connected in the wapi.kz dashboard (Facebook login).
list_ad_objects List campaigns, ad sets and ads
Campaigns, ad sets and ads from connected Meta ad accounts (data from the last sync, hourly). Fields: external_id (the Meta id — for set_ad_status / set_ad_budget), level (campaign | adset | ad), name, status (what is set: ACTIVE / PAUSED), effective_status (what is actually happening: ACTIVE, CAMPAIGN_PAUSED, ADSET_PAUSED, DISAPPROVED, WITH_ISSUES, ARCHIVED…), objective (campaign objective; for an ad set — the optimization goal), destination (where it leads: WHATSAPP, MESSENGER, WEBSITE…), parent_id, campaign_id, daily_budget / lifetime_budget (in the ad account currency, e.g. 5000 =…
| Parameter | Type | Description |
|---|---|---|
account | string | Ad account: id from list_ad_accounts or act_… |
cursor | number | next_cursor from the previous response — the next page |
level | string | Level: campaign — campaigns, adset — ad sets, ad — ads |
limit | number | How many to return, default 200, max 1000 |
parent | string | Only child objects: a campaign id (its ad sets) or an ad set id (its ads) |
status | string | Status filter: ACTIVE, PAUSED, ARCHIVED… (matched against status and effective_status) |
set_ad_status Pause or resume an ad
Pause or launch a campaign, ad set or ad in Meta. status: PAUSED — pause (the ad stops showing and spending money), ACTIVE — launch (the ad starts spending the client's budget). Pausing a campaign stops all its ad sets and ads. The change is logged (list_ad_changes). Before launching, make sure the human wants it.
| Parameter | Type | Description |
|---|---|---|
external_id * | string | Campaign, ad set or ad id in Meta (external_id from list_ad_objects) |
status * | string | ACTIVE — launch, PAUSED — pause |
set_ad_budget Change ad budget
Change the daily (daily_budget) or lifetime (lifetime_budget) budget of a campaign or ad set in Meta. WARNING: this spends the client's money — raising the budget immediately increases spend charged to their card/account in Meta. Change it only if the human asked for it or explicitly agreed. The amount is in the ad account currency, in regular units (5000 = 5,000 ₸ or $5000 — see currency in list_ad_objects), not in cents. Only an already set budget can be changed: if an ad set has no budget, it is set on the campaign (CBO) — change the campaign budget. Safeguard: one call changes the…
| Parameter | Type | Description |
|---|---|---|
external_id * | string | Campaign or ad set id in Meta (external_id from list_ad_objects) |
daily_budget | number | New daily budget in the ad account currency, e.g. 5000 |
force | boolean | Allow a change of more than 3x at once — only after explicit confirmation from the human |
lifetime_budget | number | New lifetime budget in the ad account currency (if the object has a lifetime budget) |
sync_ads Sync ad account data
Fetch fresh data from Meta now: campaigns, ad sets, ads, budgets and stats for today and yesterday (on the first run of the day — for 30 days). Normally this happens automatically (structure hourly, stats every 30 minutes) — call it if you have just changed something in Ads Manager. No more than 3 times per 10 minutes. The response — per ad account: how many objects and stats rows were fetched, or an error.
list_ad_changes List ad changes log
Log of ad changes made through wapi (dashboard, API, MCP, CLI): what changed (field: status, daily_budget, lifetime_budget), before → after (budget in the ad account currency), who (by), whether Meta accepted it (ok) and its response. Newest first.
| Parameter | Type | Description |
|---|---|---|
external_id | string | Only changes to this object |
limit | number | How many entries, default 50, max 500 |