Base URLhttps://ottla.ai/api/v1

API reference

Events and revenue attribution

Send page events from your storefront, and orders from your server.

Updated 17 min read

On this page

Ottla’s widget reports its own events for you. Any other custom front end should report what shoppers do with what Ottla shows them to /track (product views, clicks, adds to basket and the chat opening), and send orders to /attribution/ingest from your server. This lets the console show the orders placed after shoppers used each Ottla feature, and the order lines added to the basket from it.

Amounts are shown separately for each currency and never added across currencies. They show which features shoppers used before an order; they do not imply that a feature was responsible for it. To measure the direct effect of a personalised recommendation row or the basket line, run an experiment (see Growth and above). There is no way to hold the chat back from some shoppers.

On a Magento or Adobe Commerce store, our module does all of this for you, including orders, each line’s value and the feature it was added from. So this page only applies to a headless or other custom storefront.

Analytics in the Ottla console showing assisted and directly recommended revenue Example data
Orders after shoppers used Ottla, from the orders your server reports.

Report a storefront event

POST /api/v1/track Report a storefront event

Reports what a shopper does with what Ottla shows. Scope feedback:write, so your Storefront widget key works. Rate limit group track: 600 a minute per key. Like feedback, events keep flowing while a payment is overdue.

Key
Authorization: Bearer with the feedback:write scope
Origin
One of the key’s allowed origins
Call from
The browser or your server
Rate limit
track group, 600 a minute
Retries
Safe with Idempotency-Key

Headers and parameters

POST /track: headers and parameters
FieldDescription
Origin string (uri) header Required Your storefront’s address, which must be one of the key’s allowed origins. Browsers send it themselves; a server must send it too.
Idempotency-Key string header Optional Makes a retry safe: the same key, path and body within 24 hours returns the first response again. A key is shared by every API key and store in the workspace, so it must be unique to each request (a random id, not a row number from one store’s database): reusing the key with a different body is refused with 409. Servers only.
X-Ottla-Client-Ip string header Optional The shopper’s public IP address, when your server calls on a shopper’s behalf, so each shopper has their own allowance. Read only for a key marked “Used by a store connector or another server” in the console, which also needs allowed IP addresses; ignored for any other key.
X-Ottla-Request-Id string header Optional Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only.

Responses

  • 202 Accepted

    Accepted: the event will be recorded shortly. status is ignored when it came from a member of the store’s team shopping as a customer.

  • 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: forbidden_scope, ip_not_allowed or tenant_suspended as for any key, or the Origin check failed: origin_not_configured, origin_required, origin_invalid or origin_not_allowed.

  • 409 Conflict

    The Idempotency-Key was used before with a different body (idempotency_key_reused), or a request with it is still running (idempotency_in_flight).

  • 422 Invalid

    The request is not valid (validation_failed), or event is not one of the accepted events (unsupported_event).

  • 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). Wait retry_after seconds.

You should send these events from your custom front end:

EventSend it whenWorth adding
product.viewedA product page is viewed.sku, external_id, page_type
product.clickedA shopper clicks a product Ottla showed: in an answer, a row or search.answer_id, position, surface, session_id, vid, link
product.add_to_cartA shopper adds a product Ottla showed to their basket.sku, answer_id, surface, session_id, vid, link
suggestion.clickedA shopper taps a starter question or a follow-up.session_id, surface
widget.openedYour chat opens.session_id, surface
order_placedAn order is placed in a session where the shopper used Ottla.order_id, total, currency, line_skus, session_id

purchase is read as order_placed. The other names Ottla accepts are sent by its own widget, and anything else gets 422 unsupported_event. The first widget.opened also ticks Place the advisor on your store in the console’s getting started checklist.

Request fields
FieldDescription
event string Required The event name, from the table above.
answer_id integer Optional The answer the event relates to, from POST /ask.
session_id string Optional The conversation’s session_id, up to 128 characters.
sku string Optional The product’s SKU.
external_id string Optional Your platform’s product id, up to 64 characters.
external_ids array Optional Several product ids, up to 50.
position integer Optional The product’s position in what was shown, counting from 0, up to 100.
surface string Optional Where on your storefront it happened, up to 100 characters, such as chat or pdp_row.
vid string Optional The shopper’s visitor id: the value of their ottla_vid cookie, up to 128 characters. Send it only with link: true, and only when the shopper’s current privacy mode allows it: after a yes, or on a store outside the UK and the EU until the shopper says no.
link boolean Optional Set to true to let Ottla link this click, add to basket or tap on an Ottla block, row or search to a later order. Without it, vid is ignored.
privacy object Optional The shopper’s current privacy mode, as {mode}: c (consent), k (counts), o (off) or n (notice). Only in consent and notice does Ottla keep a visitor id or account link. In counts it keeps the event alone, with no identifier; in off it keeps nothing.
page_type string Optional The kind of page, up to 32 characters.
order_id string Optional For order_placed: your order number, up to 128 characters.
total number Optional For order_placed: the order total.
currency string Optional The currency, such as GBP.
line_skus array Optional For order_placed: the SKUs ordered, up to 200.
website_id integer Optional Ottla’s id for the website. Ignored for a key bound to one website.
scope_ref string Optional Your code for the market or language, such as uk.
curl https://ottla.ai/api/v1/track \
  -H "Authorization: Bearer YOUR_BROWSER_KEY" \
  -H "Origin: https://shop.example" \
  -H "Content-Type: application/json" \
  -d '{"event": "product.viewed", "sku": "TENT-2P", "external_id": "1187", "page_type": "pdp"}'

An accepted event answers 202 with status: "queued". If it came from a member of the store’s team shopping as a customer, status is ignored and it isn’t counted. Send vid, set to the shopper’s visitor id (the ottla_vid cookie), and link: true with a click, an add or a tap to link it to a later order, only when the shopper’s privacy mode allows it: after a yes, or, on a store outside the UK and the EU, until the shopper says no. Never send them after a no, and delete the cookie then. Send privacy with the shopper’s current privacy mode on every event. Ottla ignores vid without link. You don’t need them on chat events: Ottla links the chat to an order through its session. The console then shows the orders placed within 7 days after a shopper used each feature.

Report an order from your server

POST /api/v1/attribution/ingest Report an order or add to basket

Lets your back end send Ottla an order, or an add to basket, so Ottla can report which of its features shoppers used before the order. Use a key only your server holds: a Storefront widget key (it has ask:read) marked Used by a store connector or another server and limited to your servers’ IP addresses. The key in your web pages is refused with 403 server_key_required, because anyone can read it. There’s no Origin check, because the call comes from your server. Rate limit group attribution: 600 a minute per key.

Key
Authorization: Bearer with the ask:read scope
Call from
Your server only
Rate limit
attribution group, 600 a minute
Retries
Safe with Idempotency-Key

Headers and parameters

POST /attribution/ingest: headers and parameters
FieldDescription
Idempotency-Key string header Optional Makes a retry safe: the same key, path and body within 24 hours returns the first response again. A key is shared by every API key and store in the workspace, so it must be unique to each request (a random id, not a row number from one store’s database): reusing the key with a different body is refused with 409. Servers only.
X-Ottla-Request-Id string header Optional Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only.

Responses

  • 202 Accepted

    Accepted: the event will be recorded shortly.

  • 204 No content

    Revenue measurement is not on the plan, so nothing is recorded.

  • 401 Unauthorised

    No API key was sent (unauthenticated), or the key is unknown, revoked or expired (invalid_api_key).

  • 402 Payment required

    Billing needs attention. plan_limit_exceeded: the plan’s allowance and any credits are used up (the body adds metric, used and limit). account_past_due: a payment is overdue, or a trial ended without a plan. account_suspended: the account is suspended. Stop sending until the workspace owner resolves it at upgrade_url.

  • 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), the workspace is not active (tenant_suspended), or it is a key a web page may hold (server_key_required): orders are accepted only with a key limited to your servers’ IP addresses.

  • 409 Conflict

    The Idempotency-Key was used before with a different body (idempotency_key_reused), or a request with it is still running (idempotency_in_flight).

  • 422 Invalid

    The request is not valid (validation_failed, with errors keyed by field), or the Idempotency-Key header 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). Wait retry_after seconds.

Request fields
FieldDescription
event_type string Required order_placed or add_to_cart.
order_id string Optional Your order number, up to 128 characters. Required for order_placed: each order is counted once.
value number Optional The order or line value, such as 174.00.
currency string Optional The ISO 4217 code, three letters. Default GBP.
line_items array Optional Up to 1,000 lines, each with sku (required), qty and row_total, and optionally value (what the shopper paid for the line, with tax and after line discounts) and features: the Ottla features the line was added to the basket from, each as {surface, at, basis}, with at in ISO 8601 format (UTC) and basis the shopper’s privacy mode when the feature was recorded against that line (c for consent or n for notice). Send features, an empty list for none, only when you record them and the shopper’s privacy mode allowed marks for the whole basket; otherwise leave it out, and Ottla shows “added from” as not measured.
session_id string Optional The chat’s session_id, when the shopper used the assistant.
visitor_id string Optional The shopper’s visitor id (the value of their ottla_vid cookie), only when the shopper’s privacy mode allows it. Never send it after a no.
privacy object Optional The shopper’s privacy at the time of the order, as {mode, rules, refused, account_link, account_basis, chat_consent, signal}. mode is c (consent), k (counts), o (off) or n (notice); refused is true if the shopper said no; account_link says whether a signed-in customer’s chats can be linked to the order through their customer account. If the mode is anything other than c or n, Ottla ignores visitor_id and the chat session ids; it ignores customer_ref unless account_link is true, and every line’s features if refused is true.
occurred_at string Optional When it happened, in ISO 8601. Defaults to now.
website_id integer Optional Ottla’s id for the website. Ignored for a key bound to one website.

Example: sending an order from your order confirmation job

// Run this from the job or webhook that handles a new order (Node 18 or later).
// Generate the key once per order report, and pass the same key when your job retries.
import { randomUUID } from 'node:crypto';

export async function reportOrder(order, idempotencyKey = randomUUID()) {
  const res = await fetch('https://ottla.ai/api/v1/attribution/ingest', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_SERVER_STOREFRONT_KEY',
      'Content-Type': 'application/json',
      'Idempotency-Key': idempotencyKey,
    },
    body: JSON.stringify({
      event_type: 'order_placed',
      order_id: order.number,
      value: order.grandTotal,
      currency: order.currency,
      // value: what the shopper paid for the line, with tax and after line discounts.
      // features: the Ottla features the line was added from, if your basket records them.
      line_items: order.lines.map((l) => ({ sku: l.sku, qty: l.qty, row_total: l.rowTotal, value: l.paid, features: l.ottlaFeatures })),
      session_id: order.ottlaSessionId ?? undefined,
      // Only when the shopper's privacy mode allows it (c consent or n notice), never after a no.
      visitor_id: ['c', 'n'].includes(order.privacyMode) ? order.ottlaVid : undefined,
      privacy: { mode: order.privacyMode, refused: order.privacyRefused },
      occurred_at: order.placedAt,
    }),
  });
  if (res.status === 204) return; // revenue measurement is not on this workspace's plan
  if (!res.ok) throw new Error(`Ottla answered ${res.status}`);
}

An accepted order answers 202 with status: "queued", an ack_id and a request_id. You get 204 with an empty body when revenue measurement isn’t on the workspace’s plan. Send the same order twice and it’s still counted once, so retrying is always safe.

Which figures each feeds

Events and console figures
You send It feeds
/track clicks, adds, suggestion taps and chat opens Engagement with each feature in Insights → Analytics, including chats started, recommendation clicks and adds to basket, and how shoppers used each feature. With vid and link, also which features shoppers used prior to an order.
/track order_placed Holdout experiments.
/attribution/ingest Orders following use of each Ottla feature, plus AI chat details, in Insights → Analytics.
/search/events The search funnel and zero-result searches in Insights → Sales and search.
A click in the chat leading to an order

Errors

StatusCodeWhat to do
401unauthenticated, invalid_api_keySend a valid key.
402account_past_due, account_suspendedOnly on /attribution/ingest. Keep the orders and resend them once billing is resolved.
403forbidden_scope, server_key_required, the origin_* codes/track needs feedback:write and an allowed Origin; /attribution/ingest needs ask:read on a key limited to your servers’ IP addresses.
409idempotency_key_reused, idempotency_in_flightSee Idempotency.
422validation_failed, unsupported_eventFix the fields in errors, or use an event name from the table above.
429rate_limited and the other limit codesWait retry_after seconds. One call per event or order sits comfortably inside these limits.

FAQ

Questions developers ask

Which key sends orders from my server?

A Storefront widget key that only your server holds. Create one under Storefront → API keys, turn on Used by a store connector or another server and list your servers’ IP addresses. It has ask:read, which /attribution/ingest needs, and this endpoint doesn’t check Origin. The key in your web pages is refused, because anyone can read it.

Will an order be counted twice if I resend it?

No. Orders are only counted once no matter how many times you send them. So you can safely resend if you receive a timeout.

Why did I get a 204?

Revenue measurement isn’t on your workspace’s plan, so nothing has been recorded.

Does this prove the assistant caused the sale?

No, and we don’t claim it does. These figures show which features shoppers used before an order. We can’t run a holdout for the chat, but experiments (Growth and above) let you measure the effect of a personalised recommendation row on its own.

Try Ottla on your own store

Start a 14-day free trial with no card needed. The trial has every Pro feature, with lower limits, so you can install the module or the widget, connect your catalogue and try the assistant on your own products.

14 days free. No card needed.