Product creation 422: "You need to add option values for [option_name]"

Jackson_Humphre
New Member
1 0 0

I'm trying to create a product 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":[
  {
     "values":[
        "Men's Premium T-Shirt",
        "Women's Premium T-Shirt", // etc
     ],
     "position":1,
     "name":"Style"
  },
  {
     "values":[
        "S",
        "M",
        "L",
        "etc"
     ],
     "position":2,
     "name":"Size"
  },
  {
     "values":[
        "Forest Green"
     ],
     "position":3,
     "name":"Color"
  } 

(The only value provided to the "Color" option is "Forest Green" because that's the only color that appears across all this product's variants.)

Each variant looks something like this:

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

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".
  • I get the same error message even if I remove the "values" entries from the options objects.
  • 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.

Thanks for your time and attention.

Replies 7 (7)
Jordan
Shopify Staff
Shopify Staff
300 3 74

Hey Jackson!

I can definitely take a look, but can you provide me with the full request body so I can attempt to replicate and correct the issue? Maybe in a Gist?

 

- Jordan

Jordan | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Rahul_Yadav1
New Member
3 0 0
Hi, 

I am sending the Following as Array to shopify and I am getting the same above error:

------------------------------------------------------------------------------------------------------------------------

Array ( [product] => Array ( [title] => White Walker Whiskey - GOT Shirt [body_html] => Custom Ultra Cotton T-Shirt: 6.1-ounce, 100% cotton Double-needle neck, sleeves and hem; Roomy Unisex Fit Ash is 99% cotton, 1% poly; Sport Grey is 90% cotton, 10% poly; Dark Heather is 50% cotton, 50% polyester Decoration type: Digital Print or Screen Print (based on design & quantity) Made by Gildan® LS Ultra Cotton Tshirt: 6.1-ounce, 100% cotton Ash is 99% cotton, 1% poly; Sport Grey is 90% cotton, 10% poly; Dark Heather is 50% cotton, 50% polyester Double-needle neck, sleeves and hem; Unisex sizing; consult size chart for details Decoration type: Digital Print or Screen Print (based on design & quantity) Made by Gildan® Pullover Hoodie 8 oz: 8 oz 50/50 cotton/poly Air jet yarn creates a smooth, low-pill surface Double needle stitching; Pouch pocket; Unisex sizing Decoration type: Digital Print or Screen Print (based on design & quantity) Made by Gildan 100% Cotton Tank Top: 100% cotton Banded neck and armholes; Double-needle hem Ash Grey is 99% cotton, 1% polyester, Sport Grey is 90% cotton, 10% polyester Decoration type: Digital Print or Screen Print (based on design & quantity) Made by Gildan® [vendor] => Default [product_type] => Default [variants] => Array ( [0] => Array ( [option1] => Default [price] => 2389 [sku] => 6410896390 ) ) [options] => Array ( [0] => Array ( [name] => Color [position] => 1 [values] => Array ( [0] => Red [1] => Yellow [2] => Black ) ) [1] => Array ( [name] => Size [position] => 2 [values] => Array ( [0] => Small [1] => MEdium [2] => X Large ) ) ) [published] => 1 [metafields] => Array ( [0] => Array ( [key] => custom [value] => true [value_type] => string [namespace] => google ) [1] => Array ( [key] => condition [value] => new [value_type] => string [namespace] => google ) [2] => Array ( [key] => google_product_type [value] => Apparel a Accessories > Clothing [value_type] => string [namespace] => google ) [3] => Array ( [key] => gender [value] => unisex [value_type] => string [namespace] => google ) [4] => Array ( [key] => age_group [value] => adult [value_type] => string [namespace] => google ) ) [images] => Array ( [0] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_4a0885f6-a085-47da-ae6a-e11... ) [1] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_b14bce4a-d19c-44fe-99fa-29f... ) [2] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_35e797d7-6af7-4451-bcc2-658... ) [3] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_2937a977-68ec-4bb3-b6f8-d4f... ) [4] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_ac4070b2-acd0-43c6-9f89-899... ) [5] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_c50e80a2-cec4-465f-ab08-a9f... ) [6] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_78b05e76-fe3c-43e8-8da4-bc2... ) [7] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_b69385ce-8391-4519-a60c-6b0... ) [8] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_545b2409-674e-4b00-a252-50f... ) [9] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_d282c02d-7fb5-4be8-af01-aac... ) [10] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_9f38f63b-0404-4d3b-b574-709... ) [11] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_c1f9426c-4d82-47c9-9959-ea7... ) [12] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_4a0885f6-a085-47da-ae6a-e11... ) [13] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_7321946c-7468-445c-99f4-511... ) [14] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_5eec20b1-c427-421e-9b40-a9c... ) [15] => Array ( [src] => https://cdn.shopify.com/s/files/1/1297/4713/products/DynamicImageHandler_eb5fbd86-06ac-45d8-a11c-825... ) ) ) )

------------------------------------------------------------------------------------------------------------------------

 

Rahul_Yadav1
New Member
3 0 0

Here is Full Screenshot for it :

Lowmips_com__LL
Shopify Partner
1 0 1

Did you ever get a fix for this issue? I am having a similar one.

Matthias_Dierbe
Shopify Partner
4 0 1

I'm getting the same problem. Apparently it works if I create the options and the variations at the same time but I would like to create the product first and add variations later.

hussnainsheikh1
Shopify Partner
4 0 1

Does anyone get this fixed? I am facing the same issue. Thanks

 

{"product":{"variants":[{"option1":"Digital Proof","price":"18.75","cost":"15","sku":"4064445F-8783-435D-8D15-07029147D088","inventory_policy":"deny","inventory_management":"shopify","inventory_quantity":5},{"option1":"Art Time","price":"75","cost":"60","sku":"DA24EA46-9BBB-4B4A-8AA0-6030E5EA6105","inventory_policy":"deny","inventory_management":"shopify","inventory_quantity":5},{"option1":"Domestic Drop Ship","price":"6.25","cost":"5","sku":"41818C20-E1F5-4898-A899-4374109BBEB0","inventory_policy":"deny","inventory_management":"shopify","inventory_quantity":5},{"option1":"International Drop Ship","price":"18.75","cost":"15","sku":"D6C4FE07-5824-46A8-A30A-DE1ADCB849CD","inventory_policy":"deny","inventory_management":"shopify","inventory_quantity":5},{"option1":"White","price":1,"cost":1,"sku":"32BF9A8F-49A0-4B92-B76A-B5001FEBAF38","inventory_policy":"deny","inventory_management":"shopify","inventory_quantity":5}],"images":[{"src":"https:\/\/s3.distributorcentral.com\/uploads\/E\/2\/E29E512594AE694DC05593FD66F364A9.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/C\/E\/CEFC802ACDC47451003C7388E989FC3D.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/A\/5\/A58B857DEE2B933CC05B509FC022D10A.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/B\/2\/B2C9AF8DD5E219B0CC5E3D169C255AA4.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/A\/6\/A6F253F3F0269ECA125959DBE89F1B80.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/3\/F\/3F191E77ADCB2B3D594AEB037FC5685D.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/0\/6\/0609DCFBC15E444C939421D248138A36.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/5\/C\/5C707EF50E09A308847BC53BB0D24A2B.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/D\/B\/DB6FD2FB317FD86BBCC335B638FDABBE.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/1\/8\/18D4D13870ADA820E37C2EED1A5141FB.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/F\/6\/F65EF2176CDBD1CA075E495AB699F2B5.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/F\/B\/FBB316DA2B95FEF98A07CD4DC1056524.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/3\/F\/3F7503A5ED1CF8132E86080A8FE40DFD.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/3\/7\/370B41B68BCAA3BA4D64D3D2EA05A36A.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/3\/1\/318FB162791B9C4719D82BB0657FA163.jpg"},{"src":"https:\/\/s3.distributorcentral.com\/uploads\/C\/9\/C9F55BC4A7A4B75A02DAF54FCC107DE3.jpg"}],"title":"Biggie Powerbank","body_html":"<div>The Biggie is a compact 20,000 mAH power bank. The LED light indicator shows the remaining life to ensure you are aware of the available power. The Biggie comes with built-in Type- C and micro input ports as well as USB and Type- C output ports. With a sleek and compact design, it makes it easy to hold and carry.<br><br><br><b>Material<\/b><br><ul><li>ABS Plastic<\/li><\/ul><br><b>Imprint Methods Available<\/b><ul><li><b>Standard:<\/b> Full Color Direct to Substrate<\/li><\/ul><br><b>Imprint Size<\/b><ul><li><b>Standard:<\/b> 2 5\/8\" W x 4 7\/8\" H Face<\/li><\/ul><br><b>Standard Packaging<\/b><ul><li>Box<\/li><\/ul>Tags: Charger, Charging, Cell Phone, Cell, Mobile, Tablet, Power, Travel, Portable, Tech, Technology, Iphone, Ipad, Android, Microsoft, Universal, Gift, Retail, Trade Show, Give Away<\/div><br>20,000 mAH power bank<br>LED indicator lights for power level<br>90 hrs. of smartphone charging<br>Size: 2 3\/4\" W x 5  1\/32\" L x 1  1\/32\" H","vendor":"HandStands - HPG Brands","product_type":"Travel Accessories","options":[{"name":"Proofing","position":1,"values":["Digital Proof","Art Time"]},{"name":"Drop Shipments","position":2,"values":["Domestic Drop Ship","International Drop Ship"]},{"name":"15220 Colors Available","position":3,"values":["White"]}]}}

Here is my JSON. Please check and let me know. Thank you!

onets
New Member
1 0 0

Hi, when I am tring to update product and variants - I am getting 422 You need to add option values for Size

PUT https://***.myshopify.com/admin/api/2020-10/products/7267343073468.json HTTP/1.1
Host: ***.myshopify.com
X-Shopify-Access-Token: shppa_***
Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml
User-Agent: RestSharp/106.12.0.0
Connection: Keep-Alive
Accept-Encoding: gzip, deflate
Content-Type: application/json
Content-Length: 636

{"product":{"title":"Prod 01","variants":[{"sku":"PR01S","price":15.0,"option1":"Prod 01 S","barcode":"1234567891","id":41174079897788},{"sku":"PR01M","price":15.0,"option1":"Prod 01 M","barcode":"1234567892","id":41174079930556},{"sku":"PR01L","price":15.0,"option1":"Prod 01 L","barcode":"1234567893","id":41174079963324},{"sku":"PR01XL","price":15.0,"option1":"Prod 01 XL","option2":"XL","barcode":"123456784"}],"options":[{"product_id":7267343073468,"name":"Title","position":1,"values":["Prod 01 S","Prod 01 M","Prod 01 L","Prod 01 XL"]},{"product_id":7267343073468,"name":"Size","position":2,"values":["XL"]}],"id":7267343073468}}

 

HTTP/1.1 422 Unprocessable Entity
{"errors":{"base":["You need to add option values for Size"]}}

 

but my request json contains size option {"product_id":7267343073468,"name":"Size","position":2,"values":["XL"]}

What is going wrong, could you help please?