Skip to main content
POST
/
blocks
/
{blockId}
/
products
Blocks API: Get Block Products
curl --request POST \
  --url https://app.uselayers.com/api/storefront/v1/blocks/{blockId}/products \
  --header 'Accept: <accept>' \
  --header 'Content-Type: <content-type>' \
  --header 'X-Storefront-Access-Token: <x-storefront-access-token>' \
  --data '
{
  "anchor_id": "<string>",
  "anchor_handle": "<string>",
  "attributes": [
    "<string>"
  ],
  "excludeProductIds": [
    "<string>"
  ],
  "filter_group": {},
  "pagination": {
    "page": 123,
    "limit": 123
  },
  "facets": [
    "<string>"
  ],
  "retrieveFacetCount": true,
  "includeFacetRanges": true,
  "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,
        "hasResults": true,
        "fromPage": "<string>"
      }
    ],
    "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": {}
  }
}
'
POST /storefront/v1/blocks/01HQXYZ123ABC456DEF789/products

{
  "anchor_id": "8234567890123",
  "pagination": {
    "page": 1,
    "limit": 12
  },
  "context": {
    "geo": {
      "country": "US",
      "province": "California"
    },
    "productsInCart": [
      {
        "title": "Nike Air Force 1",
        "productId": "8234567890123",
        "variantId": "45678901234567"
      }
    ],
    "shoppingChannel": "web"
  },
  "identity": {
    "sessionId": "abc123",
    "deviceId": "device-uuid"
  }
}

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

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

Path parameters

blockId
string
required
The unique identifier (ULID) of the block you wish to retrieve products for.

Body

anchor_id
string
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.productsInCart instead)
  • None anchors: Not required (global blocks)
anchor_handle
string
Deprecated: Use anchor_id instead. For collection anchors, anchor_id now accepts both collection IDs and handles.
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.
excludeProductIds
string[]
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.
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.
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.

Response

results
Array of Objects
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.
totalResults
number
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.
page
number
The current page number.
totalPages
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.
resultsPerPage
number
The number of results per page (matches the limit parameter from the request).
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.
facetRanges
object
If includeFacetRanges is true then an object with keys of the facet attribute code and value is an object with min/max.
attributionToken
string
A unique request identifier (ULID) for this API call. Use this token to correlate block requests with analytics events via the Beacon API.
block
object
Information about the block that generated these recommendations.
_training
boolean
Present and set to true when the block’s interaction strategy data is still being computed. 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.
_meta
object
_workflow
array of objects
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:
HeaderDescription
x-request-idA unique identifier (ULID) for the request. This matches the attributionToken in the response body.
x-layers-buildThe Layers build version that served the request.
X-Layers-Results-CacheIndicates whether the response was served from the results cache. Returns HIT or MISS.
LinkContains 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
string
Error message when the request fails.
Common errors:
The specified block ID doesn’t exist or is not active.
{
  "error": "Block not found"
}
The block exists but couldn’t generate recommendations (e.g., missing anchor_id for product anchor).
{
  "error": "Unable to get products for block"
}
Invalid or missing authentication token.
POST /storefront/v1/blocks/01HQXYZ123ABC456DEF789/products

{
  "anchor_id": "8234567890123",
  "pagination": {
    "page": 1,
    "limit": 12
  },
  "context": {
    "geo": {
      "country": "US",
      "province": "California"
    },
    "productsInCart": [
      {
        "title": "Nike Air Force 1",
        "productId": "8234567890123",
        "variantId": "45678901234567"
      }
    ],
    "shoppingChannel": "web"
  },
  "identity": {
    "sessionId": "abc123",
    "deviceId": "device-uuid"
  }
}

See also