New Shopify Certification now available: Liquid Storefronts for Theme Developers

how to update tracked quantity

OlexBezr
Visitor
1 0 0

Hello.

How can I update to true tracked quantitry in python api? 
I use this for update quantity 

shopify.InventoryLevel.set(inventory_item_id=variant.inventory_item_id, location_id=<loc id>, available=<available>)

But this only works if enabled tracked quantitry. Otherwise I get an error 422

Response(code=422, body="b'{"errors":["Inventory item does not have inventory tracking enabled"]}'"

 

Reply 1 (1)
Sp1ke
Tourist
10 3 3

When creating new product, there is optional settings called "inventory_management" (possible values are: 'null' or 'shopify')

You will be able to update your inventory levels only in case "inventory_management"="shopify" for related product.

You can use following json code to update inventory_management for necessary product:

 

use PUT for related product_id on https://yourshop.myshopify.com/admin/api/2023-07/products/7815459321185.json

 

{"product":
{
"id": "7815459321185",
"variants": [{
"id": "43467836236481",
"inventory_management": "shopify"
}]
}
}