Search

Configurable storefront search plus the PDP's related-products rail. Results are the SAME canonical product objects the products listing serves (see products.md), reuse your product-card renderer as-is. Money is EUR decimal major units.

SDK module: @cartbase/storefront/api/search.

Matching: title/subtitle/description full-text (Cyrillic-correct 'simple' config, prefix match) ∪ typo tolerance via trigram similarity on the title ("linnen" finds "Linen Shirt") ∪ SKU prefix ∪ exact tag value. Draft products, other tenants, and products outside the publishable key's channels NEVER appear.

Synonyms (admin-authored): expansion is BIDIRECTIONAL and SINGLE-LEVEL (bounded, expansions never re-expand; capped at 24 terms): a query word matching a row's term adds its synonyms; a query word matching one of a row's synonyms adds the term + its sibling synonyms. So with the admin row term: "зехтин", synonyms: ["olive oil"], EITHER direction finds the product. Terms are normalized lowercase.

Pins & boosts (admin-authored): ordering is: (1) pins for this EXACT normalized query, in position order, pins are INJECTED even without a text match, but only if they pass filters + channel scope + published (the leak rule applies to pins too); then (2) globally-boosted products WITHIN the match set, in position order; then (3) relevance rank with a deterministic tie-break. Global boosts reorder, never inject.

Cache rule: responses carry calculated_price when a pricing context is given; they vary by customer group, so a signed-in customer's answer is never cached shared (the platform marks it private, no-store).


  • Purpose: the search results page + autocomplete backend.
  • Auth: anon: x-client-id required; Cartbase-Key optional (channel scope, products-listing semantics, the login deciding the channels on a split key); a signed-in customer optional (group pricing).
  • Request
// query, q is the word; without it, collection_id or category_id is
// required and the endpoint BROWSES that scope (see Browse mode below).
// Everything else optional.
{
  "q": "linen",
  "order": "price_asc",             // browse mode only: the collection sort vocabulary
  "collection_id": "pcol_a,pcol_b", // CSV
  "category_id": "pcat_a",          // CSV
  "tag_id": "ptag_a",               // CSV
  "type_id": "ptyp_a",              // CSV
  "price_min": 10,                  // major units, on the product's cheapest base price
  "price_max": 50,
  "availability": "in_stock",       // in_stock | out_of_stock
  // Option filters, dynamic keys, repeatable; OR within an option, AND
  // across options. URL-encode titles ("Length (cm)" becomes option.Length%20(cm)):
  "option.Size": "S,M",
  "currency_code": "eur",           // pricing context (default price facet currency: eur)
  "region_id": "reg_…",
  "limit": 20,                      // 1 to 100, default 20
  "offset": 0
}
  • Response
{
  "results": [ /* canonical product objects, see products.md */ ],
  "facets": [
    {
      "key": "price",              // "price" | "availability" | "type" |
                                   // "tags" | "collection" | "options.<Title>"
      "label": "Price",
      "type": "range",             // "range" for price, "value" otherwise
      "buckets": [
        { "value": "20-40", "label": "€20 – €40", "count": 3,
          "min": 20, "max": 40 }   // min/max on range buckets only; max null = open top
      ]
    },
    {
      "key": "availability", "label": "Availability", "type": "value",
      "buckets": [ { "value": "in_stock", "label": "In stock", "count": 5 } ]
    }
  ],
  "total": 5,
  "offset": 0,
  "limit": 20
}

Facets follow the tenant's Settings, Search & discovery, Filters config (order + enabled; defaults: price, availability and type on, tags and collection listed but OFF, because a store's tags and collections are the merchant's organising words, a promotion flag or a "valid with code" list, and a merchant turns them on when they are meant for shoppers). The faceting count rule: each facet's bucket counts are computed on the result set filtered by every OTHER active filter, the facet's own dimension is excluded, so selecting "Size: M" never zeroes the other sizes. Empty buckets are omitted; a facet with no buckets is omitted (the dev tenant has no tags/types, so those facets simply don't appear). Price buckets: auto (deterministic nice-number split of observed prices, ≤10 buckets) or fixed admin ranges; apply one by passing its min/max back as price_min/price_max. Value-facet buckets carry ids as value (type/tags/collection) or the option value string (options.<Title>).

  • Working curl: seeded catalog: Linen Shirt (45), Wool Beanie (23), Leather Belt (60), all in the essentials collection:
SEARCH=$(curl -sf "$BASE/api/store/products/search?q=linen&currency_code=eur" \
  -H "x-client-id: $CLIENT_ID")
echo "$SEARCH" | grep -q '"results"'
echo "$SEARCH" | grep -q '"facets"'
echo "$SEARCH" | grep -q '"total"'
echo "$SEARCH" | grep -q '"handle":"linen-shirt"'
echo "$SEARCH" | grep -q '"calculated_price"'
# Default facet config puts price + availability on a priced, stocked catalog:
echo "$SEARCH" | grep -q '"key":"price"'
echo "$SEARCH" | grep -q '"key":"availability"'
# Typo tolerance (title trigram): "linnen" still finds the Linen Shirt.
curl -sf "$BASE/api/store/products/search?q=linnen" -H "x-client-id: $CLIENT_ID" \
  | grep -q '"handle":"linen-shirt"'
# SKU prefix match:
curl -sf "$BASE/api/store/products/search?q=LIN-SHIRT" -H "x-client-id: $CLIENT_ID" \
  | grep -q '"handle":"linen-shirt"'
# Option filter: only the Linen Shirt has Size S; the beanie (Color) and the
# belt (Length (cm)) don't match option.Size at all.
OPT=$(curl -sf "$BASE/api/store/products/search?q=linen&option.Size=S" \
  -H "x-client-id: $CLIENT_ID")
echo "$OPT" | grep -q '"handle":"linen-shirt"'
# A value no variant carries answers an empty result set (envelope intact):
curl -sf "$BASE/api/store/products/search?q=linen&option.Size=XXL" \
  -H "x-client-id: $CLIENT_ID" | grep -q '"results":\[\]'
# Channel scope: the dev PUBLISHABLE_KEY is bound to the B2B channel
# (shirt + beanie). "leather" matches anon but returns nothing under the key.
curl -sf "$BASE/api/store/products/search?q=leather" -H "x-client-id: $CLIENT_ID" \
  | grep -q '"handle":"leather-belt"'
curl -sf "$BASE/api/store/products/search?q=leather" \
  -H "x-client-id: $CLIENT_ID" -H "Cartbase-Key: $PUBLISHABLE_KEY" \
  | grep -q '"results":\[\]'
  • Errors: 400 validation_failed (no q AND no collection_id/ category_id, bad availability, limit > 100), 400 missing_client_id, 400 invalid_publishable_key, 400 invalid_region.
STATUS=$(curl -s -o /dev/null -w '%{http_code}' \
  "$BASE/api/store/products/search" -H "x-client-id: $CLIENT_ID")
test "$STATUS" = 400
curl -s "$BASE/api/store/products/search" -H "x-client-id: $CLIENT_ID" \
  | grep -q '"code":"validation_failed"'

Browse mode: a collection page with filters and counts

Send no q (absent, or empty: the SDK's required q may be "") and a scope, collection_id and/or category_id, and the endpoint lists the scope's members instead of matching a word: the same filters, the same facets with the same counting rule, the same product objects. This is the one read a collection page with filters needs: total is the live "show N products" count under the active filters, facets are the filter groups.

  • Order is the collection's own: its default_sort by default (newest for a category or for several collections), or order= with the collection vocabulary manual | best_selling | title_asc | title_desc | price_asc | price_desc | newest | oldest. An unknown order is ignored. Pins and boosts do not apply here: the merchant's collection order is the order.
  • The request a collection page sends: collection_id=<id> · the shopper's filters (availability, price_min/price_max, type_id, option.<Title>) · order=<sort> · currency_code/region_id · limit/offset for the page.
# Browse the seeded `essentials` collection: its three members, in the
# collection's order, with facets. No word.
ESSENTIALS=$(curl -sf "$BASE/api/store/collections?handle=essentials" \
  -H "x-client-id: $CLIENT_ID" | grep -o '"id":"pcol_[^"]*"' | head -1 | cut -d'"' -f4)
BROWSE=$(curl -sf "$BASE/api/store/products/search?collection_id=$ESSENTIALS&currency_code=eur" \
  -H "x-client-id: $CLIENT_ID")
echo "$BROWSE" | grep -q '"facets"'
echo "$BROWSE" | node -e '
  let s = ""; process.stdin.on("data", d => s += d).on("end", () => {
    const j = JSON.parse(s)
    if (j.total !== 3 || j.results.length !== 3) process.exit(1)
  })'
# An empty q is the same request (the SDK on today's package sends q="").
curl -sf "$BASE/api/store/products/search?q=&collection_id=$ESSENTIALS" \
  -H "x-client-id: $CLIENT_ID" | grep -q '"total":3'
# The shopper's sort, in the collection vocabulary: cheapest first.
curl -sf "$BASE/api/store/products/search?collection_id=$ESSENTIALS&order=price_asc&currency_code=eur" \
  -H "x-client-id: $CLIENT_ID" | node -e '
  let s = ""; process.stdin.on("data", d => s += d).on("end", () => {
    const j = JSON.parse(s)
    if (j.results[0].handle !== "wool-beanie") process.exit(1)
  })'
# A filter narrows the members and total is the live count.
curl -sf "$BASE/api/store/products/search?collection_id=$ESSENTIALS&price_max=30&currency_code=eur" \
  -H "x-client-id: $CLIENT_ID" | grep -q '"total":1'
  • SDK: searchProducts(client, query), pass option filters as options: { Size: ["S","M"] }; the SDK folds them into option.<Title> params.
  • Components: search page, facet sidebar.
  • Settings: Search & discovery: synonyms, pins (per-query) + global boosts, facet order/enabled, price bucket strategy (auto/fixed).

GET /api/store/search/suggest

  • Purpose: the search box: what a shopper sees WHILE typing, the products and the published pages a word finds. The results page (Enter) stays GET /api/store/products/search.
  • Auth: as the products search: anon x-client-id, optional Cartbase-Key (channel scope), optional signed-in customer (prices).
  • Matching: products match and rank EXACTLY as in the products search (synonyms, pins, boosts, typo tolerance), so the box and the results page never disagree about what a word finds or in which order; no filters, no facets. A page matches on its title only: every word as the start of a title word ("контак" finds "Контакти") or the whole word close to the title ("достафка" finds "Условия за доставка"). Published pages only.
  • Request
{
  "q": "контак",               // required, the word as typed
  "types": "product,page",      // optional, one or both kinds (default both)
  "limit": 6,                   // optional, each kind's ceiling, 1 to 10 (default 6)
  "currency_code": "eur",       // pricing context, as the products search
  "region_id": "reg_…"
}
  • Response: products in the products listing's shape (prices included); pages in the shape of GET /api/store/pages, linked at /pages/<handle> (content.md, the path convention).
{
  "products": [ /* canonical product objects, at most `limit` */ ],
  "pages": [
    { "id": "cpage_…", "handle": "contact", "title": "Контакти",
      "publishedAt": "ISO-8601", "createdAt": "ISO-8601", "updatedAt": "ISO-8601" }
  ]
}
# The box's read for "linen": the seeded shirt, priced, and the pages
# envelope (the dev tenant publishes no pages).
SUGGEST=$(curl -sf "$BASE/api/store/search/suggest?q=linen&currency_code=eur" \
  -H "x-client-id: $CLIENT_ID")
echo "$SUGGEST" | grep -q '"handle":"linen-shirt"'
echo "$SUGGEST" | grep -q '"calculated_price"'
echo "$SUGGEST" | grep -q '"pages":\['
# One kind only: products, no pages searched.
curl -sf "$BASE/api/store/search/suggest?q=linen&types=product" \
  -H "x-client-id: $CLIENT_ID" | grep -q '"pages":\[\]'
  • Errors: 400 validation_failed (no q, a blank q, a types value other than product or page, limit outside 1 to 10), 400 missing_client_id, 400 invalid_publishable_key, 400 invalid_region.
STATUS=$(curl -s -o /dev/null -w '%{http_code}' \
  "$BASE/api/store/search/suggest" -H "x-client-id: $CLIENT_ID")
test "$STATUS" = 400
  • SDK: predictiveSearch(client, { q, types?, limit?, ...pricing }).
  • Components: usePredictiveSearch (the behaviour: when to ask, what to drop) and PredictiveSearch (the box and its panel), the search contract in components.md.

  • Purpose: the PDP's product-to-product rails, BOTH of them, discriminated by kind:
    • kind=related (default), the rail below the product. Manual admin picks first (position order), then a DETERMINISTIC fallback fills to limit: same primary collection (newest first), then most-shared-tags. auto_filled: true when any fallback item is present.
    • kind=complementary: the "goes with this" slot above the product. The merchant's picks in their order and NOTHING else; auto_filled is always false. There is no fallback by design: similarity can be computed, complementarity is a merchant judgement, and a guessed upsell beside the buy button is worse than an empty slot. An empty response means render nothing.
  • Auth: anon: x-client-id; optional publishable key, the anchor product must be visible to the key, and scoped-away products never appear as related items; an optional signed-in customer (group pricing).
  • Request: query { kind? (related|complementary, default related), limit? (1 to 24, default 12), currency_code?, region_id? }. Accepts a product id (prod_…) or handle.
  • Response
{
  "products": [ /* canonical product objects, self-excluded */ ],
  "count": 2,
  "auto_filled": true   // at least one item came from the fallback chain
}
  • Working curl: the seeded products share the essentials collection, so the shirt's rail fills from it:
RELATED=$(curl -sf "$BASE/api/store/products/linen-shirt/related?currency_code=eur" \
  -H "x-client-id: $CLIENT_ID")
echo "$RELATED" | grep -q '"products"'
echo "$RELATED" | grep -q '"auto_filled"'
echo "$RELATED" | grep -q '"count"'
  • Errors: 404 not_found (unknown id/handle, draft, or anchor outside the key's channels), 400 validation_failed, 400 invalid_region.
# Channel scope on the ANCHOR: the belt is outside the B2B key's channels.
STATUS=$(curl -s -o /dev/null -w '%{http_code}' \
  "$BASE/api/store/products/leather-belt/related" \
  -H "x-client-id: $CLIENT_ID" -H "Cartbase-Key: $PUBLISHABLE_KEY")
test "$STATUS" = 404
  • SDK: listRelatedProducts(client, idOrHandle, query?).
  • Components: PDP related rail.
  • Settings: manual picks: Admin, Product, Related (drag-ordered, ≤24); the fallback chain needs no configuration.