Skip to content

Sync customers

Needs: customers:read customers:write

When your team opens a chat or ticket, they see the customer’s name, email, phone, labels and your own fields. Syncing customers from your system means that information is already there, and correct.

  • Customers belong to one product. The same email under two products is two customers.
  • The email is unique within a product. Creating a second customer with an email that’s already there answers 409 CUSTOMER_EMAIL_TAKEN.
  • Your own ID. Give each customer an external_id: their ID in your system (up to 255 characters, no spaces). It’s unique within the product (409 CUSTOMER_EXTERNAL_ID_TAKEN), so it’s the reliable way to find the same person again, even if their email changes.
  • Stages. Each contact is a subscriber (wrote in on a channel), lead (has an open deal) or customer. Customers you create are customer unless you set stage.
  • Labels are short tags such as vip. Fields are your own custom fields (plan, account number, city), set up in the dashboard under the product’s customer settings.

Look the customer up by your own ID, then create or update. external_id finds a customer at any stage:

const base = `https://api.supportaka.com/api/v1/organizations/${org}/products/${product}`;
const headers = { Authorization: `Bearer ${process.env.SUPPORTAKA_KEY}`, 'Content-Type': 'application/json' };
async function upsertCustomer(user) {
const query = new URLSearchParams({ external_id: String(user.id) });
const { items } = await fetch(`${base}/customers?${query}`, { headers }).then((r) => r.json());
const existing = items[0];
const body = JSON.stringify({
external_id: String(user.id), // your own user ID
name: user.fullName,
email: user.email,
phone: user.phone ?? '', // E.164, e.g. +2348012345678; '' clears it
labels: user.isVip ? ['vip'] : [],
fields: { plan: user.plan, city: user.city },
});
const res = existing
? await fetch(`${base}/customers/${existing.id}`, { method: 'PATCH', headers, body })
: await fetch(`${base}/customers`, { method: 'POST', headers, body });
if (!res.ok) throw new Error((await res.json()).code);
return res.json();
}

PATCH changes only what you send. An empty string clears the email, phone or external_id. labels replaces the customer’s labels, so send the full set. fields changes only the keys you send, and null clears one. An unknown field key is 400 VALIDATION_FAILED naming fields.<key>.

List the product’s fields to see their keys and types:

Terminal window
curl https://api.supportaka.com/api/v1/organizations/$ORG/products/$PRODUCT/customer-fields \
-H "Authorization: Bearer $SUPPORTAKA_KEY"

Each field has a key (what you send in fields), a type (text, number, date, boolean or select) and, for a select, its options. Fields are created in the dashboard.

GET …/customers filters with:

Parameter Keeps customers…
external_id with that ID from your system, at any stage
q whose name or email contains the text
stage at that stage: subscriber, lead, customer, or all
label with that label
field + field_value whose custom field equals the value
source who first came from that source, such as whatsapp or email

Customers also arrive by themselves, when someone writes to you on WhatsApp or the website widget. To hear about them, subscribe a webhook to customer.created and customer.updated. They carry the customer’s id and your external_id (or null), so you can match them to your records straight away, then fetch the details:

Terminal window
curl https://api.supportaka.com/api/v1/organizations/$ORG/products/$PRODUCT/customers/$CUSTOMER_ID \
-H "Authorization: Bearer $SUPPORTAKA_KEY"

Each plan allows a number of contacts across the organization. Past it, creating answers 409 CONTACT_LIMIT_REACHED with details.limit and details.used.