2024-07 Products API Registering Only A Single Option Value

Starting with the 2024-04 API, Shopify significantly changed the products API and how the variants are handled. I am trying to create product through the GraphQL API that has 2 variants and each variant has 4 values. With the separation of the API into multiple pieces, it became very confusing what is what. I tried all of them and none of them work. I will summarize my attempts below:

1) Use the productOptionsCreate mutation.

My query:

mutation createOptions($productId: ID!, $options: [OptionCreateInput!]!) {
            productOptionsCreate(productId: $productId, options: $options) {
            userErrors {
                field
                message
                code
            }
            product {
                id
                variants(first: 5) {
                nodes {
                    id
                    title
                    selectedOptions {
                    name
                    value
                    }
                }
                }
                options {
                id
                name
                values
                position
                optionValues {
                    id
                    name
                    hasVariants
                }
                }
            }
            }
        }

With

{
        variables: {
            productId: responseJson.data.productCreate.product.id,
            options: [ 
                  {
                     name: 'broken cloud',
                     values: [ {name: 'HOB'}, {name: ...}, {name: ...}, {name: ...} ]
                  },
                  {
                     name: 'hidden dawn',
                     values: [{name: 'HOB'}, {name: ...}, {name: ...}, {name: ...} ]
                 }
            ]
        }
    }

The query succeeds but it only registers a single value. See screenshot below

For what is worth, I also tried taking the example query in the mutations docs, only changing the product id to a valid id in my test store and I get the same result. Example query doesn’t work

The example submits two colors (red & blue) and two sizes (small & medium) but on the product page, I only see one each. Screenshot:

2) Use the productVariantsBulkCreate mutation.

This straight up doesn’t work since optionValues field doesn’t seem fit to handle cases like this.

3) Use the productOptions field in the productCreate mutation

This results in the same outcome as #1 with only a single value being registered.

What is the right way of registering multiple option values under the new API? Any help would be appreciated

Hi @sinanspd

你可以检查一下你的options 数据,如图,hasVariants: true 可以展示在shopify admin

Hi @Kyle_liu

How do you set hasVariants ? On the docs (https://shopify.dev/docs/api/admin-graphql/unstable/mutations/productOptionsCreate?example=Create+new+product+options#top), the input doesn’t seem to have the field to set that?

Hi @sinanspd

You can use productVariantsBulkUpdate, where variables ->optionValues ->opitonsId corresponds to the id of hasVariants data