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.
- Default selected options — If
defaultSelectedOptionsis specified, the first matching variant is returned. - Vector search match — If semantic search matched a specific variant embedding, that variant is returned.
- Position fallback — The first available variant by position is returned.
Variant schema fields
| Field Name | Type | Description |
|---|---|---|
| id | Integer | Unique identifier for the variant |
| title | String | Title of the variant (typically the option values combined) |
| price | String | Price of the variant |
| sku | String | SKU of the variant |
| compare_at_price | String | Compare at price of the variant (original price before discount) |
| available | Boolean | Availability status of the variant. Calculation can be configured at the store level. See Variant Availability Calculation for details. |
| in_stock_location_ids | Array of Integers | Sort-only field. Array of location IDs where the variant has available inventory (available > 0). This field can be used in sort orders for location-based product demotion but is not filterable and is not included in API responses. |
| position | Integer | Position of the variant in the product’s variant list |
| selected_options | Array of Objects | The selected options for this variant (e.g., Size: “M”, Color: “Blue”) |
| featured_media | Object | The featured media for this variant (if variant-specific media exists) |
| created_at | DateTime | DateTime when the variant was created |
| updated_at | DateTime | DateTime when the variant was last updated |
| requires_selling_plan | Boolean | Whether the variant requires a selling plan (subscription) |
| has_selling_plan | Boolean | Whether the variant has an associated selling plan |
| inventory_quantity | Integer | Total inventory quantity across all locations (only included when Expose Variant Inventory is enabled) |
| inventory_policy | String | Inventory policy for the variant: DENY (stop selling when out of stock) or CONTINUE (allow overselling). Only included when Expose Variant Inventory is enabled. |
| inventory_levels | Object | Object mapping location IDs to available inventory quantities (e.g., {"1001": 5, "1002": 10}). Returns empty object {} when no inventory data exists. Only included when Expose Variant Inventory is enabled. |
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, such as building a variant selector with all sizes and colors, showing a complete price range across all variants, or creating custom product comparison interfaces. This attribute is particularly useful for product detail pages where customers need to see all available options.
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.
| Feature | first_or_matched_variant | variants |
|---|---|---|
| Return Type | Single variant object | Array of variant objects |
| Use Case | Display matched/default variant | Display all available variants |
| Ordering | N/A (single variant) | Ordered by position |
| Fields | Variant schema fields | Same variant schema fields |
Variants array structure
Thevariants attribute returns an array of variant objects, each containing the same fields as first_or_matched_variant:
| Field Name | Type | Description |
|---|---|---|
| id | Integer | Unique identifier for the variant |
| title | String | Title of the variant (typically the option values combined) |
| price | String | Price of the variant (includes discount entitlements when applicable) |
| sku | String | SKU of the variant |
| compare_at_price | String | Compare at price of the variant (original price before discount) |
| available | Boolean | Availability status of the variant |
| in_stock_location_ids | Array of Integers | Sort-only field. Array of location IDs where the variant has available inventory (available > 0). This field can be used in sort orders for location-based product demotion but is not filterable and is not included in API responses. |
| position | Integer | Position of the variant in the product’s variant list |
| selected_options | Array of Objects | The selected options for this variant (e.g., Size: “M”, Color: “Blue”) |
| featured_media | Object | The featured media for this variant (if variant-specific media exists) |
| created_at | DateTime | DateTime when the variant was created |
| updated_at | DateTime | DateTime when the variant was last updated |
| requires_selling_plan | Boolean | Whether the variant requires a selling plan (subscription) |
| has_selling_plan | Boolean | Whether the variant has an associated selling plan |
| inventory_quantity | Integer | Total inventory quantity across all locations (only included when Expose Variant Inventory is enabled) |
| inventory_policy | String | Inventory policy for the variant: DENY (stop selling when out of stock) or CONTINUE (allow overselling). Only included when Expose Variant Inventory is enabled. |
| inventory_levels | Object | Object mapping location IDs to available inventory quantities (e.g., {"1001": 5, "1002": 10}). Returns empty object {} when no inventory data exists. Only included when Expose Variant Inventory is enabled. |
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
| Field Name | Type | Description |
|---|---|---|
| name | String | The option name (e.g., “Color”, “Size”) |
| code | String | A normalized, URL-friendly version of the option name (e.g., “color”, “size”) |
| values | Array of Objects | Array of unique option values with their associated swatch and metafield data |
Option value schema fields
| Field Name | Type | Description |
|---|---|---|
| value | String | The option value (e.g., “Red”, “Medium”) |
| swatch | Object or null | Swatch data containing color and/or image information |
| linked_metafield_value | Mixed or null | The linked metafield value associated with this option value in Shopify |
Swatch object schema
| Field Name | Type | Description |
|---|---|---|
| color | String or null | Hex color code (e.g., “#FF0000”) |
| image | Object or null | Image object with alt and url properties |
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.