Text Search: Prepare Search
Text Search
Text Search: Prepare Search
Prepare Search API endpoint that starts a search asynchronously so personalization and ranking can run in the background during a redirect or page load.
POST
Text Search: Prepare Search
This endpoint asynchronously prepares expensive personalization for a given query, returning a ULIDDocumentation Index
Fetch the complete documentation index at: https://docs.uselayers.com/llms.txt
Use this file to discover all available pages before exploring further.
search_id that can be used with the Search API to execute the search.
- Use with: Search API via the
search_idbody parameter
Authorization
Token-based authentication header in the form of
<YOUR_LAYERS_TOKEN>. Same requirements as the Search API.Headers
Path parameters
The url-encoded search query to prepare.
Body
Optional hint for which product attributes you intend to include in the eventual Search response. 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, and first_or_matched_variant. See the Product Schemafor detailed descriptions.Refer to our dedicated Filter Expressions guide to learn more about filter expressions.
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:If the count of each facet value should be calculated
If you want a min/max range for numeric facets such as price.
User identity information for tracking and personalization. Automatically managed by the Storefront Pixel; required for headless integrations.
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.
Behavior
- Returns HTTP 202 (Accepted) immediately with a
search_id - Generates a ULID
search_idthat identifies the prepared search - Starts additional search preparation asynchronously
- Pre-computes query understanding and personalization inputs
- Prepared data is cached for up to 15 minutes; after TTL, Search falls back to normal processing
Response
202 Accepted
ULID identifier for the prepared search. Valid for 15 minutes.
Response headers
| Header | Description |
|---|---|
x-request-id | A unique identifier (ULID) for the request. Use it to correlate requests across your infrastructure or when contacting support. |
x-layers-build | The Layers build version that served the request. |
Error conditions
- 401 Unauthorized: Missing/invalid
X-Storefront-Access-Token - 422 Unprocessable Entity: Invalid body or parameters
Next steps
Use the returnedsearch_id with the Search API in the search_id body parameter to execute an optimized search.