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

API reference

Search

Search and list your products with filters. Search as you type and search your content. Measure your searches with events.

Updated 24 min read

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.

EndpointDescription
POST /product-searchUse to show search results pages and category listings, with filters, sort and pagination.
POST /autocompleteUse to show suggestions under your search box as the shopper types.
POST /searchUse to search your pages, FAQs, policies and documents, for example in a help centre.
POST /search/eventsUse to send search events, for search analytics in the console.
A custom search results page with colour and size filters and a sort menu Example data
A results page built on /product-search. Every filter count comes from the response.
POST /api/v1/product-search 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: Bearer with the ask:read scope
Origin
One of the key’s allowed origins
Call from
The browser or your server
Rate limit
product_search group, 600 a minute

Headers and parameters

POST /product-search: 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.
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

  • 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 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: 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.

  • 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.

  • 503 Unavailable

    This capability is temporarily paused by Ottla (feature_disabled). Try again after Retry-After seconds; help_url shows the service status.

Request fields

Query and filters
FieldDescription
query string Optional What the shopper typed, up to 500 characters. Leave it empty to browse a category.
category_external_ids array Optional The category being browsed, by your category id, up to 50. Lists that category and its subcategories unless include_descendants is false.
attributes object Optional 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 array Optional The attribute codes to return filter counts for, up to 100.
price_min number Optional The lowest price to include, in the shopper’s currency.
price_max number Optional The highest price to include.
in_stock boolean Optional true to list only products in stock.
identifier string Optional A part number, barcode or SKU to find exactly, up to 64 characters.
sort string Optional 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 boolean Optional Put out of stock products after the rest, whatever the sort.
include_descendants boolean Optional Whether a category page lists its subcategories’ products. Default true.
include array Optional Extras for each product. badges adds social proof badges when your website shows them. Unknown values are ignored.
Paging and scope
FieldDescription
page integer Optional The page to return, from 1. Default 1.
page_size integer Optional Products a page, 1 to 100. Default 24.
website_id integer Optional Ottla’s id for the website. Ignored for a key bound to one website, as every storefront key is.
scope_ref string Optional Your code for the market or language the shopper is browsing, such as uk. Leave it out for the website’s default.
locale string Optional The shopper’s language, such as en-GB.
currency string Optional The currency to show prices in, such as GBP.
store_view_id integer Optional 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}'

Response

200 response, trimmed to one product
{
  "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"
}
FieldWhat it holds
productsThis 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.attributesFilter counts for each attribute you named in facet_attributes, with selected marking the shopper’s choices.
facets.categoryCategories in the results, with counts.
facets.priceThe lowest and highest price in the results, and the selected range.
facets.stockHow many results are in stock.
total, page, page_size, total_pagesPaging. sort repeats the order used.
redirect_urlWhen 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.
rewriteThe query after your search rewrites, when one applied.
campaignPresent when the term is a running campaign’s landing term: id, slug, name and ends_at.
strategy, latency_msDiagnostic 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

POST /api/v1/autocomplete 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: Bearer with the search:read scope
Origin
One of the key’s allowed origins
Call from
The browser or your server
Rate limit
autocomplete group, 1,200 a minute

Headers and parameters

POST /autocomplete: 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.
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

  • 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 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: 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.

  • 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.

  • 503 Unavailable

    This capability is temporarily paused by Ottla (feature_disabled). Try again after Retry-After seconds; help_url shows the service status.

Request fields
FieldDescription
query string Optional What the shopper has typed so far, up to 120 characters. Required, except when you ask for popular searches alone.
limit integer Optional Suggestions per section, 1 to 20. Default 6.
mode string Optional keystroke while the shopper types (the default), or submit when they press Enter.
sections array Optional The sections to return: products, categories, pages, articles, answers, popular, ask_cta and did_you_mean. Leave it out for all of them.
include array Optional badges adds social proof badges to product suggestions.
website_id integer Optional Ottla’s id for the website. Ignored for a key bound to one website, as every storefront key is.
scope_ref string Optional Your code for the market or language the shopper is browsing, such as uk. Leave it out for the website’s default.
locale string Optional The shopper’s language, such as en-GB.
currency string Optional The currency to show prices in, such as GBP.
store_view_id integer Optional The store view, for a catalogue organised by store view.
FieldWhat it holds
suggestionsMatching products: title, url, score, sku, external_id, pricing and availability, best match first.
categories, pages, articlesMatching categories, content pages and articles, each with title and url.
answersMatching FAQs and policies.
popularPopular searches on your store: query and searches.
did_you_meanSpelling suggestions when the query looks misspelt.
aiask_cta, an offer to ask the assistant about the query, with available, query and label.
metaThe mode, the sections that ran, and corrected_query when the suggestions are for a corrected spelling.
redirect_urlWhen 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}'
POST /api/v1/search Search catalogue and 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: Bearer with the ask:read scope
Origin
One of the key’s allowed origins
Call from
The browser or your server
Rate limit
ask group, set by your plan
Retries
Safe with Idempotency-Key

Headers and parameters

POST /search: 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

  • 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 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: 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, 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.

  • 503 Unavailable

    This capability is temporarily paused by Ottla (feature_disabled). Try again after Retry-After seconds; help_url shows the service status.

Request fields
FieldDescription
query string Required What to search for, up to 500 characters.
top_k integer Optional How many results to return, 1 to 50. Default 10.
website_id integer Optional Ottla’s id for the website. Ignored for a key bound to one website, as every storefront key is.
scope_ref string Optional Your code for the market or language the shopper is browsing, such as uk. Leave it out for the website’s default.
locale string Optional The shopper’s language, such as en-GB.
currency string Optional The currency to show prices in, such as GBP.
store_view_id integer Optional 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}'
200 response
{
  "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

POST /api/v1/search/events 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: Bearer with the ask:read scope
Origin
One of the key’s allowed origins
Call from
The browser or your server
Rate limit
search_events group, 600 a minute

Headers and parameters

POST /search/events: 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.
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

  • 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 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: 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.

  • 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.

  • 503 Unavailable

    This capability is temporarily paused by Ottla (feature_disabled). Try again after Retry-After seconds; help_url shows the service status.

Request fields
FieldDescription
events array Required 1 to 200 events, each described below.
page_type string Optional The kind of page the events happened on, up to 32 characters.
surface string Optional Where on your storefront the events happened, up to 100 characters, such as search or header.
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.
Each event
FieldDescription
type string Required search (a search ran), impression (a result was shown), click, add_to_cart or order.
query string Optional The search term, up to 500 characters.
sku string Optional The product’s SKU.
product_id string Optional Your platform’s product id, up to 64 characters.
position integer Optional The result’s position, counting from 0, up to 1,000.
results_count integer Optional How many results the search returned.
value_minor integer Optional For add_to_cart and order: the value in minor units, so 12900 is £129.00.
currency string Optional The currency of value_minor, such as GBP.
session_id string Optional The shopper’s session or chat id, up to 128 characters.
order_ids array Optional For order: every order number from the checkout, up to 50. Each order is counted once.
results_source string Optional ottla when the results came from Ottla, native when they came from your own search.
redirect_url string Optional When the search went to a page instead of results, its address.
event_id string Optional 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"}]}'

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.

Search funnel in the Ottla console showing searches, clicks and zero-result searches Example data
The search funnel and zero-result searches, fed by search events.

Errors

StatusCodeWhat to do
401unauthenticated, invalid_api_keyEnsure you are sending a valid key.
402account_past_due, account_suspendedYour billing needs attention. You should use your own search until this is resolved by the workspace owner.
403forbidden_scope and the origin_* codesYour key needs the ask:read scope. You also need to send an allowed Origin.
422validation_failedPlease fix any errors returned in the errors array, such as a page_size that is greater than 100.
429rate_limited and the other rate limit codesPlease wait retry_after seconds. Debouncing your autocomplete requests usually avoids this.
503feature_disabledWe 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.

Your team can configure pins, boosts, campaigns and redirects. Learn more about merchandising.

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.