API reference
Search
Search and list your products with filters. Search as you type and search your content. Measure your searches with events.
On this page
Use these four endpoints to give your headless or custom storefront the same search Ottla runs on a Magento store. Our ecommerce product search API gives you filters with accurate counts, good sorting, spelling help, part number search and redirects for terms like “returns”. The merchandising your team configures in the console is applied to these results, such as pinned and boosted products, campaigns, synonyms, search rewrites and redirects. These endpoints do not use any of your answered questions.
| Endpoint | Description |
|---|---|
POST /product-search | Use to show search results pages and category listings, with filters, sort and pagination. |
POST /autocomplete | Use to show suggestions under your search box as the shopper types. |
POST /search | Use to search your pages, FAQs, policies and documents, for example in a help centre. |
POST /search/events | Use to send search events, for search analytics in the console. |
Search and list products
Search results and category listings for your own storefront. Send query for a search, or category_external_ids with an empty query for a category page. Prices are guest prices. The first page of each new search is recorded for your search analytics. Rate limit group product_search: 600 requests a minute per key on every plan.
- Key
Authorization: Bearerwith theask:readscope- Origin
- One of the key’s allowed origins
- Call from
- The browser or your server
- Rate limit
product_searchgroup, 600 a minute
Headers and parameters
| Field | Description |
|---|---|
Origin
|
Your storefront’s address, which must be one of the key’s allowed origins. Browsers send it themselves; a server must send it too. |
X-Ottla-Client-Ip
|
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
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
200 OK
One page of products with filter counts.
-
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 addsmetric,usedandlimit).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 atupgrade_url. -
403 Forbidden
The key cannot be used for this request:
forbidden_scope,ip_not_allowedortenant_suspendedas for any key, or theOrigincheck failed:origin_not_configured,origin_required,origin_invalidororigin_not_allowed. -
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. -
503 Unavailable
This capability is temporarily paused by Ottla (
feature_disabled). Try again afterRetry-Afterseconds;help_urlshows the service status.
Request fields
| Field | Description |
|---|---|
query
|
What the shopper typed, up to 500 characters. Leave it empty to browse a category. |
category_external_ids
|
The category being browsed, by your category id, up to 50. Lists that category and its subcategories unless include_descendants is false. |
attributes
|
Selected filters: an attribute code mapped to a list of values, up to 30 attributes. Values of one attribute are alternatives; different attributes must all match. |
facet_attributes
|
The attribute codes to return filter counts for, up to 100. |
price_min
|
The lowest price to include, in the shopper’s currency. |
price_max
|
The highest price to include. |
in_stock
|
true to list only products in stock. |
identifier
|
A part number, barcode or SKU to find exactly, up to 64 characters. |
sort
|
relevance (the default), recommended, popularity, newest, saving, top_rated, most_viewed, price_asc, price_desc, name_asc or name_desc. relevance and recommended follow your merchandising. |
out_of_stock_last
|
Put out of stock products after the rest, whatever the sort. |
include_descendants
|
Whether a category page lists its subcategories’ products. Default true. |
include
|
Extras for each product. badges adds social proof badges when your website shows them. Unknown values are ignored. |
| Field | Description |
|---|---|
page
|
The page to return, from 1. Default 1. |
page_size
|
Products a page, 1 to 100. Default 24. |
website_id
|
Ottla’s id for the website. Ignored for a key bound to one website, as every storefront key is. |
scope_ref
|
Your code for the market or language the shopper is browsing, such as uk. Leave it out for the website’s default. |
locale
|
The shopper’s language, such as en-GB. |
currency
|
The currency to show prices in, such as GBP. |
store_view_id
|
The store view, for a catalogue organised by store view. |
Example: a filtered category listing
The Tents category, filtered to only show two person tents and sorted by lowest price, with filter counts for colour and berths.
curl https://ottla.ai/api/v1/product-search \
-H "Authorization: Bearer YOUR_BROWSER_KEY" \
-H "Origin: https://shop.example" \
-H "Content-Type: application/json" \
-d '{"query": "", "category_external_ids": ["41"], "attributes": {"berths": ["2"]}, "facet_attributes": ["colour", "berths"], "sort": "price_asc", "page_size": 24}'
<?php
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' => '',
'category_external_ids' => ['41'],
'attributes' => ['berths' => ['2']],
'facet_attributes' => ['colour', 'berths'],
'sort' => 'price_asc',
'page_size' => 24,
],
]);
$listing = json_decode((string) $response->getBody(), true);
Response
{
"products": [
{
"external_id": "1187",
"sku": "TENT-2P",
"title": "Ridgeline 2 Person Tent",
"url": "https://shop.example/ridgeline-2-person-tent",
"image_url": "https://shop.example/media/tent-2p.jpg",
"snippet": "Lightweight two person tent with taped seams.",
"card_v": 1,
"type": "simple",
"requires_options": false,
"pricing": {
"amount": 129.0,
"regular_amount": null,
"currency": "GBP",
"tax": "incl",
"formatted": "£129.00",
"regular_formatted": null,
"label": null,
"hidden": false
},
"availability": "in_stock",
"availability_label": "In stock",
"lifecycle": "active"
}
],
"facets": {
"attributes": [
{ "attribute": "colour", "values": [ { "value": "Green", "count": 4, "selected": false }, { "value": "Grey", "count": 2, "selected": false } ] },
{ "attribute": "berths", "values": [ { "value": "1", "count": 3, "selected": false }, { "value": "2", "count": 6, "selected": true } ] }
],
"category": [ { "external_id": "41", "name": "Tents", "url": "https://shop.example/tents", "count": 6, "selected": true } ],
"price": { "min": 49.0, "max": 349.0, "selected_min": null, "selected_max": null },
"stock": { "in_stock": 5, "selected": false }
},
"total": 6,
"page": 1,
"page_size": 24,
"total_pages": 1,
"sort": "price_asc"
}
| Field | What it holds |
|---|---|
products | This page of products. Show the price from pricing.formatted and stock from availability. When pricing.hidden is true, every amount is null and you show no price. |
facets.attributes | Filter counts for each attribute you named in facet_attributes, with selected marking the shopper’s choices. |
facets.category | Categories in the results, with counts. |
facets.price | The lowest and highest price in the results, and the selected range. |
facets.stock | How many results are in stock. |
total, page, page_size, total_pages | Paging. sort repeats the order used. |
redirect_url | When the search term is set up to go to a page (“delivery” to your delivery page, say), its address. Send the shopper there. Results are still returned. |
rewrite | The query after your search rewrites, when one applied. |
campaign | Present when the term is a running campaign’s landing term: id, slug, name and ends_at. |
strategy, latency_ms | Diagnostic values that may change. Don’t build logic on them. |
Facet counts are disjunctive, meaning the count for colour ignores any colour that has already been selected. This allows the shopper to select another colour and know exactly how many products it will add. Counts for all other attributes respect every selection. This is what you expect from a good filter, and it means you don’t have to make a second request per facet.
When nothing matches
A search with total of 0 is a chance, not a dead end. Call /autocomplete with mode: "submit" for spelling suggestions in did_you_mean and popular searches, and if ai.ask_cta.available is true, offer to ask the assistant, which can often help with a question the catalogue words differently. Searches that find nothing are counted in your search analytics where the shopper’s privacy choice allows it, so your team can add synonyms or redirects for them.
Suggest as the shopper types
Suggestions for a search box: matching products and, when your website uses them, categories, pages, articles, FAQs and policies, popular searches and spelling suggestions. Rate limit group autocomplete: 1,200 requests a minute per key.
- Key
Authorization: Bearerwith thesearch:readscope- Origin
- One of the key’s allowed origins
- Call from
- The browser or your server
- Rate limit
autocompletegroup, 1,200 a minute
Headers and parameters
| Field | Description |
|---|---|
Origin
|
Your storefront’s address, which must be one of the key’s allowed origins. Browsers send it themselves; a server must send it too. |
X-Ottla-Client-Ip
|
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
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
200 OK
Suggestions by section.
-
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 addsmetric,usedandlimit).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 atupgrade_url. -
403 Forbidden
The key cannot be used for this request:
forbidden_scope,ip_not_allowedortenant_suspendedas for any key, or theOrigincheck failed:origin_not_configured,origin_required,origin_invalidororigin_not_allowed. -
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. -
503 Unavailable
This capability is temporarily paused by Ottla (
feature_disabled). Try again afterRetry-Afterseconds;help_urlshows the service status.
| Field | Description |
|---|---|
query
|
What the shopper has typed so far, up to 120 characters. Required, except when you ask for popular searches alone. |
limit
|
Suggestions per section, 1 to 20. Default 6. |
mode
|
keystroke while the shopper types (the default), or submit when they press Enter. |
sections
|
The sections to return: products, categories, pages, articles, answers, popular, ask_cta and did_you_mean. Leave it out for all of them. |
include
|
badges adds social proof badges to product suggestions. |
website_id
|
Ottla’s id for the website. Ignored for a key bound to one website, as every storefront key is. |
scope_ref
|
Your code for the market or language the shopper is browsing, such as uk. Leave it out for the website’s default. |
locale
|
The shopper’s language, such as en-GB. |
currency
|
The currency to show prices in, such as GBP. |
store_view_id
|
The store view, for a catalogue organised by store view. |
| Field | What it holds |
|---|---|
suggestions | Matching products: title, url, score, sku, external_id, pricing and availability, best match first. |
categories, pages, articles | Matching categories, content pages and articles, each with title and url. |
answers | Matching FAQs and policies. |
popular | Popular searches on your store: query and searches. |
did_you_mean | Spelling suggestions when the query looks misspelt. |
ai | ask_cta, an offer to ask the assistant about the query, with available, query and label. |
meta | The mode, the sections that ran, and corrected_query when the suggestions are for a corrected spelling. |
redirect_url | When the term is set up to go to a page, its address. |
If your website does not use these sections, they are not returned. So make sure you check for the key before trying to display it.
curl https://ottla.ai/api/v1/autocomplete \
-H "Authorization: Bearer YOUR_BROWSER_KEY" \
-H "Origin: https://shop.example" \
-H "Content-Type: application/json" \
-d '{"query": "gre", "mode": "keystroke", "limit": 6}'
<?php
// $client as in the product search example above
$response = $client->post('autocomplete', [
'headers' => [
'Authorization' => 'Bearer YOUR_BROWSER_KEY',
'Origin' => 'https://shop.example',
],
'json' => ['query' => 'gre', 'mode' => 'keystroke', 'limit' => 6],
]);
$suggestions = json_decode((string) $response->getBody(), true);
Search your content
Finds the passages of your catalogue and content (products, pages, FAQs, policies and documents) that best match a query, best match first. Use it for a help centre search box, or to check what Ottla holds on a topic. For a product listing with filters, use /product-search. Shares the ask rate limit group.
- Key
Authorization: Bearerwith theask:readscope- Origin
- One of the key’s allowed origins
- Call from
- The browser or your server
- Rate limit
askgroup, set by your plan- Retries
- Safe with
Idempotency-Key
Headers and parameters
| Field | Description |
|---|---|
Origin
|
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
|
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
|
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
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
200 OK
Matching passages.
-
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 addsmetric,usedandlimit).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 atupgrade_url. -
403 Forbidden
The key cannot be used for this request:
forbidden_scope,ip_not_allowedortenant_suspendedas for any key, or theOrigincheck failed:origin_not_configured,origin_required,origin_invalidororigin_not_allowed. -
409 Conflict
The
Idempotency-Keywas 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, 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. -
503 Unavailable
This capability is temporarily paused by Ottla (
feature_disabled). Try again afterRetry-Afterseconds;help_urlshows the service status.
| Field | Description |
|---|---|
query
|
What to search for, up to 500 characters. |
top_k
|
How many results to return, 1 to 50. Default 10. |
website_id
|
Ottla’s id for the website. Ignored for a key bound to one website, as every storefront key is. |
scope_ref
|
Your code for the market or language the shopper is browsing, such as uk. Leave it out for the website’s default. |
locale
|
The shopper’s language, such as en-GB. |
currency
|
The currency to show prices in, such as GBP. |
store_view_id
|
The store view, for a catalogue organised by store view. |
curl https://ottla.ai/api/v1/search \
-H "Authorization: Bearer YOUR_BROWSER_KEY" \
-H "Origin: https://shop.example" \
-H "Content-Type: application/json" \
-d '{"query": "returns policy", "top_k": 3}'
<?php
// $client as in the product search example above
$response = $client->post('search', [
'headers' => [
'Authorization' => 'Bearer YOUR_BROWSER_KEY',
'Origin' => 'https://shop.example',
],
'json' => ['query' => 'returns policy', 'top_k' => 3],
]);
$results = json_decode((string) $response->getBody(), true)['results'];
{
"results": [
{
"title": "Returns and refunds",
"source_type": "returns_policy",
"url": "https://shop.example/returns",
"snippet": "You can return unused items within 30 days of delivery for a full refund.",
"score": 0.8731,
"sku": null
}
]
}
Each result has a title, the kind of content it comes from in source_type (such as product, cms_page, faq or returns_policy), a url, the matching text in snippet, the product’s sku for a product result, and a score. Scores are relative: compare them within one response only. strategy and latency_ms are diagnostic and may change.
Report search events
Reports what shoppers do with your search results, in batches of up to 200 events. Ottla already records each search it answers through /product-search, so send the events only your storefront sees. Rate limit group search_events: 600 requests a minute per key.
- Key
Authorization: Bearerwith theask:readscope- Origin
- One of the key’s allowed origins
- Call from
- The browser or your server
- Rate limit
search_eventsgroup, 600 a minute
Headers and parameters
| Field | Description |
|---|---|
Origin
|
Your storefront’s address, which must be one of the key’s allowed origins. Browsers send it themselves; a server must send it too. |
X-Ottla-Client-Ip
|
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
|
Your own id for this request, returned in the response header. Ottla creates one when you send none. Servers only. |
Responses
-
200 OK
Nothing recorded (not an error).
-
202 Accepted
Accepted: the events will be recorded shortly.
-
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 addsmetric,usedandlimit).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 atupgrade_url. -
403 Forbidden
The key cannot be used for this request:
forbidden_scope,ip_not_allowedortenant_suspendedas for any key, or theOrigincheck failed:origin_not_configured,origin_required,origin_invalidororigin_not_allowed. -
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. -
503 Unavailable
This capability is temporarily paused by Ottla (
feature_disabled). Try again afterRetry-Afterseconds;help_urlshows the service status.
| Field | Description |
|---|---|
events
|
1 to 200 events, each described below. |
page_type
|
The kind of page the events happened on, up to 32 characters. |
surface
|
Where on your storefront the events happened, up to 100 characters, such as search or header. |
website_id
|
Ottla’s id for the website. Ignored for a key bound to one website. |
scope_ref
|
Your code for the market or language, such as uk. |
| Field | Description |
|---|---|
type
|
search (a search ran), impression (a result was shown), click, add_to_cart or order. |
query
|
The search term, up to 500 characters. |
sku
|
The product’s SKU. |
product_id
|
Your platform’s product id, up to 64 characters. |
position
|
The result’s position, counting from 0, up to 1,000. |
results_count
|
How many results the search returned. |
value_minor
|
For add_to_cart and order: the value in minor units, so 12900 is £129.00. |
currency
|
The currency of value_minor, such as GBP. |
session_id
|
The shopper’s session or chat id, up to 128 characters. |
order_ids
|
For order: every order number from the checkout, up to 50. Each order is counted once. |
results_source
|
ottla when the results came from Ottla, native when they came from your own search. |
redirect_url
|
When the search went to a page instead of results, its address. |
event_id
|
Your own id for the event, up to 64 characters. An event sent again with the same id is recorded once. |
curl https://ottla.ai/api/v1/search/events \
-H "Authorization: Bearer YOUR_BROWSER_KEY" \
-H "Origin: https://shop.example" \
-H "Content-Type: application/json" \
-d '{"surface": "search", "events": [{"type": "click", "query": "tent", "sku": "TENT-2P", "position": 0, "event_id": "evt-00412"}]}'
<?php
// $client as in the product search example above
$client->post('search/events', [
'headers' => [
'Authorization' => 'Bearer YOUR_BROWSER_KEY',
'Origin' => 'https://shop.example',
],
'json' => [
'surface' => 'search',
'events' => [
['type' => 'order', 'query' => 'tent', 'sku' => 'TENT-2P', 'value_minor' => 12900,
'currency' => 'GBP', 'order_ids' => ['100004521'], 'event_id' => 'evt-00414'],
],
],
]);
An accepted batch answers 202 with status set to queued, an ack_id and a request_id. If a batch can’t be stored, or the assistant is paused, you get 200 with stored: 0 instead of an error, so reporting never breaks your storefront.
All of these events feed into the Insights → Sales and search page to give the search funnel, click-through rate, percentage of all orders made following an Ottla search, and top searches and searches with no results. On Growth and above, they are also used to populate the Demand inbox, which turns searches with no results into cards ranked by estimated value.
Errors
| Status | Code | What to do |
|---|---|---|
| 401 | unauthenticated, invalid_api_key | Ensure you are sending a valid key. |
| 402 | account_past_due, account_suspended | Your billing needs attention. You should use your own search until this is resolved by the workspace owner. |
| 403 | forbidden_scope and the origin_* codes | Your key needs the ask:read scope. You also need to send an allowed Origin. |
| 422 | validation_failed | Please fix any errors returned in the errors array, such as a page_size that is greater than 100. |
| 429 | rate_limited and the other rate limit codes | Please wait retry_after seconds. Debouncing your autocomplete requests usually avoids this. |
| 503 | feature_disabled | We have temporarily paused this feature. You should use your own search and try again after the Retry-After time. |
FAQ
Questions developers ask
Do searches use my answered questions?
No. Product search, autocomplete, content search and search events never touch your monthly answered questions. Only answers from /ask do.
How do I show a category page?
Call /product-search with an empty query and the category in category_external_ids. Use sort: "recommended" to follow your merchandised order.
How are facet counts worked out?
Disjunctively, meaning the count for an attribute ignores any selection for that attribute. So if a shopper has selected Green, they can see how many Grey tents they would add if they also selected Grey.
What is redirect_url?
A search term redirect that your team has configured, either in Magento or under Merchandising → Search rewrites. If this is returned, you should send the shopper to that URL.
Can shoppers search by part number?
Yes. Send part numbers and barcodes with each product in identifiers, then pass a code in identifier for an exact match, or let shoppers type it into the search box. Matching ignores case, spaces and common separators such as dots and slashes.
Related
Headless storefronts
Build search, product rows and chat into your custom front end.
Recommendations and alerts
Show product rows on your listings, product pages and basket.
Rate limits
Learn about the rate limit groups and what to do if you receive a 429.
AI search
Learn more about what our search provides for your shoppers.
Your team can configure pins, boosts, campaigns and redirects. Learn more about merchandising.