Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shopifypartners/92e9b9a86091d41f3459188b6f8d1b05 to your computer and use it in GitHub Desktop.
Save shopifypartners/92e9b9a86091d41f3459188b6f8d1b05 to your computer and use it in GitHub Desktop.
# 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