Skip to main content
POST
/
search
/
{searchQuery}
/
execute
Text Search: Execute Search
curl --request POST \
  --url https://app.uselayers.com/api/storefront/v1/search/{searchQuery}/execute \
  --header 'Accept: <accept>' \
  --header 'Content-Type: <content-type>' \
  --header 'X-Storefront-Access-Token: <x-storefront-access-token>' \
  --data '
{
  "attributes": [
    "<string>"
  ],
  "search_id": "<string>",
  "filter_group": {},
  "pagination": {
    "page": 123,
    "limit": 123
  },
  "facets": [
    "<string>"
  ],
  "retrieveFacetCount": true,
  "includeFacetRanges": true,
  "discountEntitlements": [
    {
      "entitled": {
        "all": true,
        "products": [
          "<string>"
        ],
        "variants": [
          {}
        ],
        "collections": [
          "<string>"
        ]
      },
      "discount": {
        "type": "<string>",
        "value": 123
      }
    }
  ],
  "defaultSelectedOptions": [
    {
      "optionCode": "<string>",
      "value": "<string>"
    }
  ],
  "identity": {
    "deviceId": "<string>",
    "sessionId": "<string>",
    "customerId": "<string>"
  },
  "context": {
    "geo": {
      "country": "<string>",
      "province": "<string>",
      "city": "<string>"
    },
    "productsInCart": [
      {
        "title": "<string>",
        "price": 123,
        "type": "<string>",
        "productId": "<string>",
        "variantId": "<string>",
        "options": {}
      }
    ],
    "productsPurchased": [
      {
        "title": "<string>",
        "price": 123,
        "type": "<string>",
        "productId": "<string>",
        "variantId": "<string>",
        "options": {}
      }
    ],
    "priorSearches": [
      {
        "searchQuery": "<string>",
        "hadClick": true,
        "hadResults": true
      }
    ],
    "marketing": {
      "source": "<string>",
      "medium": "<string>",
      "campaign": "<string>",
      "term": "<string>"
    },
    "customer": {
      "signedIn": true,
      "returning": true,
      "numberOfOrders": 123,
      "averageOrderValue": 123,
      "daysBetweenOrders": 123,
      "daysSinceLastOrder": 123,
      "daysSinceOldestOrder": 123,
      "totalSpent": 123
    },
    "shoppingChannel": "<string>",
    "custom": {}
  },
  "sort_order_code": "<string>",
  "include_timings": true
}
'
POST /storefront/v1/search/running%20shoes/execute

{
  "pagination": {
    "page": 1,
    "limit": 20
  },
  "retrieveFacetCount": true,
  "facets": ["vendor", "product_type"],
  "context": {
    "geo": {
      "country": "US",
      "province": "California"
    },
    "productsInCart": [
      {
        "title": "Nike Air Force 1",
        "productId": "1234567890",
        "variantId": "9876543210"
      }
    ],
    "marketing": {
      "source": "google",
      "medium": "cpc",
      "campaign": "summer-sale"
    },
    "shoppingChannel": "web"
  },
  "identity": {
    "sessionId": "abc123",
    "deviceId": "device-uuid"
  }
}

Authorization

X-Storefront-Access-Token
string
required
Token-based authentication header in the form of <YOUR_LAYERS_TOKEN>.

Headers

Content-Type
string
default:"application/json"
required
Accept
string
default:"application/json"
required
X-SDK-Client
string
Optional header to identify SDK client requests. Format: sdk-name/version (e.g., layers-js-sdk/1.0.0). When provided with version >= 1.0.0, the server returns HTTP 425 (Too Early) with a Retry-After header when prepared search data isn’t ready yet, instead of blocking. This enables efficient client-side polling for async search operations.

Path Parameters

searchQuery
string
required
The url-encoded search query.

Body

attributes
string[]
Product attributes to include in the response. By default, all attributes are included. Available attributes include: id, title, handle, body_html, vendor, product_type, tags, images, available, created_at, updated_at, published_at, price_range, options, original_options, metafields, named_tags, calculated, category, featured_media, is_gift_card, has_variants_that_require_components, combined_listing_parent_product_id, combined_listing_role, first_or_matched_variant, and variants. See the Product Schema for detailed descriptions.
search_id
string
ULID identifier from the Prepare Search endpoint for optimized search execution. When provided, uses pre-computed embeddings and query expansions.
filter_group
object
Refer to our dedicated Filter Expressions guide to learn more about filter expressions.
pagination
Pagination Object
facets
string[]
Facets to be included. Accepts both exact facet codes (e.g., "vendor", "options.Size") and wildcard patterns (e.g., "options.*", "metafields.product.*").Wildcard patterns expand to all matching attribute codes. For example, "options.*" expands to all option facets like "options.Size" and "options.Color". Wildcards must match at least one attribute code to be valid.Examples:
// Exact facet codes
"facets": ["vendor", "options.Size", "options.Color"]

// Wildcard pattern
"facets": ["options.*"]

// Mixed exact and wildcard
"facets": ["vendor", "options.*", "metafields.product.*"]
retrieveFacetCount
boolean
If the count of each facet value should be calculated
includeFacetRanges
boolean
If you want a min/max range for numeric facets such as price.
discountEntitlements
array
Apply discounts to products, variants, or collections. When provided, price-based sorting and filtering will use discounted prices. See the Discount Entitlements guide for detailed usage.
defaultSelectedOptions
array
Specify which product variants should be selected by default in the first_or_matched_variant field. This is useful for scenarios like defaulting to a specific birthstone option when searching in a jewelry store.Behavior:
  • Uses OR logic - selects the first variant matching ANY of the specified option values
  • Falls back to the first variant by position if no match is found
  • Automatically skipped when any option or variant filters are applied (filters take precedence)
  • Only affects the first_or_matched_variant field in the response
  • Works with Variant Breakouts - product tiles respect your default selected options, and variant tiles respect non-breakout default selected options (preferring variants that match your preferences within each breakout group, with fallback to position ordering)
Example:
{
  "defaultSelectedOptions": [
    {
      "optionCode": "birthstone",
      "value": "February"
    }
  ]
}
Multiple options example (OR logic):
{
  "defaultSelectedOptions": [
    {
      "optionCode": "birthstone",
      "value": "February"
    },
    {
      "optionCode": "birthstone",
      "value": "March"
    }
  ]
}
This will select variants with either February OR March birthstone, preferring the first match found.
identity
object
User identity information for tracking and personalization. Automatically managed by the Storefront Pixel; required for headless integrations.
context
object
Contextual information about the customer’s session, behavior, and environment. Automatically collected by the Storefront Pixel; must be manually provided for headless integrations. See Contextual Information for implementation guidance.
sort_order_code
string
Code of the sort order to apply. Use "relevance" for the default relevance-based ranking, or any custom sort order code configured in your store. Retrieve available sort order codes from the Sort Orders API.
include_timings
boolean
default:false
When true, includes detailed timing metrics in the response _meta.timings object for debugging and performance analysis. Only available when using the prepare/execute flow (i.e., when search_id is provided). Timing values are in milliseconds.

Response

results
Array of Objects
Semantic Redirects: When a text search query semantically matches a configured redirect term, the response will include a _meta.redirect object with the redirect URL. In this case, the results array will be empty and totalResults will be 0. Semantic redirects only apply to text search queries (not image or similar product searches).
totalResults
number
The total number of results. When variant breakouts are enabled, this reflects the count of tiles (both product and variant tiles) rather than just products.
page
number
The current page number.
totalPages
number
The total number of pages. Calculated based on tile count when variant breakouts are enabled.
attributionToken
string
The attribution token.
facetRanges
object
If includeFacetRanges is true then an object with keys of the facet attribute code and value is an object with min/max.
facets
object
If retrieveFacetCount is true then an object with keys and values of the specified attributes. When variant breakouts are enabled, facet counts reflect tile counts rather than product counts. Empty values and literal "null" strings are automatically excluded from facet results.
_meta
object

Variant Breakouts

When variant breakouts are configured for search, results may include both product tiles and variant tiles. Each result includes a __typename field to identify the tile type:
__typename
string
Identifies the type of tile in the results:
  • "Product" - A standard product tile
  • "Variant" - An individual variant tile from a product with a configured breakout option

Variant Tile Fields

Variant tiles include additional fields to identify the specific variant:
product_id
number
The parent product ID. Use this to link back to the full product or group variants from the same product.
variant_id
number
The specific variant ID. For variant tiles, this matches the id field.
For variant tiles, the id field contains the variant ID (not the product ID). The title field is formatted as "{product title} - {option value}" by default (e.g., “Amethyst Ring - Rose Quartz”), but this can be configured per breakout. If the breakout’s “Include Option Value in Title” setting is disabled, the title will be the original product title. See the Variant Breakouts documentation for more details.
POST /storefront/v1/search/running%20shoes/execute

{
  "pagination": {
    "page": 1,
    "limit": 20
  },
  "retrieveFacetCount": true,
  "facets": ["vendor", "product_type"],
  "context": {
    "geo": {
      "country": "US",
      "province": "California"
    },
    "productsInCart": [
      {
        "title": "Nike Air Force 1",
        "productId": "1234567890",
        "variantId": "9876543210"
      }
    ],
    "marketing": {
      "source": "google",
      "medium": "cpc",
      "campaign": "summer-sale"
    },
    "shoppingChannel": "web"
  },
  "identity": {
    "sessionId": "abc123",
    "deviceId": "device-uuid"
  }
}