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.
Overview
Layers facet metaobjects describe which filters are configured for your store (their name and code), but they do not contain the runtime values, counts, or numeric ranges available for a given collection. To render a working filter sidebar, combine the two data sources:- Read facet metaobjects in Liquid to get the list of configured facets and their codes.
- Pass those codes to the Facets API for the current collection.
- The API returns only the facet values that exist in that collection, along with counts and min/max ranges.
Prerequisites
- The Layers Shopify app installed and synced.
- Facets configured in the Layers dashboard with Enable as Storefront Facet turned on.
- A storefront access token (available via
shop.metafields.layers.embed_settings). See Liquid integration for full setup.
The pattern
Read facet metaobjects in Liquid
Each facet metaobject exposes a
name (display label) and code (the attribute code passed to the API).Collect every facet code and pass it to the API
Build the request body from the codes rendered server-side. Set The response only includes values that exist for products in
retrieveFacetCount: true to get per-value counts and includeFacetRanges: true to get min/max for numeric facets (e.g. price).{collection_handle}. Facets with no matching products are omitted, so you never render dead-end filters.Counts and ranges
The Facets API returns two complementary shapes:| Field | When returned | Shape | Use for |
|---|---|---|---|
facets | retrieveFacetCount: true | { [code]: { [value]: count } } | Checkbox / pill filters where each option shows a result count |
facetRanges | includeFacetRanges: true | { [code]: { min, max } } | Numeric facets (price, weight, rating) rendered as sliders or min/max inputs |
facetRanges, categorical ones in facets.
Example response
Wildcards
If you have many option or metafield facets, you can pass wildcard patterns instead of enumerating every code:options.*) or every product metafield (metafields.product.*) without keeping the theme in sync with attribute changes. Wildcards must match at least one attribute code.
Keeping counts accurate as filters are applied
To narrow counts as the customer applies filters, send the active filter selections as afilter_group on the same endpoint. The response counts then reflect only products that match the current selection. See Filter expressions for the full filter grammar.
When to use the Facets API vs. Browse
- Use the Facets API when you only need filter data — for example, pre-rendering the sidebar before any product results load, or refreshing counts as the customer toggles filters.
- Use the Browse API with
retrieveFacetCountandincludeFacetRangeswhen you need products and facets in a single round trip (typical for the initial collection page load).
Troubleshooting
Facet metaobjects are empty in Liquid. Confirm the facet has Enable as Storefront Facet turned on in the Layers dashboard and that the metaobject is visible under Content → Metaobjects in Shopify admin. A facet is missing from the API response. The Facets API omits facets with no matching values for the current collection. Hide the corresponding group in the UI (as in the example above) rather than treating it as an error. Counts look wrong after applying filters. Make sure you are re-requesting the Facets API with an updatedfilter_group every time the active selection changes.
See also
- Liquid integration — reading sort orders, facets, blocks, and app settings from Liquid
- Facets API — full request and response reference
- Browse API — combined product results and facets
- Filters / facets — configuring facets in the Layers dashboard