Ad

Shopify Product Creation 422: "You Need To Add Option Values For [option Name]"

- 1 answer

Update: Solved. A coding mistake caused the variants to be wrapped in an additional list, yielding a syntactically valid but semantically invalid (for Shopify) JSON object.


I'm trying to create a product on Shopify with multiple options and multiple variants. Everything's going well, except that I'm being tripped up at the product options.

The relevant portion of the JSON I'm POSTing is below:

"options":[
  {
     "position":1,
     "name":"Style"
  },
  {
     "position":2,
     "name":"Size"
  },
  {
     "position":3,
     "name":"Color"
  } 

Each variant looks something like this:

{
    "price":"##.##",
    "option2":"S",
    "compare_at_price":"##",
    "weight_unit":"lb",
    "option3":"Black",
    "old_inventory_quantity":1,
    "option1":"Men's Premium T-Shirt",
    "inventory_management":null,
    "weight":0.0,
    "title":"Men's Premium T-Shirt / S / Black",
    "requires_shipping":true,
    "inventory_quantity":1,
    "fulfillment_service":"manual"
 },

Here's a link to the entire JSON I'm attempting to POST.

When I POST this JSON to https://STORE_NAME.myshopify.com/admin/products.json, I receive an 422 status code and the following error message:

{'errors': {'base': ['You need to add option values for Size', 'You need to add option values for Color']}}

I'm not sure what's wrong with the JSON I'm sending, and I'd appreciate some advice or a pointer in the right direction.


Here's how I got to where I am:

  • Trying to POST without the "options" entry in the dictionary gave me an error in the form of 'The variant 'Men's Premium T-Shirt' already exists'; researching this led me to introduce the "options" entry.
  • I started out with just "options": {"name": "Style", "name": "Color", "name": "Size"}, but this created a product with only one variant - "Default Title".
  • Deleting the Style option gives me an error message about just Color. Deleting Size as well creates the one-variant "Default Title" product.

That last point especially makes me suspect some kind of syntax error - something with the bracketing where the first option doesn't get closed properly, reads the next two options as its option values, and then the next two are left out in the cold. But I've ran this JSON through parsers and formatters, and it seems to check out. Additionally, Googling for Shopify "You have to add option values for" returns exactly 0 hits with the quotes intact.

The icing on the cake is that Shopify's official documentation doesn't even seem to necessitate the "options" block - see "Create a new product with multiple product variants" here - but people on Shopify's API forums and elsewhere indicate that it's absolutely necessary.

I feel like I'm making a simple error here, but for the life of me I can't find it. Any pointers would be extremely appreciated.

Ad

Answer

Is it possible that one of the variants is missing the option3 or the options2 property? Here is a minimal example of a product with numerous options:

{
    "product": {
        "title": "Cool shirt",
        "variants": [{
            "price": "4.00",
            "option1": "big",
            "option2": "mauve"
        }, {
            "price": "2.00",
            "option1": "big",
            "option2": "iridescent"
        }, {
            "price": "5.00",
            "option1": "small",
            "option2": "mauve"
        }, {
            "price": "1.00",
            "option1": "small",
            "option2": "iridescent"
        }],
        "options": [{
            "name": "Size",
            "position": 1
        }, {
            "name": "Color",
            "position": 2
        }]
    }
}

Edit: Thanks for posting the sample. You should send the product data within a {"product": ... } object. Also, it looks like the variant data in your sample has too many brackets around it. Try including the variants in just one set of square brackets like in my example.

Ad
source: stackoverflow.com
Ad