Connect a CRM
This page connects a CRM, or any system of your own, to a business's Welkai: contacts kept under your own record ids, messages sent from your system, every new message sent back to it, flows started from it, and Welkai's flow editor shown inside it. Each step has a request you can copy. The business owner's version of this guide, in plain words, is Connect your CRM in the dashboard's help.
The examples use https://your-business.welkai.net: use the business's own address. The basic API (contacts, sending, starting a flow) needs the Growth plan or higher; setting the webhook address and reading the delivery log through the API need Business or higher. See which plans.
1. Make an API key
In the dashboard: API and webhooks, API keys, New API key. Name it after the CRM ("HubSpot sync"), keep Read, Send and Contacts, add Flows to start flows and Numbers to manage the webhook, pick the numbers it may use, and copy the key: it is shown once. Store it like a password, on your server only.
Check it:
curl https://your-business.welkai.net/auth/me \
-H "Authorization: Bearer <your key>"
2. Find the numbers
curl https://your-business.welkai.net/devices \
-H "Authorization: Bearer <your key>"
Each entry has its id and channel (whatsapp, whatsapp_api, facebook, instagram, telegram, telegram_account or email). Send the id as X-Device-Id on every call about that number. With only one number it may be left out.
3. Keep contacts under your own id
Give each contact your CRM's record id as external_id. Adding a contact with it finds the number's contact holding that id first, so the same call adds or updates:
curl -X POST https://your-business.welkai.net/contacts \
-H "Authorization: Bearer <your key>" -H "X-Device-Id: <number id>" \
-H "Content-Type: application/json" \
-d '{"phone": "+60123456789", "name": "Aisyah Rahman", "external_id": "crm-10042",
"tags": ["customer"], "fields": {"plan": "gold"}}'
external_idis 1 to 128 characters, anything but control characters and/. It is unique on one number: another contact of that number holding it answers 409contact.external_id_taken, withparams.jidnaming that contact. A bad id answers 400contact.external_id_invalid.- The same id on the same person's other channels (their WhatsApp and their email) is allowed and expected.
- Phone numbers go in international format with
+and the country code. - Change or remove the id with
PATCH /contacts/<contact>and{"external_id": "..."}(""removes it).
Every /contacts/<contact> route takes ext: and your id in place of the phone or chat id:
curl https://your-business.welkai.net/contacts/ext:crm-10042 \
-H "Authorization: Bearer <your key>" -H "X-Device-Id: <number id>"
URL-encode the id when it has characters a path cannot carry. To find the person on every number at once, without X-Device-Id:
curl https://your-business.welkai.net/customers/by-external-id/crm-10042 \
-H "Authorization: Bearer <your key>"
No match answers an empty list, not 404. Contacts can also be imported from a CSV file with an external_id column in the dashboard.
4. Send a message
curl -X POST https://your-business.welkai.net/send/message \
-H "Authorization: Bearer <your key>" -H "X-Device-Id: <number id>" \
-H "Content-Type: application/json" \
-d '{"phone": "+60123456789", "message": "Your order A-1001 is on its way.", "kind": "transactional"}'
kind: "transactional" marks a message the person expects right now (an order update, a code, a delivery): it skips the business's sending hours and the three-a-day limit per person, and still counts toward the number's daily safety limit. Leave it out for anything else. Images, files, templates and the other channels' sends are in the API reference under Send.
5. Receive what happens
Point the number's webhook at your CRM, keep the signing secret, and send a test:
curl -X PATCH https://your-business.welkai.net/devices/<number id>/webhook \
-H "Authorization: Bearer <your key>" -H "Content-Type: application/json" \
-d '{"webhook_url": "https://crm.example.com/welkai", "webhook_events": "message,contact.opted_out"}'
curl -X POST https://your-business.welkai.net/devices/<number id>/webhook/test \
-H "Authorization: Bearer <your key>"
The business owner can do the same in the dashboard without a key. On your side:
- Check
X-Welkai-Signatureand its timestamp before you parse the body (code in four languages). - Answer 2xx within 10 seconds; do the work after answering.
- Store
X-Welkai-Deliveryand skip a repeat: delivery is at least once. A delivery sent again by hand has a new id andX-Welkai-Resend-Ofnaming the first. - Order by the payload's
timestamp, never by arrival: no order is promised. - Match the person by
payload.contact_external_id(your id, when the contact has one), else bypayload.fromorpayload.chat_id.
The full rules are on Webhooks.
6. Start a flow from the CRM
A flow is an automated conversation built in the dashboard. Start a published, switched-on flow for up to 1,000 contacts (key scope flows):
curl -X POST https://your-business.welkai.net/flows/<flow id>/start \
-H "Authorization: Bearer <your key>" -H "Content-Type: application/json" \
-d '{"contacts": [{"phone": "+60123456789", "name": "Aisyah", "vars": {"order_id": "A-1001"}}]}'
This sends real messages. The first contact starts at once and the rest are spread 4 to 12 seconds apart. Each contact may carry up to 50 variables, used in the flow as {{order_id}}. Contacts who opted out of campaigns are left out and counted in skipped_opted_out. Send tags instead of contacts to start it for every contact with those tags.
Without an API key: the flow's own trigger address
A flow whose trigger is Webhook has its own address and key, for systems that cannot hold an API key, such as a form tool or a shop's order hook. The business makes the key in the flow's Flow settings, Webhook trigger (it is shown once; making a new one replaces the old), and gives you the trigger address and key. It is not an API route, so it is not in the reference:
curl -X POST https://your-business.welkai.net/flows/<flow id>/trigger \
-H "X-Flow-Key: <flow key>" -H "Content-Type: application/json" \
-d '{"phone": "+60123456789", "name": "Aisyah", "order_id": "A-1001"}'
phoneis required;namebecomes the contact's name; every other field becomes a variable ({{order_id}}). Numbers keep every digit; lists and objects arrive as compact JSON.- The body is JSON or a form, up to 64 KB, not compressed.
- The flow must be switched on and have a Webhook trigger.
- Each flow takes 60 successful requests a minute. Errors: 403
FORBIDDEN(wrong key), 413PAYLOAD_TOO_LARGE, 415UNSUPPORTED_MEDIA_TYPE, 429TOO_MANY_REQUESTS, 400VALIDATION_ERROR.
7. Show Welkai's flow editor inside the CRM
The business can let your CRM show one number's flows and flow editor in a frame (Solo plan and higher). These routes take the number's embed key, not an API key, and are not in the reference.
- The embed key. Someone with the Numbers settings permission opens Channels, the number's card menu, Embed key, and makes a key. It is shown once and belongs on your server only, never in a web page. Making a new key, or removing it, ends every open embedded editor of that number.
- Allow your site. Someone with the Company settings permission adds your site's origin, such as
https://crm.example.com, under API and webhooks, Website embed, Allowed sites for the flow editor. Other sites see a blocked frame. - Get a short-lived address from your server:
curl -X POST https://your-business.welkai.net/embed/token \
-H "X-Device-Key: <embed key>"
The answer's results.url is the address to show, valid for expires_in seconds. Failed calls are limited to 30 a minute per client address; errors are 401 EMBED_KEY_INVALID and 429 TOO_MANY_REQUESTS.
- Show it:
<iframe src="RESULTS_URL" style="width:100%;height:100%;border:0"></iframe>
Add &theme=light or &theme=dark to fix the theme; by default it follows the viewer's system. The page renews its token in the background for the length of a session (12 hours unless the business's server sets another), then shows "This session has ended" and tells your page:
window.addEventListener("message", (event) => {
if (event.origin !== "https://your-business.welkai.net") return;
if (event.data?.type === "welkai:embed:ready") { /* the editor has loaded */ }
if (event.data?.type === "welkai:embed:expired") { /* get a new token and set the iframe src again */ }
});
Use each token's url as given, and do not save it for later: get a new one each time the page opens. The editor works on the flows that run on exactly this number. It can build, publish, switch on and off and start them, and see their runs. It cannot reach chats, other numbers or the send API.
Errors and limits
| Answer | Meaning | What to do |
|---|---|---|
401 unauthorized | The key is wrong or was revoked | Ask the business for a new key |
401 token.expired | The key passed its end date | Ask the business for a new key |
401 wrong_address | The key belongs to another business | Call that business's own address |
403 token.not_allowed | The key lacks a scope (scope names it), or keys can never do this | Ask for a key with that scope |
403 feature_not_in_plan | The business's plan does not include this API | The business upgrades |
404 DEVICE_NOT_FOUND | The key may not use this number | Check X-Device-Id against GET /devices |
409 DEVICE_NOT_READY | The number is disconnected | The business reconnects it |
409 contact.external_id_taken | Another contact on this number has that id | Look up params.jid |
429 token.rate_limited | Over 600 calls a minute for this key | Wait Retry-After seconds |
Sends also follow each number's own safety limits, which protect it from being banned; a refused send answers in plain words with its code. Show message to people and act on the code.