variants query
The variants query returns details about all variations of a product.
The variants query is useful for showing variant images on product detail (PDP) or product listing (PLP) pages without submitting multiple API requests.
Query results are paginated with a default, maximum pagination size of 100. The query supports cursor-based pagination as follows:
- The initial query returns a cursor value marking the last item in the current page.
- If all results are returned, the
cursorvalue isnull. - If more results are available, use the
cursorvalue returned in subsequent queries to fetch additional results. For an example, see Paginate product variant results.
Syntax
variants(sku: String!, optionIds: [String!], pageSize: Int, cursor: String): ProductViewVariantResults
Endpoints
data-src=../../../../includes/graphql/endpoints.md
Required headers
You must specify the following HTTP headers to run this query.
data-src=../../../../includes/graphql/catalog-service/headers.md
Find the customer group code
data-src=../../../../includes/graphql/customer-group-code.md
Example usage
The variants query requires at least one SKU value as input. Optionally, you can specify optionIDs and pagination controls. Specify optionIDs to retrieve variants based on product options such as size or color. See Input fields.
Return all variants using pagination
The following query returns the SKU, name, and available image information for all variants of the MH07 product. Setting the query pagination to 10 fetches the first ten results.
data-slots=heading, code
data-repeat=2
data-languages=JSON
query {
variants(sku: "MH07", pageSize: 10) {
variants {
selections
product {
sku
name
images(roles: []) {
url
label
roles
}
}
}
cursor
}
}
{
"data": {
"variants": {
"variants": [
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzU4",
"Y29uZmlndXJhYmxlLzE4Ni8xODM="
],
"product": {
"sku": "MH07-31-Black",
"name": "Hero Hoodie28-31-Black",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzU5",
"Y29uZmlndXJhYmxlLzE4Ni8xODM="
],
"product": {
"sku": "MH07-31-Blue",
"name": "Hero Hoodie28-31-Blue",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzE4Ni8xODM=",
"Y29uZmlndXJhYmxlLzkzLzYx"
],
"product": {
"sku": "MH07-31-Gray",
"name": "Hero Hoodie28-31-Gray",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzYy",
"Y29uZmlndXJhYmxlLzE4Ni8xODM="
],
"product": {
"sku": "MH07-31-Green",
"name": "Hero Hoodie28-31-Green",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzU4",
"Y29uZmlndXJhYmxlLzE4Ni8xODY="
],
"product": {
"sku": "MH07-34-Black",
"name": "Hero Hoodie28-34-Black",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzE4Ni8xODY=",
"Y29uZmlndXJhYmxlLzkzLzU5"
],
"product": {
"sku": "MH07-34-Blue",
"name": "Hero Hoodie28-34-Blue",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzYx",
"Y29uZmlndXJhYmxlLzE4Ni8xODY="
],
"product": {
"sku": "MH07-34-Gray",
"name": "Hero Hoodie28-34-Gray",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzE4Ni8xODY=",
"Y29uZmlndXJhYmxlLzkzLzYy"
],
"product": {
"sku": "MH07-34-Green",
"name": "Hero Hoodie28-34-Green",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzU4",
"Y29uZmlndXJhYmxlLzE4Ni8xNzg="
],
"product": {
"sku": "MH07-L-Black",
"name": "Hero Hoodie-L-Black",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-black_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzE4Ni8xNzg=",
"Y29uZmlndXJhYmxlLzkzLzU5"
],
"product": {
"sku": "MH07-L-Blue",
"name": "Hero Hoodie28-L-Blue",
"images": []
}
}
],
"cursor": "TUgwNy1MLUJsdWU6Ojo6OjoxMA=="
}
}
}
Return results by cursor position
Using the cursor value from the previous response (TUgwNy1MLUJsdWU6Ojo6OjoxMA==) as input, run the same query to fetch the next set of results. When the last variant item is returned, the cursor value is null.
data-slots=heading, code
data-repeat=2
data-languages=JSON
query {
variants(sku: "MH07", pageSize: 10 cursor: "TUgwNy1MLUJsdWU6Ojo6OjoxMA==") {
variants {
selections
product {
sku
name
images(roles: []) {
url
label
roles
}
}
}
cursor
}
}
{
"data": {
"variants": {
"variants": [
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzYx",
"Y29uZmlndXJhYmxlLzE4Ni8xNzg="
],
"product": {
"sku": "MH07-L-Gray",
"name": "Hero Hoodie-L-Gray",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
},
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_alt1_2.jpg",
"label": "",
"roles": []
},
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_back_2.jpg",
"label": "",
"roles": []
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzYy",
"Y29uZmlndXJhYmxlLzE4Ni8xNzg="
],
"product": {
"sku": "MH07-L-Green",
"name": "Hero Hoodie-L-Green",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-green_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzU4",
"Y29uZmlndXJhYmxlLzE4Ni8xNzc="
],
"product": {
"sku": "MH07-M-Black",
"name": "Hero Hoodie-M-Black",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-black_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzU5",
"Y29uZmlndXJhYmxlLzE4Ni8xNzc="
],
"product": {
"sku": "MH07-M-Blue",
"name": "Hero Hoodie28-M-Blue",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzYx",
"Y29uZmlndXJhYmxlLzE4Ni8xNzc="
],
"product": {
"sku": "MH07-M-Gray",
"name": "Hero Hoodie-M-Gray",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
},
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_alt1_2.jpg",
"label": "",
"roles": []
},
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_back_2.jpg",
"label": "",
"roles": []
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzYy",
"Y29uZmlndXJhYmxlLzE4Ni8xNzc="
],
"product": {
"sku": "MH07-M-Green",
"name": "Hero Hoodie-M-Green",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-green_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzU4",
"Y29uZmlndXJhYmxlLzE4Ni8xNzY="
],
"product": {
"sku": "MH07-S-Black",
"name": "Hero Hoodie-S-Black",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-black_main_1.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzU5",
"Y29uZmlndXJhYmxlLzE4Ni8xNzY="
],
"product": {
"sku": "MH07-S-Blue",
"name": "Hero Hoodie28-S-Blue",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzYx",
"Y29uZmlndXJhYmxlLzE4Ni8xNzY=",
"Y29uZmlndXJhYmxlLzkzLzUwOA=="
],
"product": {
"sku": "MH07-S-Gray",
"name": "Hero Hoodie-S-Gray",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
},
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_alt1_2.jpg",
"label": "",
"roles": []
},
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_back_2.jpg",
"label": "",
"roles": []
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzE4Ni8xNzY=",
"Y29uZmlndXJhYmxlLzkzLzYy"
],
"product": {
"sku": "MH07-S-Green",
"name": "Hero Hoodie-S-Green",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-green_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
}
]
}
}
],
"cursor": "TUgwNy1TLUdyZWVuOjo6Ojo6MTA="
}
}
}
Return variants by optionId
This query returns the SKU, name, and images for all size large variants of product MH07. The optionIDs input parameter value is sourced from the Return details about a complex product example in the products query. The optionIDs parameter can be specified as a single string, or an array if you supply multiple values.
data-slots=heading, code
data-repeat=2
data-languages=JSON, CURL, JSON
query {
variants(sku: "MH07", optionIds: "Y29uZmlndXJhYmxlLzE4Ni8xNzg=") {
variants {
selections
product {
sku
name
images(roles: []) {
url
label
roles
}
}
}
cursor
}
}
{
"data": {
"variants": {
"variants": [
{
"selections": [
"Y29uZmlndXJhYmxlLzE4Ni8xNzg=",
"Y29uZmlndXJhYmxlLzkzLzU4"
],
"product": {
"sku": "MH07-L-Black",
"name": "Hero Hoodie-L-Black",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-black_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzE4Ni8xNzg=",
"Y29uZmlndXJhYmxlLzkzLzU5"
],
"product": {
"sku": "MH07-L-Blue",
"name": "Hero Hoodie28-L-Blue",
"images": []
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzE4Ni8xNzg=",
"Y29uZmlndXJhYmxlLzkzLzYx"
],
"product": {
"sku": "MH07-L-Gray",
"name": "Hero Hoodie-L-Gray",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
},
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_alt1_2.jpg",
"label": "",
"roles": []
},
{
"url": "http://example.com/media/catalog/product/m/h/mh07-gray_back_2.jpg",
"label": "",
"roles": []
}
]
}
},
{
"selections": [
"Y29uZmlndXJhYmxlLzkzLzYy",
"Y29uZmlndXJhYmxlLzE4Ni8xNzg="
],
"product": {
"sku": "MH07-L-Green",
"name": "Hero Hoodie-L-Green",
"images": [
{
"url": "http://example.com/media/catalog/product/m/h/mh07-green_main_2.jpg",
"label": "",
"roles": [
"image",
"small_image",
"thumbnail"
]
}
]
}
}
],
"cursor": null
}
}
}
Input fields
You must specify a SKU value for the query.
cursorcursor value returned in the results from a previous variants query to fetch the next set of results. See Return results by cursor position example.optionIdspageSizeskuOutput fields
This query returns a ProductViewVariantResults object, which contains the cursor field and a list of ProductViewVariant objects, one for each variant associated with the product SKU.
cursorStringvariants query to fetch the next set of results. If there are no more results, the cursor value is null.variants[ProductViewVariant]!ProductViewVariant type
selections[String!]ProductView interface
The ProductView return object is an interface that can contain the following fields. It is implemented by the SimpleProductView and ComplexProductView types.
addToCartAllowedattributes(roles: [String])descriptionexternalIdidinputOptionsinStocklastModifiedAtlowStockmetaDescriptionmetaKeywordmetaTitlenameshortDescriptionskuurlurlKeyComplexProductView type
The ComplexProductView type represents bundle, configurable, and group products. Complex product prices are returned as a price range, because price values can vary based on selected options. The type implements ProductView.
addToCartAllowedattributes(roles: [String])descriptionexternalIdidinputOptionsinStocklowStockmetaDescriptionmetaKeywordmetaTitlenameshortDescriptionskuurlurlKeyvideos[ProductViewVideo](#productviewvideo-type)Price type
The Price type defines the price of a simple product or a part of a price range for a complex product. It can include a list of price adjustments.
PriceAdjustment type
The PriceAdjustment type specifies the amount and type of a price adjustment. An example code value is weee.
amountcodeProductViewAttribute type
The ProductViewAttribute type is a container for customer-defined attributes that are displayed the storefront.
labelnamerolesvalueProductViewImage type
The ProductViewImage type contains details about a product image.
labelrolesimage, small_image, or thumbnail.urlProductViewLink type
The ProductViewLink type contains details about product links for related products and cross selling.
linkTypescrosssell, related, and upsell.productProductView!ProductViewMoney type
The ProductViewMoney type defines a monetary value, including a numeric value and a currency code.
currencyvalueProductViewInputOption type
Product input options provide details about how a shopper can enter customization details for a product. For example, for product personalization the input options might provide the fields for the shopper to add an image or text for a monogram. The input option can include an associated markupAmount that is applied to the product price. For additional information, see Product settings - Customizable Options.
fileExtensionspng, jpg.idmarkupAmountrangerequiredsortOrdersuffixtitletypetextfield, textarea, date, date_time, time, file.ProductViewInputOptionRange type
Lists the value range associated with a [ProductViewInputOption]. For example, if the input option is a text field, the range represents the number of characters.
fromtoProductViewInputOptionImageSize type
Lists the image dimensions for an image associated with a [ProductViewInputOption].
heightwidthProductViewOption type
Product options provide a way to configure products by making selections of particular option values predefined for the product. Selecting one or many options points to a specific simple product.
idmultirequiredtitleProductViewOptionValue interface
The ProductViewOptionValue interface defines the product fields available to the ProductViewOptionValueProduct and ProductViewOptionValueConfiguration types.
idinStocktitleProductViewOptionValueConfiguration type
The ProductViewOptionValueConfiguration type is an implementation of ProductViewOptionValue for configuration values.
idinStocktitleProductViewOptionValueProduct type
The ProductViewOptionValueProduct type is an implementation of ProductViewOptionValue that adds details about a simple product.
idinStockisDefaulttitleProductViewOptionValueSwatch type
The ProductViewOptionValueSwatch type is an implementation of ProductViewOptionValue that adds details about a product swatch.
idinStocktitletypeTEXT, IMAGE, COLOR_HEX, or CUSTOM.valueProductViewPrice type
The ProductViewPrice type provides the base product price view, inherent for simple products.
finalregularrolesProductViewPriceRange type
The ProductViewPriceRange type lists the minimum and maximum price of a complex product.
maximumminimumProductViewVideo type
urldescriptiontitleSimpleProductView type
The SimpleProductView type represents all product types, except bundle, configurable, and group. Simple product prices do not contain price ranges. SimpleProductView implements ProductView.
addToCartAllowedattributes(roles: [String])descriptionexternalIdidinputOptionsinStocklowStockmetaDescriptionmetaKeywordmetaTitlenameshortDescriptionskuurlurlKey