productVariantsBulkCreate "message":"Option does not exist"

Solved

productVariantsBulkCreate "message":"Option does not exist"

LaytonBerth
Tourist
8 1 5

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.

Accepted Solutions (2)

BSSCommerce-B2B
Shopify Partner
1425 397 458

This is an accepted solution.

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! 

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

View solution in original post

LaytonBerth
Tourist
8 1 5

This is an accepted solution.

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). 

View solution in original post

Replies 2 (2)

BSSCommerce-B2B
Shopify Partner
1425 397 458

This is an accepted solution.

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! 

B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.


B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.


B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.


BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now

LaytonBerth
Tourist
8 1 5

This is an accepted solution.

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).