Widget embed & API
Embed the website chat widget with one script tag, or build your own chat interface on the widget's public endpoints.
Embed the widget
The simplest integration is the script tag from Widget Settings:
<script src="https://YOUR_WORKSPACE_DOMAIN/widget/chatbot.js" data-key="YOUR_WIDGET_KEY" defer></script>
| Attribute | Description |
|---|---|
src | The widget script on your workspace domain. The snippet in Widget Settings adds a version parameter so browsers pick up updates. |
data-key | Your widget key. Required. |
Put it just before </body>. The widget renders in its own shadow root, so your site’s styles don’t affect it and it doesn’t affect your page. See Website chat widget for the settings.
Build your own chat interface
To design the chat yourself, call the same public endpoints the widget uses. They don’t need an API token — the widget key identifies your widget — and they enforce your widget’s Allowed Domains, based on the request’s Origin or Referer header.
- Base URL:
https://YOUR_WORKSPACE_DOMAIN/api/widget - Limit: 30 requests per minute per IP address
Get the widget’s settings
/api/widget/config?key=YOUR_WIDGET_KEY{
"bot_name": "Assistant",
"welcome_message": "Hi! How can I help you today?",
"theme_color": "#2f7cf6",
"enabled": true
}
Start or resume a session
/api/widget/session| Field | Required | Description |
|---|---|---|
widget_key | Yes | Your widget key |
name | Yes | The visitor’s name, up to 100 characters |
email | Yes | The visitor’s email address |
session_id | No | A previous session_id, to resume that conversation |
lead_token | No | The lead_token from an earlier session. It proves this is the same visitor and restores their history. |
{
"session_id": "4a7c2e…",
"lead_token": "9f1b6d…",
"name": "Sara",
"welcome_message": "Hi! How can I help you today?",
"messages": []
}
When a conversation is resumed, messages holds the earlier messages — each with a role of visitor or bot — and welcome_message is null. Keep session_id and lead_token in the visitor’s browser and send them back next time. The visitor is recorded as a lead at this step.
Send a message
/api/widget/chat| Field | Required | Description |
|---|---|---|
widget_key | Yes | Your widget key |
session_id | Yes | From the session call |
message | Yes | The visitor’s message, up to 2,000 characters |
{
"reply": "We deliver every day between 9 am and 9 pm.",
"session_id": "4a7c2e…"
}
Errors
Errors return { "error": "…" } with one of these status codes:
| Status | When |
|---|---|
| 400 | The widget key is missing from a config request |
| 401 | The session has expired ("code": "session_required"). Start a new session, then send the message again. |
| 403 | The widget is switched off, or the page’s domain isn’t in Allowed Domains |
| 404 | The widget key isn’t valid |
| 422 | A field is missing or invalid |
| 429 | Too many requests, the daily message cap was reached, or the monthly conversation limit was reached |
| 503 | The assistant couldn’t reply — try again shortly |
Our team is happy to walk you through Wazline and help you set up your workspace.