API use cases
Practical recipes for embedding chat, identifying users, and routing conversations with the Zora APIs.
These patterns combine the JavaScript and Web APIs. Adapt hostnames and tokens from your cloud dashboard.
Register a custom user and log them in
When your app already knows the customer:
- On the server,
add-user(or update) via the Web API with email and profile fields. - On the page, open the widget and pass login/identity parameters your embed supports, or set a login verification URL that trusts your session.
- Call
SBChat.open()so the visitor lands in an authenticated thread.
Show chat only on specific pages
Load the embed globally but open it only where needed:
if (window.location.pathname.startsWith("/support")) {
SBChat.open();
}
Or omit the embed script on marketing pages and include it only on product/app routes.
Open chat from a button
<button type="button" id="open-zora">Message support</button>
<script>
document.getElementById("open-zora").addEventListener("click", () => {
SBChat.open();
});
</script>
Toggle visibility with showDashboard / hideDashboard or your own CSS around the launcher if you want a fully custom trigger.
Create a conversation with a department
SBChat.newConversation(0, null, null, null, departmentId);
SBChat.open();
Exact argument order follows your runtime’s newConversation signature—check the method in the admin’s API panel if your build differs. You can also force department via URL parameters documented in cloud setup.
Assign a conversation to an agent
Pass the agent ID when creating or updating the conversation (JS newConversation / Web update-conversation-agent). Useful for VIP routing from your CRM.
Force a conversation, department, or agent
Use URL parameters or JS setters before the first message so the visitor skips picker UI. Common cases:
- Deep-link from an email (“Continue this conversation”)
- Product page that always hits Billing
- Account manager dedicated agent for enterprise accounts
Send a message and open chat
SBChat.open();
SBChat.sendMessage("Hi! I need help with my order.");
Combine with a pre-built template for “Report a bug” or “Request a refund” buttons.
Pop-up on scroll
let prompted = false;
window.addEventListener("scroll", () => {
if (prompted) return;
if (window.scrollY > 1200) {
prompted = true;
SBChat.open();
}
});
Prefer this for docs or pricing pages—avoid interrupting checkout flows.
Server-driven outreach
From your backend, use the Web API to new-conversation + send-message when an order fails or an SLA breaches. Agents see the thread in the same inbox as widget chats.
Next steps
- Cloud setup — embed basics
- Web API — method catalog
- JavaScript API — widget methods