I am trying to create a shopify product as well as multiple variants all in the same productCreate mutation.
This is the query I have:
mutation CreateProductWithOptions($input: ProductInput!) {
productCreate(input: $input) {
userErrors {
field
message
}
product {
id
options {
id
name
position
values
optionValues {
id
name
hasVariants
}
}
variants(first: 5) {
nodes {
id
title
selectedOptions {
name
value
}
}
}
}
}
}
This is the productOptions:
[{"name":"colours","values":[{"name":"blue"},{"name":"green"}]},{"name":"sizes","values":[{"name":"Medium"},{"name":"Small"}]}]
And this is the variants:
[{"barcode":"C1AQ68VG","options":"colours: blue / sizes: Medium"},{"barcode":"6C7AS6KG","options":"colours: blue / sizes:
Small"},{"barcode":"UHWACOLQ","options":"colours: green / sizes: Medium"},{"barcode":"0P07QNKL","options":"colours: green / sizes: Small"}]
My input looks like this:
input: {
title, // Product title
productOptions, // Product options
variants,
},
But it didn't create successfully.
Is this completely wrong?
I saw this post on Shopify forum: https://community.shopify.com/c/graphql-basics-and/adding-multiple-product-variants-with-graphql/m-p/1340228
and thought it would work.
Can someone help me out?
I have tried the codes I posted but it didn't create shopify products with multiple variants successfully.