I’m currently experimenting ways to optimize cost in our API that creates Shopify products externally.
I’m looking at the productOptionsCreate mutation but as I experimented on it by adding an option with multiple values, it creates the optionValues successfully, but when I look at options.values it only contains the first created option.
e.g.
I use productOptionsCreate to create an option named Size and add S, M, and L as values
Is this a bug? Or does this mean I have to manually add the other options to the options.values field? That seems too much of a hassle and a waste of another call…
Hey folks - from digging into this, it does seem that this is not a bug, but an intentional way that the API is set up. When creating a product option with multiple values, the optionValues field will correctly list all the values you specified, but the values field only includes the first value.
Only the first value per option is used to create a single default variant, and in your case that single variant is something like Rosso / S / Regular. Other values (Blu, L, Slim, Tailored) exist as potential option values but no variants use them yet, so they don’t appear in options.values; they would appear under optionValues if you requested that field.
When you pass productOptions into productCreate, You’re defining the set of possible option values per option. Shopify then creates one default variant using the first value of each option:
Colore = Rosso
Taglia = S
Fit = Regular
It does not automatically create all combinations of variants (e.g., Rosso / S / Slim, Blu / L / Tailored, etc.). That’s why you only see the first value on the admin and in options.values: those are the values currently in use by at least one variant.
If you want to verify that all your values (e.g. Blu, L, Slim, Tailored) are registered as possible values on the product, you should query optionValues as well as values.
Here is a validated query you can run to inspect the product’s options after creation:
query ProductOptionsAndVariants($id: ID!) {
product(id: $id) {
id
options {
name
values
optionValues {
name
hasVariants
}
}
variants(first: 10) {
nodes {
id
title
selectedOptions {
name
value
}
}
}
}
}
It sounds like you want to have all combinations of those options as variants, so you’ll need to explicitly create the variants yourself. There are two common approaches:
Create the product with options only, then use a separate mutation to add variants (e.g., productVariantsBulkCreate).
Or, create the product first, then call productOptionsCreate etc. if you’re doing more advanced option management.