The remote server returned an error: (422) Unprocessable Entity.

Solved
pujaparekh
New Member
7 0 0

hi there,

I  get "The remote server returned an error: (422) Unprocessable Entity."  error when am I try to add a new product using API.

I am posting below json to the url https://xxx:yyy@myshopname.myshopify.com/admin/api/2020-04/products.json 

also Response.Header["X-Request-Id"] is null when i run into this exception. Could anyone please help ?

 

 

{

"product":{
"title":"AU*Mini button",
"vendor":"EverUgg",
"variants":[
{
"option1":"Chestnut",
"option2":"L10",
"sku":"12702-/Chestnut/L10",
"price":"171.6",
"barcode":"9349788033161",
"compare_at_price":"155"
},
{
"option1":"Chestnut",
"option2":"L11",
"sku":"12702-/Chestnut/L11",
"price":"171.6",
"barcode":"9349788033178",
"compare_at_price":"155"
},
{
"option1":"Chocolate",
"option2":"L10",
"sku":"12702-/Chocolate/L10",
"price":"171.6",
"barcode":"9349788033185",
"compare_at_price":"155"
},
{
"option1":"Chocolate",
"option2":"L11",
"sku":"12702-/Chocolate/L11",
"price":"171.6",
"barcode":"9349788033192",
"compare_at_price":"155"
}
],
"options":[
{
"name":"Color",
"values":[
"Chestnut",
"Chocolate"
]
},
{
"name":"Size",
"values":[
"L10",
"L11"
]
}
]
}
}

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 221

When I run into situations like this I try to cull out things to make the API request simpler. Can you create the product, without the variants and their options? If so, then I would recommend first creating the product via an API request. Then once you get a product ID back in the response you can reference that in a second API request, creating the variants with their options. I think that's what I had to resort to when creating new products.

pujaparekh
New Member
7 0 0

I have .net windows application which i use to add new products to shopify. I have been using the same code to add new products and its variants at the same time and it works fine. But I get this error particularly when i add this product and its variant. Its very strange. I need to find out the reason for getting this error. 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 221

Maybe it's an illegal character somewhere. Perhaps the forward slashes in the SKU's?

0 Likes
_JB
Shopify Staff
Shopify Staff
761 89 170

This is an accepted solution.

Hey @pujaparekh,

Maybe it's an illegal character somewhere. Perhaps the forward slashes in the SKU's?

This is my best guess as well. Try removing any characters in your fields that aren't `A-Z` and `0-9` and send the request again. If it's still not working, try making the request using an HTTP client like Insomnia. If the request also fails in Insomnia, please take another look for the request_id, or provide a specific timestamp for when you made the call, along with the IP address you made the call from. I can use this info to check our logs and see what the request looks like from our end.

JB | 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

0 Likes
pujaparekh
New Member
7 0 0

Guess what? It turns out that my compare at price was lower than retail price.

thanks for answering. I checked the response using insomnia and it gave me the correct error which i was not able to get in visual studio.

may be it will help other users. Btw, also found out that price should NOT have more than 2 decimal places. 

 

0 Likes
Greg_Kujawa
Shopify Partner
1016 83 221

Good catch! I didn't notice that the Compare At prices were actually lower than the regular prices. Makes sense why the 422 error was returned, since that broke the app's business logic.

0 Likes