Bubata ndepụta ndị ahịa gị otu ugboro, zipu mgbanwe ọ bụla site na CRM gị na upsert, debe nkwenye na ihe akaebe ya, ma nweta nhọrọ ịpụ, mgbanwe nọmba na mgbanwe kọntaktị site na app2email dịka ihe omume webhook a nyochara.
N'akwụkwọ nkuzi a, ị na-ebubata ndepụta ndị ahịa gị n'app2email ma debe ya n'otu na CRM ma ọ bụ database ị na-eji. Mgbanwe na CRM gị na-aga app2email ka ha na-eme. Nhọrọ ịpụ, nọmba ọhụrụ na mgbanwe ndị ọzọ n'akụkụ WhatsApp na-alaghachi gaa CRM gị dịka ihe omume webhook.
Ihe onye ahịa na-ahụ: ihe ọhụrụ adịghị, na nke ahụ bụ ihe ebe a bu n'uche. Ozi ndị ha na-enweta na-eji aha mbụ kwesịrị ekwesị na nọmba order, ndị kwenyere na ihe ndị a na-enye ga-enweta ha, ndị kwuru STOP, n'WhatsApp ma ọ bụ na CRM gị, anaghị enweta ozi ahịa ọzọ site na gị.
Ihe ị na-ahụ: kọntaktị ọ bụla na app2email nwere otu aha, tag, ubi nke onye ọrụ na nkwenye ahịa dị ka na CRM gị. CRM gị na-akọ ndị mmadụ dị ka ndị ahụ kwụsịrị otu sekọnd mgbe ha pịrị "Stop promotions", ma na-agbanwe nọmba ekwentị ha mgbe ha gbanwere ya na WhatsApp.
app2email enweghị njikọ akpaaka maka CRM ọ bụla. Ị na-ejikọ CRM gị site na oku ndị dị n'okpuru: site na koodu gị, ma ọ bụ site na ngwa akpaaka (lee Zipu ozi WhatsApp site na n8n, Zapier ma ọ bụ Make).
POST /contacts/import (CSV ma ọ bụ JSON, ruo ahịrị 5000 kwa oku).POST /contacts. Nke a bụ upsert: app2email na-emepụta kọntaktị mgbe ọ dị ọhụrụ ma na-agbanwe ya mgbe ọ dị, site na nọmba ekwentị (ma ọ bụ user id nke azụmahịa).contact.opted_out mgbe mmadụ kwụsịrị promotions, contact.updated mgbe a gbanwere kọntaktị site na API ma ọ bụ mgbe ọ laghachi na ozi ahịa na WhatsApp, contact.changed_number mgbe onye ahụ gaa nọmba ọhụrụ, na message.received mgbe onye ahụ dere gị.GET /contacts (ibe site na ibe) ma ọ bụ GET /contacts/export.csv, iji chọta ihe ọ bụla ihe omume ahụ ejighị kpuchie.Key ị na-atụnye ya bụ identity nke kọntaktị: nọmba WhatsApp ya nwere koodu mba nke mbụ, naanị ọnụọgụgụ (61412345678 maka +61 412 345 678). Debe otu uru ahụ na CRM gị. Onye ahịa nke na-eji username WhatsApp nwere ike ịbịa nwee user id nke azụmahịa kama nọmba (dịka AU.1234567890123456, identity_type ga-abụ bsuid); ọ na-arụ ọrụ ebe ọ bụla nọmba na-arụ ọrụ.
| Ubi | Ihe ọ bụ | Oke |
|---|---|---|
phone ma ọ bụ identity | Onye kọntaktị. identity na-anabata nọmba ma ọ bụ user id nke azụmahịa | Koodu mba nke mbụ, naanị ọnụọgụgụ |
name | Aha kọntaktị | Ruo mkpụrụedemede 200 |
tags | Akara dịka vip ma ọ bụ newsletter. Ederede e kewapụrụ site na comma dịkwa mma | Ruo tags 50, mkpụrụedemede 40 kwa otu |
custom_fields | Uru ederede gị, dịka first_name, order_id, crm_id. A na-eji ha dị ka uru template aha n'izipu segment | Ruo 50; aha bụ mkpụrụedemede, ọnụọgụgụ na underscore |
source | Ebe kọntaktị si bịa, dịka crm | Ruo mkpụrụedemede 50 |
consent | Nkwenye ahịa nwere ihe akaebe ya: marketing (true ma ọ bụ false), at, source, text (okwu ha kwenyere), evidence (njikọ, aha faịlụ, adreesị IP ma ọ bụ id ozi) | source 100, text 1000, evidence 500 mkpụrụedemede |
Na azịza, kọntaktị nwekwara identity_type (phone ma ọ bụ bsuid), consent.recorded (true mgbe ndekọ nkwenye ọ bụla dị), last_inbound_at, last_outbound_at, created na updated. Ubi nke enweghị uru a na-ehapụ na azịza.
Otu mmelite si arụ ọrụ: ubi ị nyere na-edochi ndị echekwara, ubi ị hapụ na-anọgide dị otu. tags na-edochi ndepụta niile dum, ya mere zipu tags niile kọntaktị kwesịrị inwe mgbe niile. custom_fields na-agwakọta: aha ndị ị zipụrụ ka a na-etinye, ndị ọzọ na-anọgide.
plan_not_allowed; ọrụ akwụsịrị na-azaghachi 403 service_not_live. Lee Ịmalite.contacts:manage ma ọ bụ Full access: igodo Default enweghị ya.| Ikike | Ihe ọ bụ |
|---|---|
contacts:manage | Bubata, mepụta, gbanwee na hichapụ kọntaktị, debe nkwenye, chekwa segment (POST /contacts/import, POST /contacts, PATCH /contacts/{identity}, DELETE /contacts/{identity}, POST /contacts/{identity}/consent, POST /segments) |
messages:read | Gụọ kọntaktị na segment, bupụta, nweta ihe omume (GET /contacts, GET /contacts/{identity}, GET /contacts/export.csv, GET /segments/{id}/contacts, GET /events) |
webhooks:manage | Debanye webhook otu ugboro (POST /webhooks). Ị nwekwara ike ịtinye ya na ibe igodo API n'okpuru Webhooks, na-enweghị koodu |
dnc:manage | Tinye ndị mmadụ kwụsịrị na CRM gị na ndepụta Do Not Call, bupụta ndekọ nrube isi (POST /donotcall, GET /compliance/export.csv) |
settings:manage | Naanị ma ị na-eji iwu nhọrọ maka ahịa: debe nhọrọ ahịa (POST /optins) |
GET /events kama ya.Nwalee site na kọntaktị ole na ole nke gị, ọ bụghị na igodo sandbox. Kọntaktị abụghị akụkụ nke sandbox ngwa ngwa (nọmba demo 12025550100 na-azaghachi 403 not_in_instant_sandbox). Igodo sandbox na nọmba gị nke onwe ya na-agụ kọntaktị nkịtị, mana POST /contacts, POST /contacts/import, PATCH, nkwenye na segment na-agbanwe data gị n'ezi, ebe DELETE /contacts/{identity} nwere igodo sandbox naanị na-eme ka ọ dị ka ọ mere, enweghị ihe a hichapụ. Nye kọntaktị nnwale gị tag dị ka test, ma hichapụ ha ka e mesịrị site na igodo nkịtị. Nkọwa: Sandbox.
Oku niile na-aga https://api.app2email.com/v1/YOUR_NUMBER, ebe YOUR_NUMBER bụ nọmba WhatsApp gị (koodu mba nke mbụ, naanị ọnụọgụgụ), nwere isi Authorization: Bearer YOUR_API_KEY. Ihe atụ ndị a na-agụ igodo site na mgbanwe gburugburu A2E_KEY.
GET /me na-egosi ikike na oke igodo ahụ.
curl -s https://api.app2email.com/v1/YOUR_NUMBER/me \
-H "Authorization: Bearer $A2E_KEY"Ihe ị na-enweta azịza (dị mkpụmkpụ):
{
"success": true,
"request_id": "a7k3p",
"key_valid": true,
"number": "4976659348270",
"service_status": "LIVE",
"key": { "name": "CRM sync", "scopes": ["contacts:manage", "messages:read", "webhooks:manage", "dnc:manage"], "ip_allow": "" },
"limits": { "max_numbers_per_request": 1000, "requests_per_second": 20, "burst": 50, "rate_limit_mode": "enforce", "webhooks_max": 5 }
}service_status ga-abụ LIVE, key.scopes ga-edepụta ikike ị chọrọ (ma ọ bụ * maka ohere zuru ezu). limits na-agwa gị otu ngwa ngwa oku sync gị nwere ike ime.
Bupụta ndepụta gị site na CRM dị ka CSV nwere ahịrị isi. Kolụm app2email maara bụ phone (ma ọ bụ identity, number, mobile), name (ma ọ bụ first_name + last_name), tags (e kewapụrụ site na |), consent_marketing (yes ma ọ bụ no), consent_source, consent_text, consent_evidence, consent_at na source. Kolụm ọ bụla ọzọ na-aghọ ubi nke onye ọrụ, ya mere kolụm crm_id na-echekwa id CRM gị nke onwe ya na kọntaktị ọ bụla. Ruo ahịrị 5000 kwa oku.
phone,name,first_name,crm_id,tags,consent_marketing,consent_source,consent_text,consent_evidence,consent_at,source
61412345678,John Smith,John,C-1001,vip|newsletter,yes,web form,"Yes, send me offers on WhatsApp",https://example.com/forms/123,2026-10-01T09:00:00Z,crm
61498765432,Mary Jones,Mary,C-1002,newsletter,no,,,,,crmcurl -s https://api.app2email.com/v1/YOUR_NUMBER/contacts/import \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: text/csv" \
--data-binary @contacts.csvimport { readFile } from "node:fs/promises";
const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/contacts/import", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.A2E_KEY}`,
"Content-Type": "text/csv",
},
body: await readFile("contacts.csv"),
});
const result = await res.json();
console.log(res.status, result.saved, "saved,", result.skipped, "skipped");
for (const e of result.errors ?? []) console.log(`row ${e.row}: ${e.problem}`);import os, requests
with open("contacts.csv", "rb") as f:
res = requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/contacts/import",
headers={"Authorization": f"Bearer {os.environ['A2E_KEY']}", "Content-Type": "text/csv"},
data=f,
timeout=120,
)
result = res.json()
print(res.status_code, result.get("saved"), "saved,", result.get("skipped"), "skipped")
for e in result.get("errors", []):
print(f"row {e['row']}: {e['problem']}")Ihe ị na-enweta azịza: ahịrị ndị nwere nsogbu a na-ahapụ ma depụta ha, ndị ọzọ a na-echekwa.
{
"success": true,
"request_id": "i2gka",
"rows": 120,
"saved": 118,
"created": 90,
"updated": 28,
"skipped": 2,
"errors": [
{
"row": 7,
"problem": "'0412' must be a WhatsApp number with country code, digits only (8 to 15 digits), or a business-scoped user id like 61.AbC123"
}
],
"note": "Rows with a problem were skipped (the first 50 are listed); the rest were saved."
}Otu esi agụ ya:
rows bụ ihe app2email gụrụ, saved = created + updated, na skipped bụ ahịrị nwere nsogbu.errors na-edepụta ahịrị nsogbu 50 mbụ nwere nọmba ahịrị na ihe kpatara ya. Dozie ahịrị ndị ahụ na CRM gị (ọ na-abụkarị nọmba na-enweghị koodu mba) wee bubata naanị ha ọzọ. Ibubata ahịrị ọzọ dị nchekwa: kọntaktị dị adị na-agbanwe, ọ naghị emepụta ya ọzọ.Oku otu ahụ na-anabatakwa application/json nwere ndepụta kọntaktị n'ụdị POST /contacts (nzọụkwụ ọzọ). Ibubata adịghị eziga ihe omume contact.updated, ya mere ibubata mbụ buru ibu adịghị ejuputa webhook gị.
Mgbe a na-emepụta ma ọ bụ gbanwee kọntaktị na CRM gị (webhook CRM, trigger database, ma ọ bụ ọrụ kwa nkeji ole na ole), zipu ya gaa POST /contacts: otu kọntaktị dị ka object, ma ọ bụ ndepụta ruo 1000.
curl -s https://api.app2email.com/v1/YOUR_NUMBER/contacts \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: application/json" \
-d '{
"phone": "61412345678",
"name": "John Smith",
"tags": ["vip", "newsletter"],
"custom_fields": { "first_name": "John", "crm_id": "C-1001", "order_id": "1234" },
"source": "crm"
}'const BASE = "https://api.app2email.com/v1/YOUR_NUMBER";
const headers = { Authorization: `Bearer ${process.env.A2E_KEY}`, "Content-Type": "application/json" };
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// crmRows: the contacts that changed in your CRM since the last run
export async function pushToApp2email(crmRows) {
const contacts = crmRows.map((c) => ({
phone: c.mobile, // 61412345678: country code first, digits only
name: c.fullName,
tags: c.tags, // the whole list: it replaces the stored tags
custom_fields: { first_name: c.firstName, crm_id: String(c.id) },
source: "crm",
}));
for (let i = 0; i < contacts.length; i += 1000) {
const batch = contacts.slice(i, i + 1000);
for (let attempt = 1; ; attempt++) {
const res = await fetch(`${BASE}/contacts`, { method: "POST", headers, body: JSON.stringify(batch) });
const body = await res.json();
if (res.ok) { console.log(`saved ${body.saved}: ${body.created} new, ${body.updated} updated`); break; }
if (res.status === 429 || (res.status >= 500 && attempt < 5)) {
const wait = Number(res.headers.get("Retry-After") ?? body.error?.retry_after_seconds ?? 2 ** attempt);
await sleep(wait * 1000);
continue; // the same batch again is safe: it is an upsert
}
throw new Error(`${body.error?.code}: ${body.error?.how_to_fix} (request ${body.request_id})`);
}
}
}import os, time, requests
BASE = "https://api.app2email.com/v1/YOUR_NUMBER"
HEADERS = {"Authorization": f"Bearer {os.environ['A2E_KEY']}"}
def push_to_app2email(crm_rows):
"""crm_rows: the contacts that changed in your CRM since the last run."""
contacts = [{
"phone": c["mobile"], # 61412345678: country code first, digits only
"name": c["full_name"],
"tags": c["tags"], # the whole list: it replaces the stored tags
"custom_fields": {"first_name": c["first_name"], "crm_id": str(c["id"])},
"source": "crm",
} for c in crm_rows]
for i in range(0, len(contacts), 1000):
batch = contacts[i:i + 1000]
for attempt in range(1, 6):
res = requests.post(f"{BASE}/contacts", headers=HEADERS, json=batch, timeout=60)
body = res.json()
if res.ok:
print(f"saved {body['saved']}: {body['created']} new, {body['updated']} updated")
break
if res.status_code == 429 or res.status_code >= 500:
wait = res.headers.get("Retry-After") or body.get("error", {}).get("retry_after_seconds") or 2 ** attempt
time.sleep(float(wait))
continue # the same batch again is safe: it is an upsert
raise RuntimeError(f"{body['error']['code']}: {body['error']['how_to_fix']} (request {body['request_id']})")Ihe ị na-enweta azịza: ole ka e debere, ole e mere, na ole e melitere, yana kọntaktị 100 mbụ dịka a debere ha.
{
"success": true,
"request_id": "u8wqb",
"saved": 1,
"created": 0,
"updated": 1,
"contacts": [
{
"identity": "61412345678",
"identity_type": "phone",
"phone": "61412345678",
"name": "John Smith",
"tags": ["vip", "newsletter"],
"custom_fields": { "first_name": "John", "crm_id": "C-1001", "order_id": "1234" },
"source": "crm",
"consent": {
"marketing": true,
"at": "2026-10-01T09:00:00Z",
"source": "web form",
"text": "Yes, send me offers on WhatsApp",
"evidence": "https://example.com/forms/123",
"recorded": true
},
"last_inbound_at": "2026-10-26T01:20:44Z",
"created": "2026-10-01T09:00:10Z",
"updated": "2026-11-21T09:00:00Z"
}
]
}Arịrịọ nke ruo kọntaktị 50 na-eziga contact.updated maka onye ọ bụla; ndepụta buru ibu adịghị. Iji gbanwee naanị ụfọdụ ubi nke otu kọntaktị, PATCH /contacts/{identity} na-ewere otu ubi ahụ, ma naanị ndị ejiri nye na-agbanwe:
curl -s -X PATCH https://api.app2email.com/v1/YOUR_NUMBER/contacts/61412345678 \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: application/json" \
-d '{ "tags": ["vip", "newsletter", "repeat_buyer"] }'PATCH na-azaghachi 404 contact_not_found maka kọntaktị app2email enweghị ruo ugbu a, ya mere sync dị mfe ka ọ bụrụ POST /contacts n'ebe niile.
Mgbe onye kwenyere na ahịa n'CRM gị (fom weebụ, akụkụ a na-ahọrọ na checkout), debe ya na kọntaktị ahụ na okwu ya na ihe akaebe ya. Ị nwere ike iziga otu object consent n'ime POST /contacts, ma ọ bụ jiri oku nkwenye, nke na-emepụtakwa kọntaktị mgbe ọ dị ọhụrụ. at bụ oge a ugbu a ma ọ bụrụ na ị hapụ ya.
curl -s https://api.app2email.com/v1/YOUR_NUMBER/contacts/61412345678/consent \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: application/json" \
-d '{
"marketing": true,
"source": "web form",
"text": "Yes, send me offers on WhatsApp",
"evidence": "https://example.com/forms/123"
}'await fetch("https://api.app2email.com/v1/YOUR_NUMBER/contacts/61412345678/consent", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.A2E_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
marketing: true,
source: "web form",
text: "Yes, send me offers on WhatsApp",
evidence: "https://example.com/forms/123",
}),
});requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/contacts/61412345678/consent",
headers=HEADERS,
json={
"marketing": True,
"source": "web form",
"text": "Yes, send me offers on WhatsApp",
"evidence": "https://example.com/forms/123",
},
timeout=10,
)Ihe ị na-enweta azịza: kọntaktị ahụ, nwere consent.recorded: true, na ihe omume contact.updated nwere change: "consent" na-esonye ya.
Mgbe onye kwụsịrị na CRM gị, mee ihe abụọ:
"marketing": false. Segment nwere consent_marketing: true ga-ewepụ ha.dnc:manage, ruo nọmba 1000 kwa oku, ihe niile ma ọ bụ enweghị ihe ọ bụla):curl -s https://api.app2email.com/v1/YOUR_NUMBER/donotcall \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: application/json" \
-d '{ "numbers": [ { "number": "61498765432", "name": "Mary", "note": "Unsubscribed in our CRM" } ] }'Azịza na-edepụta nọmba ndị dị na added na ndị dị n'ndepụta tupu nke a na already_on_list.
Naanị debe nkwenye ị nwere n'ezi. Ọ bụrụ na nọmba gị na-eji iwu nhọrọ maka ahịa (PUT /settings/optin), iwu ahụ na-elele ndekọ nhọrọ, nke a na-edobe ka ọ dị iche na nkwenye kọntaktị. Debanye ndị ahụ site na POST /optins (ikike settings:manage) kwa. Nkuzi mgbasa ozi ahịa na-egosi otu esi eme ya.
Otu oku. Azịza nwere nzuzo mbinye aka (whsec_...) nke na-abịnye ihe omume ọ bụla: debe ya dị ka WEBHOOK_SECRET.
curl -s -X POST https://api.app2email.com/v1/YOUR_NUMBER/webhooks \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: application/json" \
-d '{ "url": "https://crm-sync.example.com/app2email" }'Ihe ị na-enweta azịza (201 Created, dị mkpụmkpụ):
{
"success": true,
"request_id": "w8hk2",
"webhook": {
"id": "wh_a1b2c3d4e5f6g7h8",
"url": "https://crm-sync.example.com/app2email",
"secret": "whsec_...",
"active": true,
"format": "app2email"
}
}Webhook ọ bụla nke nọmba ahụ na-anata ihe omume ọ bụla (ruo webhook 5 kwa nọmba), ya mere onye na-anata gị na-ahọrọ ụdị ya site na type ma zaghachi 2xx maka ndị ọzọ niile. Idebanye otu URL ọzọ na-enyekwa webhook ahụ azịza, ya mere oku a dị nchekwa ịmegharị.
Enweghị adreesị ọha? GET /events?types=contact.updated,contact.opted_out,contact.changed_number,message.received&wait=25 na-enweta otu ihe omume ahụ. Debe cursor nke azịza ahụ wee nye ya dịka after na oku ọzọ. Oku mbụ na-emeghe feed ahụ, ihe omume ka echekwara ruo awa 72 site n'oge ahụ.
Onye na-anata gị na-enyocha akara, na-agafe ihe omume ọ mere ụbọchị, na-azaghachi 200 ozugbo, mgbe ahụ na-emelite CRM.
import crypto from "node:crypto";
import express from "express";
function verifyWebhook(rawBody, header, secret, toleranceSeconds = 300) {
const t = /(?:^|,)\s*t=(\d+)/.exec(header ?? "")?.[1];
const v1 = [...(header ?? "").matchAll(/(?:^|,)\s*v1=([0-9a-f]+)/g)].map((m) => m[1]);
if (!t || v1.length === 0 || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSeconds) return false;
const expected = crypto.createHmac("sha256", secret).update(t + ".").update(rawBody).digest("hex");
return v1.some((v) => v.length === expected.length && crypto.timingSafeEqual(Buffer.from(v), Buffer.from(expected)));
}
const app = express();
app.post("/app2email", express.raw({ type: "application/json" }), async (req, res) => {
if (!verifyWebhook(req.body, req.get("X-App2email-Signature"), process.env.WEBHOOK_SECRET)) return res.sendStatus(401);
const eventId = req.get("X-App2email-Delivery");
if (await alreadySeen(eventId)) return res.sendStatus(200); // a retry
const event = JSON.parse(req.body);
res.sendStatus(200); // answer within 10 seconds, then do the work
if (event.test) return; // test events carry made-up contacts
const d = event.data;
switch (event.type) {
case "contact.opted_out": // STOP, "Stop promotions" or one of your opt-out words
await crm.markUnsubscribed(d.number, { channel: "whatsapp", reason: d.source, at: d.timestamp });
break;
case "contact.updated": {
if (d.change === "marketing_resumed") {
await crm.noteMarketingResumed(d.contact.identity, d.timestamp);
break;
}
// upsert, patch or consent: write only what differs, so your own pushes do not loop
const c = d.contact;
const current = await crm.findByIdentity(c.identity);
if (current && sameValues(current, c)) break;
await crm.save(c.identity, { name: c.name, tags: c.tags, fields: c.custom_fields, consent: c.consent });
break;
}
case "contact.changed_number":
if (d.change === "user_changed_number") await crm.changePhone(d.previous.phone, d.new.phone);
else await crm.changeUserId(d.previous.user_id, d.new.user_id);
break;
case "message.received": // someone wrote: a lead, or a "last contacted" date
await crm.touch(d.from ?? d.from_user_id, { name: d.name, lastInboundAt: d.timestamp });
break;
}
await markSeen(eventId);
});
app.listen(3000);import hashlib, hmac, json, os, re, time
from flask import Flask, request
def verify_webhook(raw_body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
t = re.search(r"(?:^|,)\s*t=(\d+)", header or "")
v1 = re.findall(r"(?:^|,)\s*v1=([0-9a-f]+)", header or "")
if not t or not v1 or abs(time.time() - int(t.group(1))) > tolerance:
return False
expected = hmac.new(secret.encode(), t.group(1).encode() + b"." + raw_body, hashlib.sha256).hexdigest()
return any(hmac.compare_digest(v, expected) for v in v1)
app = Flask(__name__)
@app.post("/app2email")
def app2email():
raw = request.get_data()
if not verify_webhook(raw, request.headers.get("X-App2email-Signature"), os.environ["WEBHOOK_SECRET"]):
return "", 401
event_id = request.headers.get("X-App2email-Delivery")
if already_seen(event_id):
return "", 200 # a retry
queue.put(json.loads(raw)) # a worker calls handle(event) after the answer
mark_seen(event_id)
return "", 200 # within 10 seconds
def handle(event):
if event.get("test"):
return # test events carry made-up contacts
d = event["data"]
t = event["type"]
if t == "contact.opted_out":
crm.mark_unsubscribed(d["number"], channel="whatsapp", reason=d["source"], at=d.get("timestamp"))
elif t == "contact.updated":
if d["change"] == "marketing_resumed":
crm.note_marketing_resumed(d["contact"]["identity"], d.get("timestamp"))
return
c = d["contact"]
current = crm.find_by_identity(c["identity"])
if current and same_values(current, c):
return # your own push coming back: nothing to do
crm.save(c["identity"], name=c.get("name"), tags=c.get("tags", []),
fields=c.get("custom_fields", {}), consent=c.get("consent"))
elif t == "contact.changed_number":
if d["change"] == "user_changed_number":
crm.change_phone(d["previous"].get("phone"), d["new"].get("phone"))
else:
crm.change_user_id(d["previous"].get("user_id"), d["new"].get("user_id"))
elif t == "message.received":
crm.touch(d.get("from") or d.get("from_user_id"), name=d.get("name"), last_inbound_at=d.get("timestamp"))crm.*, alreadySeen, markSeen na sameValues bụ koodu gị nke onwe ya. Nwalee onye na-anata gị site na POST /webhooks/{id}/test na ihe dịka {"type": "contact.opted_out"}: ị na-enweta ihe atụ ihe omume ahụ e mbinyere aka, nwere "test": true.
Segment bụ nzacha echekwara n'elu kọntaktị gị, ya mere ndepụta ị na-echekwa na CRM gị nwere ike ịghọ ndị na-ege ntị n'enweghị ịdeta nọmba. Ihe ọ bụla enyere ga-adị mma: tags_any, tags_all, consent_marketing, last_inbound_days (dere gị n'ime N ụbọchị gara aga, 1 ruo 3650) na search (akụkụ aha ma ọ bụ nọmba). Ruo segment 100 kwa nọmba.
curl -s https://api.app2email.com/v1/YOUR_NUMBER/segments \
-H "Authorization: Bearer $A2E_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "VIP, consented",
"filter": { "tags_any": ["vip"], "consent_marketing": true, "last_inbound_days": 90 }
}'const res = await fetch("https://api.app2email.com/v1/YOUR_NUMBER/segments", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.A2E_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
name: "VIP, consented",
filter: { tags_any: ["vip"], consent_marketing: true, last_inbound_days: 90 },
}),
});
const { segment } = await res.json();
console.log(segment.id, segment.contacts);res = requests.post(
"https://api.app2email.com/v1/YOUR_NUMBER/segments",
headers=HEADERS,
json={"name": "VIP, consented",
"filter": {"tags_any": ["vip"], "consent_marketing": True, "last_inbound_days": 90}},
timeout=10,
)
segment = res.json()["segment"]
print(segment["id"], segment["contacts"])Ihe ị na-enweta azịza (HTTP 201): segment nwere id, name, filter, created, updated na contacts, ole kọntaktị dabara ugbu a. GET /segments/{id}/contacts na-edepụta ha (ibe site na next_cursor), na id ma ọ bụ aha kpọmkwem na-arụ ọrụ n'ụzọ.
Segment na-esochi kọntaktị gị: mgbe sync na-agbanwe tag ma ọ bụ nkwenye, ndị otu segment na-agbanwe ya. Zipu template gaa ya site na "segment": "VIP, consented" na POST /messages; uru template aha nke enweghị uru nke ya ka a na-ejuputa site na custom_fields nke onye ọ bụla (name site na aha kọntaktị). Lee Zipu mgbasa ozi ahịa nke na-asọpụrụ nkwenye. Usoro ndọrọ ndọrọ nwere enrol_tag na-ebanye kọntaktị ndị nwetara tag ahụ site n'oge ahụ gaa n'ihu: lee Solite ndọrọ ndọrọ akpaaka site na usoro ndọrọ ndọrọ.
Ihe omume kpuchie mgbanwe API, nhọrọ ịpụ na mgbanwe nọmba, mana contact.updated adịghị ezipụ maka ibubata, maka ndepụta upsert karịa kọntaktị 50, ma ọ bụ maka mgbanwe a na-eme na mpụga API. Otu abalị (ma ọ bụ otu izu), gụọ kọntaktị ọ bụla wee tụnyere.
GET /contacts na-agafe n'ime kọntaktị, ọhụrụ kacha, ruo 200 kwa ibe. Sịfụta site na tag, consent (true ma ọ bụ false) ma ọ bụ q (akụkụ aha ma ọ bụ nọmba) mgbe ị chọrọ naanị ụfọdụ.
curl -s "https://api.app2email.com/v1/YOUR_NUMBER/contacts?limit=200" \
-H "Authorization: Bearer $A2E_KEY"
# next page: add &cursor=<next_cursor of the previous answer>export async function* allContacts() {
let cursor;
do {
const url = new URL("https://api.app2email.com/v1/YOUR_NUMBER/contacts");
url.searchParams.set("limit", "200");
if (cursor) url.searchParams.set("cursor", cursor);
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.A2E_KEY}` } });
const page = await res.json();
yield* page.contacts;
cursor = page.next_cursor;
} while (cursor);
}
for await (const c of allContacts()) {
if (new Date(c.updated) > lastReconcile) await compareWithCrm(c);
}def all_contacts():
cursor = None
while True:
params = {"limit": 200}
if cursor:
params["cursor"] = cursor
page = requests.get("https://api.app2email.com/v1/YOUR_NUMBER/contacts",
headers=HEADERS, params=params, timeout=30).json()
yield from page["contacts"]
cursor = page.get("next_cursor")
if not cursor:
break
for c in all_contacts():
if c["updated"] > last_reconcile_iso:
compare_with_crm(c)Ihe ị na-enweta azịza: contacts (ọ bụla n'ụdị egosiri na nzọụkwụ upsert), count n'ibe a, total, na next_cursor ruo ibe ikpeazụ.
Maka spreadsheet ma ọ bụ nchekwa, GET /contacts/export.csv na-enye kọntaktị ọ bụla dị ka faịlụ CSV otu (ruo ahịrị 50,000): otu ahịrị kwa kọntaktị, tags e kewapụrụ site na |, nkwenye, na ubi nke onye ọrụ dị ka JSON.
curl -s https://api.app2email.com/v1/YOUR_NUMBER/contacts/export.csv \
-H "Authorization: Bearer $A2E_KEY" -o contacts-export.csvCRM gị na app2email ugbu a nwere otu ndị mmadụ nwere otu tags, ubi na nkwenye. Nke a bụ ihe na-abịa na webhook gị, na mgbe ọ na-abịa.
| Ihe omume | Mgbe ọ na-abịa | Ihe CRM gị na-eme |
|---|---|---|
contact.opted_out | Kọntaktị zara STOP (ma ọ bụ otu n'ime okwu nhọrọ ịpụ gị) ma ọ bụ pịa "Stop promotions". Ọ dị na ndepụta Do Not Call ugbu a. source bụ stop_promotions, whatsapp_stop ma ọ bụ keyword | Kpọọ ha dị ka ndị kwụsịrị ozi ahịa WhatsApp |
contact.updated nwere change upsert, patch ma ọ bụ consent | A mepụtara ma ọ bụ gbanwere kọntaktị site na API: sync gị, ndọrọ ndọrọ ọzọ, ma ọ bụ onye nnọchi AI na-eji ngwá ọrụ MCP upsert_contact | Debe ihe dị iche |
contact.updated nwere change: "marketing_resumed" | Kọntaktị gbanwere ozi ahịa site na gị ka ọ na-arụ ọrụ n'ime WhatsApp | Dee ya. Ọ bụghị nkwenye ọhụrụ: debe nkwenye naanị mgbe ị nwere ya |
contact.changed_number | Kọntaktị gaa nọmba WhatsApp ọhụrụ (user_changed_number), ma ọ bụ user id nke azụmahịa ha gbanwere (user_changed_user_id) | Melite ekwentị ma ọ bụ id na ndekọ CRM |
message.received | Kọntaktị dere gị ma ọ bụ pịa bọtịnụ | Mepụta onye ndụmọdụ, ma ọ bụ tinye "kpọtụrụ ikpeazụ" |
Kọntaktị echekwara site na API (contact.updated):
{
"id": "evt_Xq3k9m2Lw8Rt5Yp1Zs01",
"type": "contact.updated",
"created": "2026-11-06T01:00:00.000Z",
"number": "4976659348270",
"data": {
"contact": {
"identity": "61412345678",
"identity_type": "phone",
"phone": "61412345678",
"name": "Sample Contact",
"tags": ["vip"],
"custom_fields": { "city": "Sydney" },
"source": "api",
"consent": {
"marketing": true,
"at": "2026-11-06T01:00:00.000Z",
"source": "website form",
"recorded": true
},
"created": "2026-11-06T01:00:00.000Z",
"updated": "2026-11-06T01:00:00.000Z"
},
"change": "upsert",
"timestamp": "2026-11-06T01:00:00.000Z"
}
}Nhọrọ ịpụ (contact.opted_out):
{
"id": "evt_Xq3k9m2Lw8Rt5Yp1Zs01",
"type": "contact.opted_out",
"created": "2026-11-06T01:00:00.000Z",
"number": "4976659348270",
"data": {
"number": "61412345678",
"name": "Sample Contact",
"source": "stop_promotions",
"detail": "Stop promotions",
"timestamp": "2026-11-06T01:00:00.000Z"
}
}Nọmba ọhụrụ (contact.changed_number):
{
"id": "evt_Pa3k9m2Lw8Rt5Yp1Zs03",
"type": "contact.changed_number",
"created": "2026-11-06T01:00:00.000Z",
"number": "4976659348270",
"data": {
"change": "user_changed_number",
"previous": { "phone": "61412345678", "user_id": "AU.9876543210987654" },
"new": { "phone": "61498765432", "user_id": "AU.1234567890123456" },
"name": "Sample Contact",
"body": "User Sample Contact changed from 61412345678 to 61498765432",
"message_id": "wamid.HBgLNjE0MTIzNDU2NzgVAgARGBJTQU1QTEVfVEVTVF9FVkVOVAA=",
"conversation_url": "https://www.app2email.com/conversation/61412345678_4976659348270_SAMPLEk3XbQ9rTzP2mW",
"timestamp": "2026-11-06T01:00:00.000Z"
}
}N'ihe omume ọ bụla, number n'elu bụ nọmba WhatsApp gị; kọntaktị nọ n'ime data. Ubi nke enweghị uru a na-ehapụ, ya mere ghọta ubi ọ bụla dị ka nhọrọ ma e wezụga ndị ị na-atụnye ya. GET /webhooks/samples na-enye ihe atụ nke ụdị ihe omume ọ bụla.
DELETE /contacts/{identity} na-ehichapụ ndekọ kọntaktị. Ndepụta Do Not Call na ndekọ nhọrọ ahịa dị iche ma nọgide, ya mere mmadụ kwuru STOP ka na-echebe mgbe ehichapụsịrị ya. Nzukọ ha, ndetu na ịkwụ ụgwọ ka a na-echekwa, belụsọ na ị tinye ?booking_data=erase: nke ahụ na-ehichapụ ma ọ bụ mezie data ndebanye ha na tikiti, enweghị ike ịkagbu ya, ma ọ bụ maka arịrịọ mkpochapụ. A na-ajụ ya, na ihe kpatara ya na note, mgbe kọntaktị nwere tikiti dị irè maka ụbọchị na-abịa.
curl -s -X DELETE "https://api.app2email.com/v1/YOUR_NUMBER/contacts/61412345678" \
-H "Authorization: Bearer $A2E_KEY"Ihe omume ọ bụla nwere isi X-App2email-Signature: t=<unix seconds>,v1=<hex>. Uru v1 bụ HMAC-SHA256 nke "<t>.<raw body>", nwere nzuzo webhook (whsec_..., gụnyere prefix) dị ka igodo. Lelee ọ bụla v1= (abụọ mgbe igodo ochie ka edobere mgbe a gbanwere ya), gbakọta ya n'elu raw body dịka a natara ya, wee jụ t ochie. Jụ ihe omume dara nyocha a: onye ọ bụla nwere ike izipu gaa URL ọha, ma contact.opted_out ma ọ bụ contact.changed_number ezighi ezi ga-agbanwe CRM gị.
Zaghachi site na ọnọdụ 2xx n'ime sekọnd 10. Ọ bụghị ya, a ga-ezipụ ihe omume ọzọ mgbe sekọnd 10, nkeji 1, nkeji 5, nkeji 30, awa 1, 2, 4, 8 na 16. X-App2email-Delivery (id ihe omume, evt_...) dịkwa otu n'ọzọ ọ bụla: debe ya ma hapụ ihe omume ị rụchara.
Upsert gị nke ruo kọntaktị 50 na-alaghachi dị ka contact.updated. Ọ bụrụ na CRM gị na-eziga mgbanwe gaa app2email mgbe ọ bụla a chekwara ndekọ, ide ihe omume ahụ azụ gaa CRM na-echekwa ndekọ ahụ ọzọ, ma usoro abụọ ahụ ga-ebikọ ruo ebighị ebi. Tụnyere mbụ, dee naanị ubi dị iche. Tụnyere ndekọ site na identity, ọ bụghị site na aha: aha adịghị iche ma ndị mmadụ na-agbanwe ha.
Oku kọntaktị anaghị ewere isi Idempotency-Key, ma ha achọghị ya: upsert nke e tụnyere site na identity nwere ike izipu ọzọ mgbe oge agwụla ma ọ bụ 500, kọntaktị ahụ ga-anọ otu ahụ, ọ bụghị ugboro abụọ. Otu ihe ahụ dị maka ahịrị ibubata. Zipu bulọọkụ consent naanị mgbe nkwenye onwe ya gbanwere, ọ bụghị n'oge sync ọ bụla, ka oge at ya na ihe akaebe ya bụrụ nke nkwekọrịta n'ezi. POST /donotcall na-ahapụ nọmba ndị dị n'ndepụta ka ha nọgide dị otu.
Zipu ndepụta, ọ bụghị oku otu maka kọntaktị ọ bụla: ruo kọntaktị 1000 kwa POST /contacts, ruo ahịrị 5000 kwa POST /contacts/import, kọntaktị 200 kwa ibe nke GET /contacts. Azịza ọ bụla nwere X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset (sekọnd ruo ọ juru ọzọ) na X-RateLimit-Policy; limits na GET /me na-egosi requests_per_second na burst nke igodo ahụ. Ọ bụrụ na ị gafere oke ahụ, ị na-enweta 429 rate_limited nwere isi Retry-After na error.retry_after_seconds: chere ogologo oge ahụ, mgbe ahụ zipu arịrịọ otu ahụ ọzọ.
4xx ọ bụla ọzọ: ekwesịghị igbalị ọzọ n'otu ụzọ. Kpebie site na error.code, soro how_to_fix, ma kọwaa request_id gaa support. error.is_retriable na-egosi ma arịrịọ otu ahụ nwere ike ịrụ ọrụ mgbe e mesịrị.
consent kọntaktị bụ ihe akaebe Spam Act 2003 chọrọ ka ị nwee ike igosi: oge, ebe, okwu na ihe akaebe. Debe nkwenye naanị ndị ị nwere n'ezi.contact.opted_out. Dee ya na CRM gị, ma ejila wepụ ha na ndepụta site na CRM gị ọ bụrụ na ha ekwenyeghị ọzọ."marketing": false na kọntaktị na POST /donotcall.contact.updated nwere marketing_resumed pụtara na onye ahụ gbanwere ozi ahịa gị ka ọ na-arụ ọrụ n'ime WhatsApp. Ọ bụ ihe ịrịba ama, ọ bụghị nkwenye nwere ihe akaebe.GET /compliance/export.csv (ikike dnc:manage) na-enye ndekọ nkwenye, ndepụta Do Not Call na nhọrọ ahịa dị ka faịlụ otu.Kọntaktị na segment na-ekpebi naanị onye ga-enweta ozi. Ịmalite mkparịta ụka, ma ọ bụ ide mgbe ozi ikpeazụ onye kọntaktị karịrị awa 24, ka chọrọ template a kwadoro; n'ime oge ahụ ị nwere ike izipu ozi nkịtị. GET /conversations/{contact} na-egosi window_state na window_closes_at. Lee Zipu ozi order na nzukọ site na template.
Igodo sync nwere ike ịgụ ma gbanwee kọntaktị niile. Debe ya na mgbanwe gburugburu sava gị, ọ bụghị na ibe weebụ ma ọ bụ ubi CRM ndị ọzọ nwere ike ịhụ. Igodo nwere ike ịgbanwe naanị n'adreesị IP sava gị (oku site n'ebe ọzọ na-azaghachi 403 ip_not_allowed) ma nwee ike ịgwụ; nye naanị ikike ihe nkuzi a chọrọ.
Njehie ọ bụla bụ JSON nwere error.code, message, how_to_fix na request_id iji kọwaa gaa support. Lee Njehie maka koodu niile na Oke maka oke ndị ahụ.
| Koodu | Mgbe | Ihe ị ga-eme |
|---|---|---|
403 insufficient_scope | Igodo enweghị ikike (details.required_scope), na-abụkarị contacts:manage na igodo Default | Mepụta igodo nwere ikike ndị dị n'tebụl n'elu, ma ọ bụ Full access |
403 not_in_instant_sandbox | Oku kọntaktị na nọmba demo 12025550100 | Jiri nọmba gị jikọrọ nke onwe gị |
403 api_key_number_mismatch | Igodo na nọmba dị na URL adabeghị ọnụ, dịka igodo nke nọmba n'ezi ejiri nọmba demo | Jiri igodo nke nọmba dị na URL |
401 missing_api_key, invalid_api_key, api_key_revoked, api_key_expired | Enweghị igodo, igodo ezighi ezi, ma ọ bụ igodo ewepụrụ ma ọ bụ gwụrụ | Zipu Authorization: Bearer YOUR_API_KEY nwere igodo dị na ibe igodo API |
403 plan_not_allowed, 403 service_not_live | Enweghị atụmatụ ịkwụ ụgwọ, ma ọ bụ ọrụ akwụsịrị | Lelee atụmatụ na ọnọdụ ọrụ na dashboard |
400 invalid_contacts | Kọntaktị dị na ahụ ezighi ezi, ma ọ bụ enweghị ihe a ga-agbanwe | Zipu {"phone": "61412345678", "name": "John", "tags": ["vip"]} ma ọ bụ ndepụta ha |
400 too_many_numbers | Kọntaktị karịrị ihe a nyere n'arịrịọ otu (1000 maka POST /contacts) | Kewaa ndepụta, ma ọ bụ jiri POST /contacts/import (ruo ahịrị 5000) |
400 invalid_csv | CSV enweghị ahịrị isi ma ọ bụ ahịrị kọntaktị | Zipu ahịrị isi na ahịrị ọ bụla, dị ka text/csv |
400 invalid_json | Ahụ abụghị JSON ziri ezi | Lelee quotes, comma na bracket nso ebe e kwuru na ozi ahụ |
413 request_too_large | Ahụ buru ibu | Zipu faịlụ n'obere akụkụ |
Ahịrị na errors nke ibubata | Otu ahịrị agụghị, dịka nọmba na-enweghị koodu mba | Dozie ahịrị ahụ wee bubata ya ọzọ; ahịrị ndị ọzọ echekwara |
400 invalid_phone | Kọntaktị dị na URL abụghị nọmba ma ọ bụ user id nke azụmahịa | Jiri nọmba zuru ezu, koodu mba nke mbụ, naanị ọnụọgụgụ (/contacts/61412345678) |
404 contact_not_found | GET ma ọ bụ PATCH maka kọntaktị app2email enweghị | Lelee identity; POST /contacts na-emepụta ya |
400 invalid_numbers | POST /donotcall nwere nọmba ezighi ezi (details.invalid); enweghị ihe a tinyere | Dozie nọmba edepụtara wee zipu oku ahụ ọzọ |
400 invalid_segment | Aha segment efu, karịa mkpụrụedemede 100, ma ọ bụ naanị nọmba | Zipu {"name": "VIP, consented", "filter": {...}} |
409 segment_exists | Segment nwere aha ahụ dị | Jiri aha ọzọ, ma ọ bụ gbanwee ya site na PUT /segments/{id} |
400 too_many_segments | Nọmba nwere segment 100 | Hichapụ otu ị na-achọghịzi |
404 segment_not_found | Enweghị segment nwere id ma ọ bụ aha ahụ | GET /segments na-edepụta ha; jiri id ma ọ bụ aha kpọmkwem |
400 invalid_cursor | Agbanwere cursor ma ọ bụ ọ sitere na ndepụta ọzọ | Zipu next_cursor na-agbanwegharị, ma ọ bụ hapụ ya maka ibe mbụ |
429 rate_limited | Oku ndị dị ukwuu maka igodo a | Chere sekọnd Retry-After, mgbe ahụ zipu arịrịọ otu ahụ ọzọ |
| Ihe omume adịghị abịa | A kpọchiri webhook mgbe nnyefe dara ọtụtụ ugboro, ma ọ bụ URL gị adịghị azaghachi 2xx n'ime sekọnd 10 | Lee GET /webhooks/{id}/deliveries; mee ka ọ rụọ ọrụ ọzọ site na PATCH /webhooks/{id} na {"active": true} |
Enweghị contact.updated mgbe sync | Ibubata, na ndepụta upsert karịa kọntaktị 50, enweghị ihe omume | A tụrụ anya ya; tụnyere site na GET /contacts ọzọ |
Zipu template gaa segment kọntaktị ndị kwenyere, soro nsonaazụ site na nọmba ọ bụla.
Banye kọntaktị site na tag ma zipu usoro template n'oge nke ha.
Gbaa sync na izipu site na ngwa akpaaka, na-enweghị ide sava.
Mepụta template utility, nweta nkwenye ya, ma soro ozi ọ bụla.