ProductSet - GraphQL API (2025-04)

Hi, I’m in need of some clarification on whether it’s possible to manage a product’s default variant price, barcode, and SKU using the ProductSet mutator.

I have successfully added a product without this information, but I’m struggling to add one with the mentioned fields without having to add a variant.

Working example (adds custom variant named “Default”):

$variables = [
    'input' => [
        'title' => $title,
        'descriptionHtml' => $descriptionHtml,
        'metafields' => [
            [
                "key" => "general_information",
                "value" => "test 99",
                "type" => "string",
                "namespace" => "custom_fields"
            ],
            [
                "key" => "directions",
                "value" => "test 99",
                "type" => "string",
                "namespace" => "custom_fields"
            ],
            [
                "key" => "ingredients",
                "value" => "test 3",
                "type" => "string",
                "namespace" => "custom_fields"
            ],
            [
                "key" => "warnings",
                "value" => "test 4",
                "type" => "string",
                "namespace" => "custom_fields"
            ]
        ],
        'tags' => explode(',', $tags),
        'vendor' => $vendor,
        'productType' => $productType,
        'status' => strtoupper($status),
        // Minimal productOptions to satisfy Shopify's requirements
        'productOptions' => [
            [
                'name' => 'Default', // Placeholder name for the product option
                'position' => 1, // Option position
                'values' => [
                    [
                        'name' => 'Default' // Placeholder value
                    ]
                ]
            ]
        ],
        'variants' => [
            [
                'price' => $price, // Assign the price
                'sku' => $sku, // Assign the SKU
                'barcode' => $barcode, // Assign the barcode
                'inventoryPolicy' => $ignoreStockLevels === 'continue' ? 'CONTINUE' : 'DENY',
                // Minimal optionValues to match productOptions
                'optionValues' => [
                    [
                        'optionName' => 'Default', // Matches the productOptions name
                        'name' => 'Default' // Matches the productOptions value
                    ]
                ]
            ]
        ]
    ],
    'synchronous' => true
];

Example which does not work (Attempting to add field data without explicit / creation of a custom variant):

$variables = [
    'input' => [
        'title' => $title,
        'descriptionHtml' => $descriptionHtml,
        'metafields' => [
            [
                "key" => "general_information",
                "value" => "test 99",
                "type" => "string",
                "namespace" => "custom_fields"
            ],
            [
                "key" => "directions",
                "value" => "test 99",
                "type" => "string",
                "namespace" => "custom_fields"
            ],
            [
                "key" => "ingredients",
                "value" => "test 3",
                "type" => "string",
                "namespace" => "custom_fields"
            ],
            [
                "key" => "warnings",
                "value" => "test 4",
                "type" => "string",
                "namespace" => "custom_fields"
            ]
        ],
        'tags' => explode(',', $tags),
        'vendor' => $vendor,
        'productType' => $productType,
        'status' => strtoupper($status),
        'variants' => [
            [
                'price' => $price, // Assign the price
                'sku' => $sku, // Assign the SKU
                'barcode' => $barcode, // Assign the barcode
                'inventoryPolicy' => $ignoreStockLevels === 'continue' ? 'CONTINUE' : 'DENY'
            ]
        ]
    ],
    'synchronous' => true
];

Throws Error: Variable $input of type ProductSetInput! was provided invalid value for variants.0.optionValues (Expected value to not be null)

I believe that either this development feature is still needed or it simply doesn’t exist, requiring us to use a different mutator. However, the documentation states that the mutators can both add and modify products. Therefore, it’s reasonable to assume that updating SKU, barcode, and price—which are essential fields for commerce—should be possible. Any ideas?

Thank-you!

Ref: productSet - GraphQL Admin

SOLVED:
Resolution is within the naming conventions for the set variant details.
After digging around in the forums I found the solution (Re: Create products without variant/options using productSet - Shopify Community)

Essentially during your ProductSet mutation variable passing it is required to assign a variant manually but using the following:

'productOptions' => [
            [
                'name' => 'Title', // Placeholder name for the product option
                'position' => 1, // Option position
                'values' => [
                    [
                        'name' => 'Default Title'
                    ]
                ]
            ]
        ],
'variants' => [
            [
                'optionValues' => [
                    [
                        'optionName' => 'Title', // Matches the productOptions name
                        'name' => 'Default Title' // Matches the productOptions value
                    ]
                ]

I hope this also helps others running into this issue.

1 Like

Hi Jake,

Great to hear you’ve figured this out and thanks for coming back to post your solution :slight_smile: Let us know if you have any other questions!