Blocks API: Get Block Products
Blocks
Blocks API: Get Block Products
Blocks API endpoint that returns product recommendations for a specific block using its configured strategy, fallback chain, and merchandising rules.
POST
Blocks API: Get Block Products
Documentation Index
Fetch the complete documentation index at: https://docs.uselayers.com/llms.txt
Use this file to discover all available pages before exploring further.
Authorization
Token-based authentication header in the form of
<YOUR_LAYERS_TOKEN>.Headers
Path parameters
The unique identifier (ULID) of the block you wish to retrieve products for.
Body
The anchor identifier for the block. Required for product and collection anchor types.
- Product anchors: Numeric product ID (e.g.,
"8234567890123") or Shopify GID (e.g.,"gid://shopify/Product/8234567890123"). Both formats are resolved automatically. - Collection anchors: Collection ID (e.g.,
"456789012345") or collection handle (e.g.,"summer-collection"). The system automatically resolves both numeric IDs and string handles. - Cart anchors: Not required (uses
context.productsInCartinstead) - Home, Search, Not Found, Landing, Other anchors: Not required. These surfaces rely on the
contextandidentityparameters (search query, landing source, shopper context) to drive strategy selection. - None anchors: Not required (global blocks)
Deprecated: Use
anchor_id instead. For collection anchors, anchor_id now accepts both collection IDs and handles.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.A list of product IDs to exclude from the recommendations returned by this block. Use this to deduplicate products across multiple blocks rendered on the same page — for example, to prevent the same product from appearing in both a “Frequently Bought Together” block and a “Customers Also Viewed” block.Each entry can be either a numeric product ID (e.g.,
"8234567890123") or a Shopify GID (e.g., "gid://shopify/Product/8234567890123"). Both formats are accepted and resolved automatically.Excluded products are filtered out before strategy ranking, safeguard checks, and fallback evaluation. If excluding products causes the primary block to fall below its minimum products safeguard, the fallback chain is used and exclusions are applied to fallback blocks as well.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.
Per-request overrides for response behavior. Currently controls image preload hints emitted in the
Link response header. You can disable preloads or narrow the srcset to the breakpoints your storefront uses. You cannot enable preloads when the store has them disabled.Example:Response
When the store has the Expose Variant Inventory setting enabled, variant data in block responses (both
first_or_matched_variant and variants) includes the inventory_quantity, inventory_policy, and inventory_levels fields. This behavior is consistent across all storefront API endpoints — search, browse, and blocks. See Variant Schema Fields for details on these fields.The total number of results. When a maximum products safeguard is configured, this value is capped to the maximum. When variant breakouts are enabled, this reflects the count of tiles (both product and variant tiles) rather than just products.
The current page number.
The total number of pages. Calculated from
totalResults and the requested page size. When a maximum products safeguard is configured, this reflects the capped total. When variant breakouts are enabled, the calculation is based on tile count.The number of results per page (matches the
limit parameter from the request).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.If
includeFacetRanges is true then an object with keys of the facet attribute code and value is an object with min/max.A unique request identifier (ULID) for this API call. Use this token to correlate block requests with analytics events via the Beacon API.
Information about the block that generated these recommendations.
Present and set to
true when the block’s strategy data is still being computed or the strategy doesn’t yet have enough signal to return results. This applies to interaction strategies during their initial computation and to trending and contextual strategies that are warming up. In this state, the primary block returns empty results and the fallback chain is used instead. Once the strategy data is ready, this field is no longer included in the response.An ordered trace of processing steps the engine performed to produce results. Each entry represents a stage in the pipeline, recorded in the order it was executed.See the Text Search documentation for the full list of possible step types.
Response headers
Every API response includes the following headers for request tracing and performance optimization:| Header | Description |
|---|---|
x-request-id | A unique identifier (ULID) for the request. This matches the attributionToken in the response body. |
x-layers-build | The Layers build version that served the request. |
X-Layers-Results-Cache | Indicates whether the response was served from the results cache. Returns HIT or MISS. |
Link | Contains rel="preload" directives for product images (up to 6 items). See Early hints for details. Only included when early hints are enabled (enabled by default). |
Block concepts
For details on how blocks work conceptually (anchor types, strategies, rules, safeguards, and fallback chains), see the platform documentation:Error handling
Error message when the request fails.
404 - Block not found
404 - Block not found
The specified block ID doesn’t exist or is not active.
404 - Unable to get products
404 - Unable to get products
The block exists but couldn’t generate recommendations (e.g., missing anchor_id for product anchor).
401 - Unauthorized
401 - Unauthorized
See also
- Blocks Platform Documentation - Learn about block concepts and configuration