Problem in updating Products and variants through API in Shopify
Shopify provides a cloud platform for e-commerce business. While using Shopify to setup online ecommerce for a reputed industry we found a strange issue which gave us lot of trouble in finding out the root cause. Let us look at the problem in updating Products and variants through API in Shopify and then we move towards the solution of it.
We were asked by our client to integrate the Shopify Products with an ERP. We wanted to use our own application APPSeCONNECT which has a generic solution to send batched set of product to Shopify Cloud solution so that when any product gets updated in the ERP we get the same product updated into Shopify. APPSeCONNECT allows mapping data between two types of heterogeneous environment at an interval and generates an XML file which needs to be updated. But while updating the product with all its variants we see an unexpected result.
We send the data as under:
The process didn’t work and it throws “Unprocessable entry” and the details say “product variant and option are not unique” even though there aren’t any duplicate product in the batch. This seems to us as a Bug in Shopify and we were desperate to find a solution.
During trial and error when we send the product without variant, the same endpoint does consume the xml correctly. For instance, if we send:
Here in the xml you can see the Product gets updated but with the Variants it doesn’t.
As we got the product updated successfully, we use a separate API to update the Variants too. We use https://xxxx.myshopify.com/admin/variants.xml to update the Variants and thank god, Shopify does update the Variants too successfully.
So the solution is to update the Variant and the Product separately and the process works like champ.
We hope the solution helps.