Guides
Headless and custom storefronts
The widget gives you the assistant UI. The API gives you search, recommendations and the data behind them. You build your own UI around that.
On this page
Ottla works on any storefront you can add a script tag to, whether that is PWA Studio, a React or Vue front end, or something your agency built from scratch. The shopping assistant arrives ready-made as a widget. Everything else Ottla does is available through the REST API, and you decide how it looks.
That split matters when you plan the work, so this page is honest about it: what you get, what you build, and the order to do it in.
What you get and what you build
| Building block | How you get it |
|---|---|
| The assistant | The widget, with no UI to build. Or your own chat UI on /ask. |
| Search box and results | Your UI on /autocomplete and /product-search |
| Recommendation rows | Your UI on /recommendations |
| Product questions | Your UI on /product-questions |
| Back-in-stock and price-drop alerts | Your form on /product-alerts |
| Handoffs to your team | Handled by the widget, or your UI on /escalation |
| Your catalogue | Your server on the /ingest/* endpoints |
| Orders after Ottla features, in Analytics | /track from the page and /attribution/ingest from your server |
If you’re on Magento, the module draws instant search, product listings, recommendation rows, badges and alert forms in your theme automatically. Those blocks are features of the Magento module. On a headless store, your front end builds them using the API: Ottla supplies the products, sorting and copy, and your front end decides how they look. Allow front-end development time to build each block you want beyond the chat window.
Order of work
-
Add the website
In Storefront → Websites, add your storefront and select its platform as Custom / headless (REST API).
-
Send your catalogue
Create a Server import key and send categories, products with their prices and stock, and content such as your delivery and returns pages. Send your catalogue from any platform walks through it.
-
Create a browser key
Create a Storefront widget key and add your storefront under Allowed origins, plus
http://localhost:3000or similar while you develop. -
Install the widget
Paste the two tags from the widget’s Install button into your page layout. See Install the widget.
-
Give it page and basket context
Tell the widget which product a page is about with
data-skuor a product meta tag, and defineOttlaPageContext,OttlaCartandOttlaCartAddso answers know the basket and Add to basket works. See JavaScript events and consent. -
Report orders
On making an order, post to
/attribution/ingestusing a key known only to your server or servers (that is, a Storefront widget key flagged as Used by a store connector or another server, including your servers’ IP addresses). This will allow the Ottla features shoppers used to be reported against orders under Insights → Analytics. You should pass, for each order line, itsvalueand the variousfeaturesit was added from, if your basket knows them, andprivacywith the shopper’s privacy mode when they placed the order; sendvisitor_idwith the value ofottla_vidonly when that mode iscorn, and leave it out otherwise. The sample shows a shopper who said yes, so it includes the visitor id. In the same way, to link clicks and adds to the order, passvidandlink: truein calls to/trackonly when the shopper’s privacy mode allows it, withprivacyon each event. If you use the Magento module, sendX-Ottla-Privacy(yfor yes;n,rorofor a no) with the shopper’s choice on every cart and checkout request,placeOrderincluded, and, only when that choice allows it, theX-Ottla-Surfaceheader onaddProductsToCart, so the relevant order lines are marked. Each order is counted once, so a retry is safe.curl https://ottla.ai/api/v1/attribution/ingest \ -H "Authorization: Bearer YOUR_SERVER_STOREFRONT_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: order-100004215" \ -d '{ "event_type": "order_placed", "order_id": "100004215", "value": 153.99, "currency": "GBP", "visitor_id": "vid2.20419.0f1e2d3c4b5a69788796a5b4c3d2e1f0", "privacy": {"mode": "c", "rules": "u", "refused": false, "account_link": true, "account_basis": "c", "chat_consent": false, "signal": "y"}, "line_items": [ {"sku": "TENT-2P", "qty": 1, "row_total": 149.00}, {"sku": "PEG-SET", "qty": 1, "row_total": 4.99} ] }'
Your own search box
Search is the block most headless stores build first. Call /autocomplete on each keystroke with mode: "keystroke", and /product-search when the shopper submits or picks a filter. Then report impressions and clicks with /search/events, so the search figures in your console reflect your own UI.
A few things worth knowing before you design the results page:
- Filters go in
attributes, such as{"colour": ["green", "blue"]}. Values of one attribute are OR’d together; different attributes are AND’d. - Facet counts are disjunctive, meaning the other colours still have their counts once a shopper selects green. That’s why you can show “Blue (12)” alongside a ticked “Green”.
- An empty
querywithcategory_external_idsbrowses a category, so the same call can draw your category pages. - Sort with
relevance,recommended,popularity,newest,top_rated,price_asc,price_desc,name_ascorname_desc, among others. - If a response carries
redirect_url, a search rewrite in your console wants the shopper on that page instead.
const API = 'https://ottla.ai/api/v1/';
const headers = {
'Authorization': 'Bearer YOUR_BROWSER_KEY',
'Content-Type': 'application/json',
};
// As the shopper types (debounce this in your own code)
async function suggest(text) {
const res = await fetch(API + 'autocomplete', {
method: 'POST',
headers,
body: JSON.stringify({ query: text, mode: 'keystroke', limit: 6 }),
});
return (await res.json()).suggestions;
}
// When they press Enter, or pick a filter
async function search(text, filters = {}) {
const res = await fetch(API + 'product-search', {
method: 'POST',
headers,
body: JSON.stringify({ query: text, attributes: filters, sort: 'relevance', page: 1, page_size: 24 }),
});
return res.json(); // products, facets, total, total_pages, redirect_url
}
// Tell Ottla what the shopper saw and clicked
function report(events) {
fetch(API + 'search/events', { method: 'POST', headers, body: JSON.stringify({ events }) });
}
report([{ type: 'click', query: 'tent', sku: 'TENT-2P', position: 1 }]);
use GuzzleHttp\Client;
$client = new Client(['base_uri' => 'https://ottla.ai/api/v1/']);
$response = $client->post('product-search', [
'headers' => [
'Authorization' => 'Bearer YOUR_BROWSER_KEY',
'Origin' => 'https://shop.example',
],
'json' => [
'query' => 'tent',
'attributes' => ['colour' => ['green']],
'sort' => 'relevance',
'page' => 1,
'page_size' => 24,
],
]);
$results = json_decode((string) $response->getBody(), true);
// $results['products'], $results['facets'], $results['total'], $results['redirect_url']
The search reference has every field, and the recommendations reference covers product rows.
Product rows and product pages
Recommendation rows come from /recommendations. Pick a strategy for each row: similar (the default), bought_together, coview, bestsellers, trending or recently_viewed. Bought together and best sellers learn from the order history you send to /ingest/orders, so a store that sends no orders gets fewer of them.
An empty list can be a valid answer, for a brand-new product nobody has ordered yet, for example. Opt to hide the row rather than showing an empty box to shoppers. If you run a holdout experiment (Growth and above), visitors in the held-out group receive an empty list deliberately, so the same rule applies.
For a “Questions people ask” block on product pages, /product-questions returns the questions you have approved in Answer Studio for that product.
// A "Frequently bought together" row under the Add to basket button
const res = await fetch('https://ottla.ai/api/v1/recommendations', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_BROWSER_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({ sku: 'TENT-2P', strategy: 'bought_together', limit: 4 }),
});
const { recommendations } = await res.json();
if (recommendations.length === 0) hideRow(); // your own function
Prices for signed-in customers
Direct API calls are answered with guest prices and guest visibility. Fields such as customer_group in a request body are ignored, so a page cannot ask for trade prices on its own. Customer-group prices and catalogues need the Magento module, which is the only thing that can tell Ottla who a signed-in shopper is. Bear that in mind if trade customers on your headless store see their own prices elsewhere on the site.
Calling from your own server
A server that renders pages, or a backend for a mobile app, can call the storefront endpoints with the Storefront widget key. Two headers make that work. Send Origin with your storefront’s address, because the key’s allowed origins are checked whoever calls. And, on a key marked Used by a store connector or another server, send X-Ottla-Client-Ip with the shopper’s public IP address, so each shopper has their own rate allowance.
FAQ
Frequently asked questions
Does Ottla work with PWA Studio?
Yes, through the REST API and the widget. It is not tested with the Magento module.
Do I get the instant search box on a headless store?
No, that is a Magento module feature. Build your own search box on /autocomplete and /product-search; the example above is a starting point.
Do I need a server?
Yes. You need one to send your catalogue and report orders, and that is where the Server import key lives.
Why does a signed-in trade customer see retail prices?
Direct calls are answered with guest prices. Customer-group prices need the Magento module, which can vouch for who the shopper is.
Do you have Shopify, WooCommerce or BigCommerce connectors?
Not yet. You can connect any store, including those, through the REST API and the widget as this page describes.
Next
Send your catalogue from any platform
Products, prices, stock, content, orders and deletes.
Install the widget
Where to find the two tags, and how to test each.
Events API
Track clicks and report orders for Analytics.
Ottla for headless stores
What Ottla does on a headless storefront.