Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating inventory quantities using the Shopify API

Tags:

api

shopify

I'm trying to update products using the Shopify API. Here's a sample XML request to update the title, weight and inventory of a product:

<?xml version="1.0" encoding="UTF-8"?>
<product>
  <id type="integer">100159400</id>
  <title>150 Watt Mini Stereo Power Amplifier</title>
  <variants type="array">
    <variant>
      <id type="integer">233139732</id>
      <grams type="integer">700</grams>
      <inventory-quantity type="integer">222</inventory-quantity>
    </variant>
  </variants>
</product>

I get a 200-OK after PUT /admin/products/100159400.xml. The title and weight (grams) get updated just fine, but not the inventory quantity. This is consistent for all other calls: I can update every field but the inventory quantity. Ideas?

like image 690
MiGz Avatar asked Aug 29 '12 02:08

MiGz


1 Answers

That product does not have inventory tracking turned on. In your admin, you should see that the inventory level shows as infinity.

To change this and start tracking inventory, you need to set the inventory_management field on the variant to shopify. The following XML should do the trick:

<?xml version="1.0" encoding="UTF-8"?>
<product>
  <id type="integer">100159400</id>
  <title>150 Watt Mini Stereo Power Amplifier</title>
  <variants type="array">
    <variant>
      <id type="integer">233139732</id>
      <grams type="integer">700</grams>
      <inventory-management>shopify</inventory-management>
      <inventory-quantity type="integer">222</inventory-quantity>
    </variant>
  </variants>
</product>
like image 70
David Underwood Avatar answered Oct 01 '22 10:10

David Underwood