PROBLEM with « Create a new product with multiple product variants and multiple options »

Solved
Tourist
5 0 1

When I'm trying to create a product with multiple variants and options

POST /admin/api/#{api_version}/products.json

I always get this error message: « The remote server returned an error: (422) Unprocessable Entity. »

 

I have no problem with all the other calls, only with this one. I need help!

 

Thanks in advance

0 Likes
Shopify Staff
Shopify Staff
469 36 94

This is most likely due to the request being formatted incorrectly.  Make sure you are following the format available in our API reference.  For more assistance we would need the X-Request-ID response returned from Shopify or the body of the POST call you are making.

Developer Experience @ Shopify
0 Likes
Tourist
5 0 1

I'm using the example in help.shopify.com!

 

POST /admin/api/#{api_version}/products.json
{
  "product": {
    "title": "Burton Custom Freestyle 151",
    "body_html": "<strong>Good snowboard!</strong>",
    "vendor": "Burton",
    "product_type": "Snowboard",
    "variants": [
      {
        "option1": "Blue",
        "option2": "155"
      },
      {
        "option1": "Black",
        "option2": "159"
      }
    ],
    "options": [
      {
        "name": "Color",
        "values": [
          "Blue",
          "Black"
        ]
      },
      {
        "name": "Size",
        "values": [
          "155",
          "159"
        ]
      }
    ]
  }
}

 

The only thing I changed is the « vendor ». I changed it for mine. 

0 Likes
Shopify Staff
Shopify Staff
469 36 94

Can you provide the X-Request-ID you get as a response in the header? Assuming you copied the formatting correctly there is no issue with that call and I am able to create it.  Did you update the URL to include an actual version instead of #{api_version}?

POST /admin/api/#{api_version}/products.json

 

 Ryan

 

 

Developer Experience @ Shopify
0 Likes
Tourist
5 0 1

Yes I did change the #{api_version} to 2019-07.. I'm not that stupid!

 

Here's my full request:

https://xxxxx:yyyyy@zzzzzz.myshopify.com/admin/api/2019-07/products.json

 

{
"product": {
"title": "Burton Custom Freestyle 151",
"body_html": "<strong>Good snowboard!</strong>",
"vendor": "PremiceSoft-Test",
"variants": [
{
"option1": "Blue",
"option2": "155"
},
{
"option1": "Black",
"option2": "159"
}
],
"options": [
{
"name": "Color",
"values": [
"Blue",
"Black"
]
},
{
"name": "Size",
"values": [
"155",
"159"
]
}
]
}
}

 

And the response:

<html>

<body>
  <noscript>
    <a
  </noscript>

  <script type="text/javascript">
    window.location = "https:\/\/app.shopify.com\/services\/login\/identity?destination_uuid=3e07f64f-671c-4124-917d-8cdc61272c00&return_to=https%3A%2F%2Fapp.shopify.com%2Fservices%2Flogin%2Fidentity_callback%3Fshop_name%3DPremicesoft-test%26state%3DiaM09JSHlmfiXajjAmhLQfAYGusY0CEl4712QesDUjD-RB4Iux5ByTfszsoESrNDUIn1qUjQFB--TZDwUlyuLISu4ovOZpr51PIsB_iUjQxUdOEbYW94Kx9gomJOqknE1ne0bnbdLw3BYMa0U5NGWWENmUfFmMtL88B8uevw-v-si-YUuAz3T2UARrIrz4qM3EQaYh0UUGxWkG3MMm9F_uoXvdYlgQpy1GYt1QNj-fQ%253D&ui_locales=en&upgradeable=false&ux=shop";
  </script>
</body>

</html>

 

 

 

0 Likes

Success.

Shopify Staff
Shopify Staff
469 36 94

I edited your post to take out the private key, will take a look at your request in the logs to see if I can find any issues.

 

Edit; the issue is that you are sending cookies with your request.  Shopify doesn't accept post requests that include cookies.  If you remove these from the request it should work.

Developer Experience @ Shopify
0 Likes
Tourist
5 0 1

It works! Thanks for your help!

1 Like
Shopify Staff
Shopify Staff
469 36 94

No problem.  Any time you see an HTML response like you mentioned as the return, the first thing I would check is if cookies are being sent!

Developer Experience @ Shopify
0 Likes
Tourist
5 0 1

Perfect! Thanks!

0 Likes
Highlighted
New Member
1 0 0

hello there, would you please post the full code for the POST request you have made !?

I'm struggling with the same issue you had,  thanks 

0 Likes