How can I update inventory quantity via API?

Solved

How can I update inventory quantity via API?

Coludus
Tourist
8 0 2

I would like to change inventory quantity of products, but I don't even know how to do that.

Here is a part of example to list a product I try to do.

product = shopify.Product()
product.title = "example"
product.save()

 

Accepted Solution (1)

etrolmos
Shopify Partner
23 1 5

This is an accepted solution.

The SDK should be similar to Shopify Admin API, so check the API docs on inventory handling:

https://shopify.dev/api/admin/rest/reference/inventory 

https://shopify.dev/api/examples/product-inventory

Inventory is now tracked against InventoryItem and InventoryLevel in connection to a Location on each product variant.

I'm not familiar with the Python SDK, not sure if InventoryItem will be auto-populated on the Variant object, but I'm guessing after saving the product, you can do something like:

inv = shopify.InventoryLevel()
inv.set(inventory_item_id=variant.inventory_item_id, location_id=<location id>, available=<quantity>)

Should return a collection, then call set() method to set the inventory for a location.

View solution in original post

Replies 4 (4)

etrolmos
Shopify Partner
23 1 5

This is an accepted solution.

The SDK should be similar to Shopify Admin API, so check the API docs on inventory handling:

https://shopify.dev/api/admin/rest/reference/inventory 

https://shopify.dev/api/examples/product-inventory

Inventory is now tracked against InventoryItem and InventoryLevel in connection to a Location on each product variant.

I'm not familiar with the Python SDK, not sure if InventoryItem will be auto-populated on the Variant object, but I'm guessing after saving the product, you can do something like:

inv = shopify.InventoryLevel()
inv.set(inventory_item_id=variant.inventory_item_id, location_id=<location id>, available=<quantity>)

Should return a collection, then call set() method to set the inventory for a location.

Coludus
Tourist
8 0 2

Thank you for your help

I didn't even understand what location was.

I could manage inventory.

I appreciate it again!

Satish5
New Member
6 0 0

Hi, can you please tell me how did you acheive this via api?

Satish5
New Member
6 0 0

hi, should i install any libraries for acheiving that and also can you please tell me where should i write this code