productVariantsBulkCreate "message":"Option does not exist"

I try to run this query:

$query = <<<QUERY
            mutation productVariantsBulkCreate(\$productId: ID!, \$variants: [ProductVariantsBulkInput!]!) {
                productVariantsBulkCreate(productId: \$productId, variants: \$variants) {
                    productVariants {
                        id
                        inventoryItem {
                            id
                        }
                    }
                        userErrors {
                        field
                        message
                    }
                }
            }
        QUERY;

        $variables = [
            "productId" => $productParentId,
            "strategy" => "REMOVE_STANDALONE_VARIANT",
            "variants" => [
                "price" => $requestBodyData['price'],
                "barcode" => $productVariant->ean,
                "taxable" => true,
                "inventoryPolicy" => "DENY",
                "inventoryItem" => [
                    "sku" => $productVariant->ean,
                    "tracked" => true,
                    "cost" => $productVariant->unit_cost,
                    "measurement" => [
                        "weight" => [
                            "unit" => "GRAMS",
                            "value" => $productVariant->weight
                        ]
                    ]
                ],
                "inventoryQuantities" => [
                    [
                        "availableQuantity" => $requestBodyData['stock'],
                        "locationId" => "gid://shopify/Location/" . ShopifyService::LOCATION
                    ]
                ],
                "optionValues" => [
                    [
                        "name" => "Red",
                        "optionName" => "Color",
                    ],
                    [
                        "name" => "Large",
                        "optionName" => "Size",
                    ]
                ]
            ]
        ];

It returns this error: “message”:“Option does not exist”

Contacted support but they didn’t know the problem.

Hi @LaytonBerth ,

I think the Color or Size option does not exist in your product with the id “$productParentId”.

Hope you find out how to fix it soon! Have a great day bro!

Exactly… Apparently which is very weird in my opinion, I had to first define all the POSSIBLE options I will ever have on the product (createProduct mutation with options field) and then you can use those options you defined in the ‘productVariantsBulkCreate’ mutation.

What is also very weird is that the strategy REMOVE_STANDALONE_VARIANT is not working and still creates a variant for the first options you defined (for example, small / black).