Forked from atomgiant/update_variant_inventory.rb
Last active
September 23, 2020 03:15
-
-
Save shopifypartners/92e9b9a86091d41f3459188b6f8d1b05 to your computer and use it in GitHub Desktop.
Shopify API update variant inventory - https://www.shopify.com/partners/blog/84051654-7-tips-to-maximize-your-use-of-the-shopify-api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Takes a product id, and a map of variant ids and quantities | |
def update_inventory(id, vid_quantities) | |
variants = vid_quantities.map do |vid, qty| | |
{ "id" => vid, "inventory_quantity" => qty } | |
end | |
data = { | |
"product" => { | |
"variants" => variants | |
} | |
} | |
request(:put, "products/#{id}.json", body: data.to_json) | |
end | |
update_inventory(1234567, {2222222 => 100, 3333333 => 200}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment