Hi, I’m trying to create products and variants via the GraphQL Admin API. Precisely, I
- create the product with media and options
- then try to create the product variant with option values and media id assigned.
While the former works perfectly, the latter fails silently. I get an empty result instead of an array of the variants created. Further, the variants are created but incomplete. The image is present in the product but isn’t assigned to the variant. Price and inventory item information also haven’t been applied. I have no idea why.
Here an example mutation with real data.
mutation CreateProductVariants(
$productId: ID!,
$media: [CreateMediaInput!],
$variants: [ProductVariantsBulkInput!]!,
$strategy: ProductVariantsBulkCreateStrategy
) {
productVariantsBulkCreate(
productId: $productId,
media: $media,
variants: $variants,
strategy: $strategy
) {
productVariants {
id
displayName
product {
id
}
position
selectedOptions {
name
}
image {
id
url
width
height
}
}
media(first: 100) {
edges {
node {
id
mediaContentType
alt
status
preview {
image {
id
altText
url
width
height
}
}
}
}
inventoryItem {
id
}
inventoryQuantity
inventoryPolicy
price
createdAt
updatedAt
}
}
}
and the data passed:
Array
(
[productId] => gid://shopify/Product/8574635835549
[variants] => Array
(
[0] => Array
(
[price] => 19.90
[mediaId] => gid://shopify/MediaImage/30908724215965
[inventoryItem] => Array
(
[sku] => 1000132-1118-003-XS
[cost] => 11.87
[measurement] => Array
(
[weight] => Array
(
[value] => 250
[unit] => GRAMS
)
)
)
[optionValues] => Array
(
[0] => Array
(
[optionName] => Color
[name] => black
)
[1] => Array
(
[optionName] => Size
[name] => XS
)
)
)
)
[strategy] => REMOVE_STANDALONE_VARIANT
[media] =>
)
Any help is appreciated.