Open API and webhooks
Connect your member system so agents see member details, use the API to read chats and send messages, and receive webhooks for new messages.
This article is for developers. Everything is in Settings → Open API, in four tabs: Member identity, API keys, Webhook and API docs. The API docs tab has the full parameter list and examples.
Member identity
When a visitor is signed in to your website, you can pass their member details to your agents. Agents see them under Member in the right panel of the agent desk and no longer have to ask for an account number.
1. Send the details from your web page
After the member signs in, run this after the embed code:
<script>
MeaiChat.identify({
user_id: '10086',
name: 'Alex Chen',
email: 'alex@example.com',
level: 'VIP3',
balance: '1280.00'
}, 'signature computed on your server');
</script>Besides user_id, name, email and phone, you can send any fields you like, up to 20. You can also set window.MeaiChatSettings = { user: {...}, user_hash: 'signature' } before the embed code instead.
2. Compute the signature on your server
The signature stops visitors from changing the member ID to someone else's:
signature = HMAC-SHA256(identity secret, user_id), lowercase hexClick Create secret on the Open API page. Each website has its own identity secret. Keep it on your server and never put it in a web page. The page has sample code for Node.js, PHP, Python and Java.
Member details without a signature are still shown, but agents see them marked "Unverified".
API keys
Available on the Pro and Business plans.
Click New key under API keys and choose:
- Read only: can only read data.
- Read & write: can also send messages, end chats and update visitor details.
Send the key in the request header:
Authorization: Bearer mc_your_keyResponses are JSON: { "data": ... } on success, { "error": { "code", "message" } } on failure. Each key can make up to 300 requests per minute.
Endpoints
| Method | Path | Description | Needs |
|---|---|---|---|
| GET | /api/v1/conversations | List chats, filtered by status, website, visitor or time, with paging | Read only |
| GET | /api/v1/conversations/{id} | One chat with visitor details and all messages (internal notes excluded) | Read only |
| POST | /api/v1/conversations/{id}/messages | Send a message to the visitor as an agent | Read & write |
| POST | /api/v1/conversations/{id}/close | End a chat | Read & write |
| GET | /api/v1/visitors/{id} | Visitor details, including member details | Read only |
| PATCH | /api/v1/visitors/{id} | Update a visitor's name, contact, notes, tags or member details | Read & write |
| GET | /api/v1/leaves | Offline messages | Read only |
| GET | /api/v1/agents | Agents and their current status | Read only |
The base address is your console address, for example:
curl https://sunny-store.meaichats.com/api/v1/conversations?status=active \
-H "Authorization: Bearer mc_your_key"Webhooks
Available on the Pro and Business plans.
When there is a new chat, message, offline message or rating, we POST a JSON payload to your server right away. Click Add webhook under Webhook, enter your URL and choose the events.
| Event | Sent when |
|---|---|
conversation.created | A new chat starts (the visitor's first message) |
conversation.closed | A chat ends |
message.created | A new message from the visitor or an agent (internal notes excluded) |
rating.created | A visitor rates a chat |
leave.created | A new offline message |
visitor.identified | A visitor signs in as a member |
ticket.created | A new ticket |
ticket.updated | A ticket changes |
Good to know:
- Headers include
X-MeaiChat-Event(the event name),X-MeaiChat-Delivery(a delivery ID that stays the same on retries, useful for de-duplication) andX-MeaiChat-Signature. - A 2xx response within 8 seconds counts as delivered. Failed deliveries are retried after 30 seconds and again after 5 minutes. A webhook is turned off automatically after 50 failures in a row.
- To verify the signature:
signature = HMAC-SHA256(signing secret, timestamp + "." + raw body), hex. Use the raw request body; do not parse the JSON and convert it back to a string. Also check that the timestamp is within 5 minutes of now.
The API docs tab has sample code for verifying signatures.