← Documentation

CRM integration guide

How to send email and WhatsApp from your own system through IkoniaCX, so every message is delivered and recorded against the customer — and how to read back the full history of communication with them.

What this gives you

Your CRM already knows who your customers are. What it usually cannot do is send a message and keep an accurate record of every reply that follows, across email and WhatsApp, in one thread.

When you send through IkoniaCX rather than directly through Gmail or the WhatsApp API, three things happen that would not otherwise:

Setting up

1. Create a key

In IkoniaCX, open Settings → API keys and create one. For a CRM integration you need:

messages:sendSend email and WhatsApp
messages:readRead the messages in a conversation
conversations:readList conversations and find a customer's history
contacts:readLook customers up
contacts:writeCreate or update a customer record

Add tickets:write only if your CRM should raise tickets. Leave everything else off — a key can only do what it was granted. Google Business reviews are not part of the API; they are handled in IkoniaCX itself.

2. Decide what you will test against

Marking a key test tags it so you can tell your keys apart in logs and revoke one without touching the other. It does not create a sandbox.

A test key sending through a connected channel delivers a real message to a real customer. What suppresses delivery is the channel, not the key: a channel marked as demo records the message in the conversation and never sends it. The test_mode field in a send response reports that channel flag — not the environment of your key.

So to build safely, point your integration at a demo channel, or send only to addresses and numbers you own. The failure modes worth rehearsing — timeouts, duplicate sends — are the ones you least want to discover against real customers.

3. Store the key as a secret

Server-side only, in an environment variable. A key in browser or mobile code is public. Never commit one.

export IKONIACX_KEY="ikx_test_…"

Sending a message

One endpoint covers both channels. It finds or creates the contact, opens a conversation if there is not one already, delivers, and records the message.

Email

curl -X POST https://cx.ikonia.co.za/api/v1/messages \
  -H "Authorization: Bearer $IKONIACX_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "email",
    "to": "jane@example.com",
    "subject": "Your order #4471 has shipped",
    "content": "Hi Jane,\n\nYour order is on its way.\n\nThe team"
  }'

WhatsApp

curl -X POST https://cx.ikonia.co.za/api/v1/messages \
  -H "Authorization: Bearer $IKONIACX_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "channel": "whatsapp",
    "to": "+27821234567",
    "content": "Hi Jane, your order is on its way."
  }'

Response

{
  "id": "…",                  // the message
  "conversation_id": "…",     // the thread — keep this
  "contact_id": "…",          // the customer — keep this too
  "channel": "email",
  "delivered": true,
  "test_mode": false
}

Store contact_id against your CRM record the first time you message someone. You can always send by address instead, but holding the id saves a lookup and makes the history endpoints direct.

If you already have the contact id

-d '{ "channel": "email", "contact_id": "…", "subject": "…", "content": "…" }'

Retrying safely

Every send requires an Idempotency-Key header. This is the single most important part of the integration, so it is worth being precise about.

When a request times out you cannot tell whether it arrived. Retrying naively sends the message twice. Instead, generate one key per message you intend to send, and reuse it on every retry of that message:

# correct — the key belongs to the message, not the attempt
key=$(uuidgen)
for attempt in 1 2 3; do
  code=$(curl -s -o /tmp/out -w '%{http_code}' -X POST https://cx.ikonia.co.za/api/v1/messages \
    -H "Authorization: Bearer $IKONIACX_KEY" \
    -H "Idempotency-Key: $key" \
    -H "Content-Type: application/json" \
    -d "$payload")
  [ "$code" = "200" ] && break
  sleep $((attempt * 2))
done

Generating a fresh key per attempt defeats the mechanism entirely and your customer receives duplicates. The key must be stable across retries of the same message.

A retry that arrives after the original succeeded returns the original result with "duplicate": true and sends nothing. A retry after a genuine failure is allowed through, because the provider may never have been reached.

Reading everything said to a customer

Two calls: list their conversations, then read each thread. This covers every channel — email, WhatsApp, Facebook, Instagram — not only what your CRM sent.

# 1. every conversation with this customer, most recent first
curl "https://cx.ikonia.co.za/api/v1/contacts/{contact_id}/conversations" \
  -H "Authorization: Bearer $IKONIACX_KEY"

# 2. the transcript of one, oldest message first
curl "https://cx.ikonia.co.za/api/v1/conversations/{conversation_id}/messages" \
  -H "Authorization: Bearer $IKONIACX_KEY"

Each message tells you who said it:

{
  "data": [
    { "sender_type": "contact", "content": "Where is my order?",      "created_at": "…" },
    { "sender_type": "ai",      "content": "It shipped on Tuesday…",  "created_at": "…" },
    { "sender_type": "agent",   "content": "Tracking attached.",      "created_at": "…" }
  ],
  "has_more": false,
  "next_cursor": null
}
contactThe customer
agentA person on your team, or your CRM via this API
aiAn automated reply generated by IkoniaCX
systemA platform note, not something anyone said

Finding a customer you only know by email

curl "https://cx.ikonia.co.za/api/v1/contacts?search=jane@example.com" \
  -H "Authorization: Bearer $IKONIACX_KEY"

Getting replies back into your CRM

Register a webhook and replies arrive within about a minute of the customer sending them. Add the webhooks:manage scope to your key, then:

# every conversation, most recently active first — stop when you
# reach one you have already seen
curl "https://cx.ikonia.co.za/api/v1/conversations?limit=50" \
  -H "Authorization: Bearer $IKONIACX_KEY"

Every five minutes is comfortably inside the rate limit and fast enough for most CRM workflows. Track the newest last_message_at you have processed and stop paging once you pass it.

Respond 2xx within 10 seconds and process afterwards. Slow processing is recorded as a failure and retried, so it becomes duplicate deliveries rather than merely late ones. Deduplicate on the X-IkoniaCX-Delivery header.

Paging through results

Lists return data, has_more and next_cursor. Pass the cursor back unchanged until has_more is false. Do not build or parse a cursor — it is opaque and its format will change.

cursor=""
while :; do
  page=$(curl -s "https://cx.ikonia.co.za/api/v1/contacts?limit=100&cursor=$cursor" \
    -H "Authorization: Bearer $IKONIACX_KEY")
  echo "$page" | jq -r '.data[].id'
  [ "$(echo "$page" | jq -r .has_more)" = "true" ] || break
  cursor=$(echo "$page" | jq -r .next_cursor)
done

Handling failures

400idempotency_key_requiredAdd the header. Every send needs one.
401invalid_api_keyWrong, revoked or expired key. Do not retry.
403insufficient_scopeThe key lacks a scope. Add it in Settings.
404not_foundNo such record in your organisation.
409channel_unavailableThe channel needs reconnecting. Alert someone; retrying will not help.
409send_in_progressThe same key is mid-send. Wait, then check before resending.
422contact_unreachableNo address on that channel — e.g. no phone number for WhatsApp.
429rate_limitedHonour Retry-After.
502provider_errorGmail or Meta rejected it. Safe to retry with the SAME key.
502recorded_partiallyDELIVERED but not recorded. Do NOT retry — it would send twice.
503idempotency_unavailableWe could not guarantee safety, so nothing was sent. Retry.

recorded_partially is the one to handle explicitly. The customer received the message; only our record of it failed. Retrying sends a second copy. Log it and move on — the record can be reconciled, a duplicate cannot be unsent.

Rate limits

600 reads, 120 writes and 60 sends per minute. Every response carries X-RateLimit-Remaining; a 429 carries Retry-After in seconds. Sends are counted separately because they cost money and reach real people.

Before you go live