Variant data with first_or_matched_variant
Thefirst_or_matched_variant field provides variant-level data in search and browse responses. This field is particularly useful when you need to display variant-specific information like the matched variant’s price, SKU, or selected options.
When to use first_or_matched_variant
This field returns the most relevant variant for the current request. The system selects a variant using the following priority:- Explicit variant filters — If option or variant filters are applied, the filtered variant is returned.
- Keyword-matched variant — During text search, if keyword features target variant-scoped attributes (options, variant metafields, or variant fields), the variant with the highest keyword relevance score is returned. To prevent false matches, variant selection requires keyword scores to exceed a minimum relevance threshold — only variants with meaningful keyword relevance are selected.
- Pin-level default variant — If the product is pinned (via a merchandising rule or a ranking rule) and the pin has default variant options configured, the variant matching those options is returned. See default variant for pins.
- Default selected options — If
defaultSelectedOptionsis specified, the first matching variant is returned. - Confident vector search match — If semantic search matched a specific variant embedding and the match is confident, that variant is returned. Confidence is determined by comparing the variant embedding distance against the product-level embedding distance of the same type (text-to-text or image-to-image). A match is confident when the variant is meaningfully closer to the query than the product-level embedding. When multiple variants have similar vector scores, or when no product-level embedding of the same type exists for comparison, the system falls through to the position fallback.
- Position fallback — The first available variant by position is returned.
- Displaying the correct variant image when filtering by color
- Showing the matched variant’s price when filtering by size
- Surfacing the keyword-relevant variant when searching for a specific option value
- Accessing variant-specific metafields
Variant schema fields
The
inventory_quantity, inventory_policy, and inventory_levels fields only appear in variant data when the store has the Expose Variant Inventory setting enabled. Location IDs in inventory_levels are returned as string keys.Example first_or_matched_variant response
To include
first_or_matched_variant in API responses, you must explicitly request it in the attributes array parameter. See the Available Attributes for API Requests section.All variants with variants
Thevariants attribute provides access to all product variants in a single API response. This field returns an array of all variants for a product, ordered by position, making it ideal for displaying complete variant selection interfaces or building custom product pages.
When to use variants
Use thevariants attribute when you need to display all available options for a product at once — for example, building a variant selector with all sizes and colors, showing a complete price range, or creating custom comparison interfaces. This attribute is particularly useful for product detail pages.
How variants differs from first_or_matched_variant
Whilefirst_or_matched_variant returns a single variant (either the first available or the one matching applied filters), the variants attribute returns all variants for the product as an array. Both attributes return the same field structure for each variant, but variants gives you complete visibility into all product options.
Variants array structure
Thevariants attribute returns an array of variant objects, each containing the same fields as first_or_matched_variant:
Example variants response
To include
variants in API responses, you must explicitly request it in the attributes array parameter. The variants array is always ordered by the variant’s position field. When discount entitlements are configured, the price field reflects the discounted price for each variant.options_v2 structure
Theoptions_v2 field provides enhanced option data with swatch and linked metafield information from Shopify’s product option values. This field is useful when you need to display visual swatches (colors or images) for product options or access linked metafield data associated with specific option values.
options_v2 schema fields
Option value schema fields
Swatch object schema
Example options_v2 response
The
options_v2 field preserves Shopify’s option ordering and includes option values from all variants regardless of stock status, aligning with original_options behavior. When the same option value appears on multiple variants with different swatch or metafield data, the first non-null value is used.