2024-07 Products API Registering Only A Single Option Value

Solved

2024-07 Products API Registering Only A Single Option Value

sinanspd
Shopify Partner
4 0 1

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 

 

Screenshot 2024-08-29 at 1.59.14 AM.png

 

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:

 

Screenshot 2024-08-29 at 2.01.13 AM.png

 

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

Accepted Solution (1)

Kyle_liu
Shopify Partner
171 24 27

This is an accepted solution.

Hi @sinanspd 

 

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

Kyle_liu_1-1725341724129.png

 

 

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me on (liushuaicc@shinetechsoftware.com)

View solution in original post

Replies 3 (3)

Kyle_liu
Shopify Partner
171 24 27

This is an accepted solution.

Hi @sinanspd 

 

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

Kyle_liu_1-1725341724129.png

 

 

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me on (liushuaicc@shinetechsoftware.com)
sinanspd
Shopify Partner
4 0 1

Hi @Kyle_liu 

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

Kyle_liu
Shopify Partner
171 24 27

Hi@sinanspd 

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

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me on (liushuaicc@shinetechsoftware.com)