Shopify API not saving all variants changes in single request

313 views
Skip to first unread message

Prashant Bhure

unread,
Sep 20, 2012, 3:38:19 AM9/20/12
to shopify-a...@googlegroups.com
Hi,

I have a product in a shopify shop with 36 variants.
Now this product is on sale and I wanted to change the price of all the variants.
But sending the request to update the product "PUT /admin/products/#{id}.xml", which includes the request xml having all the variant changed price, doesn't work.
<?xml version="1.0" encoding="UTF-8"?>
<product> 
<id type="integer">104977489</id>
<variant> 
<id type="integer">241280165</id> 
<option1>Large</option1> 
<option2>Blue</option2> 
<option3>Bears</option3> 
<sku>25000-030201</sku> 
<price>85.00</price>
<inventory-quantity type="integer">20</inventory-quantity> 
<inventory-management>shopify</inventory-management> 
<inventory-policy>deny</inventory-policy> 
<requires-shipping type="boolean">true</requires-shipping> 
<taxable type="boolean">true</taxable> 
</variant>
<variant>  
</variant> 
3
4
.
.
35
<variant>  
</variant> 
</product>

For this I have to update each variant separately using "PUT /admin/variants/#{id}.xml" request. 

This results in performance issue as the application has to send request  36 times.
I just wanted to know if there is any way so that this could be done in a single request.

Thank you very much.

Regards

Prashant Bhure

Christopher Saunders

unread,
Sep 20, 2012, 9:21:54 AM9/20/12
to shopify-a...@googlegroups.com
Nope, that's the way you do it. You're updating a single resource (Product Variant), so for each one you want to change you'll have to do it this way.

If you're worried about it hitting API limits or having your app be slow, just create N background jobs with the necessary information for each variant you want to update. Also, be sure to check your API limits so you don't end up having jobs die on you by mistake.

--
Chris // API and Integrations Developer @ Shopify
> --
>
>
>

Christopher Saunders

unread,
Sep 20, 2012, 10:10:41 AM9/20/12
to shopify-a...@googlegroups.com
On further inspection you can indeed do a batch update.

You need to include all the variant information you want updated in an update to your product.  Also, if that is the XML you are posting to Shopify it won't work because you need to have a list of variants, which contain all your variant data.

<product>
<!-- Stuff -->
<variants>
  <variant>
    <!-- Your updated variant information here -->
  </variant>
</variants>

For future questions, please ask them on Stack Overflow, tagged with Shopify.

--
Chris // API and Integrations Developer @ Shopify

Reply all
Reply to author
Forward
0 new messages