API reference
Conversations
Retrieve a full conversation from a session. View a shopper’s previous chats on this device.
On this page
Shoppers want to know that their chat persists after reloading a page. They may even come back the next day wanting to see that conversation about walking boots. Our chat history API allows you to build your own chat UI that can reload a conversation from a session, list previous chats from a visitor and delete a chat. Every chat is linked to a visitor id. Ottla sets the visitor id only when the shopper’s privacy mode allows it: after a yes, or, on stores outside the UK and the EU, until the shopper says no.
Read a conversation
The whole conversation for a session_id, oldest first: the shopper’s questions, the assistant’s answers and any messages with your team. Use it to restore a chat after a page load, or poll with since for new messages. Send the fields as query parameters.
- Key
Authorization: Bearerwith theask:readscope- Call from
- The browser or your server
- Rate limit
conversation_readgroup, set by your plan
Headers and parameters
| Field | Description |
|---|---|
session_id
|
|
since
|
Return only messages after this cursor. |
X-Ottla-Request-Id
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
200 OK
The conversation (empty when there is none).
-
401 Unauthorised
No API key was sent (
unauthenticated), or the key is unknown, revoked or expired (invalid_api_key). -
403 Forbidden
The key cannot be used for this request: it lacks the scope (
forbidden_scope), it is limited to other IP addresses (ip_not_allowed), or the workspace is not active (tenant_suspended). -
422 Invalid
The request is not valid (
validation_failed, witherrorskeyed by field), or theIdempotency-Keyheader is malformed (invalid_idempotency_key). -
429 Rate limited
A rate limit was reached: this key’s limit for the operation’s group (
rate_limited), the workspace’s limit across all its keys (tenant_rate_limited), the limit for one network address (ip_rate_limited) or for one shopper (shopper_rate_limited). Waitretry_afterseconds.
The same, with the fields in a JSON body. Use whichever suits your client.
- Key
Authorization: Bearerwith theask:readscope- Call from
- The browser or your server
- Rate limit
conversation_readgroup, set by your plan
| Field | Description |
|---|---|
session_id
|
The conversation’s session_id, up to 128 characters. |
since
|
The cursor from an earlier response, to fetch only newer messages. 0 or absent returns the whole conversation. |
| Field | What it holds |
|---|---|
messages | Oldest first. Each has sort_key, created_at, role and payload. |
role | Who wrote it: shopper, the assistant (ai), a person from the store’s team (agent) or system. |
payload | A shopper question has body. An answer has answer_id and blocks, which you render as you would an answer from /ask. A message in a handoff conversation has the same fields as /escalation/messages returns. |
cursor | Send it as since next time to fetch only newer messages. |
Chats created by a signed-in customer via our Magento module are only returned to that customer, meaning you receive an empty array when making a direct call. This is deliberate, to prevent anyone reading a signed-in shopper’s chat by guessing a session id.
List a visitor’s chats
The chats held under one visitor id, most recent first, with titles only. Fetch a whole chat with /conversation. Without a visitor id the list is empty.
- Key
Authorization: Bearerwith theask:readscope- Call from
- The browser or your server
- Rate limit
conversation_readgroup, set by your plan
Headers and parameters
| Field | Description |
|---|---|
X-Ottla-Request-Id
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
200 OK
The visitor’s chats.
-
401 Unauthorised
No API key was sent (
unauthenticated), or the key is unknown, revoked or expired (invalid_api_key). -
403 Forbidden
The key cannot be used for this request: it lacks the scope (
forbidden_scope), it is limited to other IP addresses (ip_not_allowed), or the workspace is not active (tenant_suspended). -
422 Invalid
The request is not valid (
validation_failed, witherrorskeyed by field), or theIdempotency-Keyheader is malformed (invalid_idempotency_key). -
429 Rate limited
A rate limit was reached: this key’s limit for the operation’s group (
rate_limited), the workspace’s limit across all its keys (tenant_rate_limited), the limit for one network address (ip_rate_limited) or for one shopper (shopper_rate_limited). Waitretry_afterseconds.
| Field | Description |
|---|---|
ottla_vid
|
The visitor id the chats were held under: the vid you send with /ask. Up to 128 characters. |
website_id
|
Ottla’s id for the website. Ignored for a key bound to one website. |
The response holds conversations, each with session_id, title (usually the first question), last_activity_at and message_count.
Remove a chat
Removes one of a visitor’s chats from their list. Send the visitor id it was held under; without it nothing is removed. The answer is always 204, whether or not the chat existed, so the response never reveals which chats there are.
- Key
Authorization: Bearerwith theask:readscope- Call from
- The browser or your server
- Rate limit
conversation_readgroup, set by your plan
Headers and parameters
| Field | Description |
|---|---|
X-Ottla-Request-Id
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
204 No content
Done.
-
401 Unauthorised
No API key was sent (
unauthenticated), or the key is unknown, revoked or expired (invalid_api_key). -
403 Forbidden
The key cannot be used for this request: it lacks the scope (
forbidden_scope), it is limited to other IP addresses (ip_not_allowed), or the workspace is not active (tenant_suspended). -
422 Invalid
The request is not valid (
validation_failed, witherrorskeyed by field), or theIdempotency-Keyheader is malformed (invalid_idempotency_key). -
429 Rate limited
A rate limit was reached: this key’s limit for the operation’s group (
rate_limited), the workspace’s limit across all its keys (tenant_rate_limited), the limit for one network address (ip_rate_limited) or for one shopper (shopper_rate_limited). Waitretry_afterseconds.
| Field | Description |
|---|---|
session_id
|
The chat to remove, up to 128 characters. |
ottla_vid
|
The visitor id the chat was held under. Without it, nothing is removed. |
Example: restore, list and remove
curl "https://ottla.ai/api/v1/conversation?session_id=sess_8f2c1&since=0" \
-H "Authorization: Bearer YOUR_BROWSER_KEY"
<?php
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'https://ottla.ai/api/v1/']);
$response = $client->post('conversations', [
'headers' => ['Authorization' => 'Bearer YOUR_BROWSER_KEY'],
'json' => ['ottla_vid' => $visitorId],
]);
$chats = json_decode((string) $response->getBody(), true)['conversations'];
// Remove one; the answer is always 204
$client->post('conversations/delete', [
'headers' => ['Authorization' => 'Bearer YOUR_BROWSER_KEY'],
'json' => ['session_id' => $chats[0]['session_id'], 'ottla_vid' => $visitorId],
]);
Errors
| Status | Code | What to do |
|---|---|---|
| 401 | unauthenticated, invalid_api_key | Ensure you are sending a valid key. |
| 403 | forbidden_scope, ip_not_allowed | Your key needs the ask:read scope, or it is restricted to other IP addresses. |
| 422 | validation_failed | Please send a session_id that is 128 characters or less. |
| 429 | rate_limited and the other rate limit codes | Please wait retry_after seconds. Try polling at a lower rate if there is no activity in the chat. |
FAQ
Questions developers ask
Why does delete always return 204?
This means you never know if a chat exists or not. If someone were to guess session ids, they would learn nothing.
How long are conversations kept?
There’s no set period. The chat history these endpoints return is kept until that shopper’s data is erased or your workspace is deleted, and removing a chat with /conversations/delete only hides it from the visitor’s list. To erase a shopper’s data, use the shopper erasure endpoint. Retention periods for everything else are on the data and privacy page.
Do I need consent for chat history?
Yes, on UK and EU stores. Previous chats are listed by visitor id, and Ottla sets the visitor id only when the shopper’s privacy mode allows it: after a yes, or on stores outside the UK and the EU until the shopper says no. Without it, the current chat still works during that session but does not appear in the list later.
Related
Ask
Start a conversation and render its answers.
Escalations
Poll messages from your team while in a live chat.
JavaScript events and consent
Learn more about how we use visitor ids and consent in our widget.
Data and privacy
Learn what data we store about your shoppers, and for how long.