How to create a product with multiple variants via 2024-04 GraphQL?

Solved

How to create a product with multiple variants via 2024-04 GraphQL?

daveluke
Shopify Partner
25 2 10

What is the standard process for creating a new product with multiple variants via the Shopify GraphQL API?

 

I am creating a product with options, and then in a separate call, I am trying to create multiple variants. with productVariantsBulkCreate. However, the productCreate mutation also creates a single variant from the options, so sometimes the productVariantsBulkCreate mutation fails, because it is trying to create a Variant that already exists?

 

Should I delete this Variant before continuing? Is there a way to specify if a variant should exist in the productCreate call?

 

Thanks.

Accepted Solution (1)

daveluke
Shopify Partner
25 2 10

This is an accepted solution.

Found the answer, use the strategy input set to REMOVE_STANDALONE_VARIANT here:

 

https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productVariantsBulkCreate

View solution in original post

Replies 2 (2)

daveluke
Shopify Partner
25 2 10

This is an accepted solution.

Found the answer, use the strategy input set to REMOVE_STANDALONE_VARIANT here:

 

https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productVariantsBulkCreate

BalloutMohamad
Shopify Partner
7 0 0

Can you please show me the graphql code, I am trying to create a product with multiple variants but I am stuck at the moment. Thank you