title: Shopify product creation 422: "You need to add option values for [option name]"
body: <p><strong>Update:</strong> Solved. A coding mistake caused the <code>variants</code> to be wrapped in an additional list, yielding a syntactically valid but semantically invalid (for Shopify) JSON object.</p>
  
  <hr>
  
  <p>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.</p>
  
  <p>The relevant portion of the JSON I'm POSTing is below: </p>
  
  <pre><code>"options":[
    {
       "position":1,
       "name":"Style"
    },
    {
       "position":2,
       "name":"Size"
    },
    {
       "position":3,
       "name":"Color"
    } 
  </code></pre>
  
  <p>Each variant looks something like this:</p>
  
  <pre><code>{
      "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"
   },
  </code></pre>
  
  <p><a href="http://pastebin.com/VzUegWce" rel="nofollow noreferrer">Here's a link to the entire JSON I'm attempting to POST.</a></p>
  
  <p>When I POST this JSON to <code>https://STORE_NAME.myshopify.com/admin/products.json</code>, I receive an 422 status code and the following error message:</p>
  
  <p><code>{'errors': {'base': ['You need to add option values for Size', 'You need to add option values for Color']}}</code></p>
  
  <p>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.</p>
  
  <hr>
  
  <p>Here's how I got to where I am:</p>
  
  <ul>
  <li>Trying to POST without the <code>"options"</code> entry in the dictionary gave me an error in the form of <code>'The variant 'Men's Premium T-Shirt' already exists'</code>; researching this led me to introduce the <code>"options"</code> entry.</li>
  <li>I started out with just <code>"options": {"name": "Style", "name": "Color", "name": "Size"}</code>, but this created a product with only one variant - "Default Title". </li>
  <li>Deleting the Style option gives me an error message about just Color. Deleting Size as well creates the one-variant "Default Title" product.</li>
  </ul>
  
  <p>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 <code>Shopify "You have to add option values for"</code> returns exactly 0 hits with the quotes intact.</p>
  
  <p>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" <a href="https://help.shopify.com/api/reference/product#create" rel="nofollow noreferrer">here</a> - but people on Shopify's API forums and elsewhere indicate that it's absolutely necessary.</p>
  
  <p>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.</p>