Does the product/update webhook let me know if an item has been restocked?

Excursionist
24 1 2

I would like to know when a product's `inventory_quantity` changes from 0 to non-zero. I've taken a look at the webhooks documentation: https://help.shopify.com/en/api/reference/events/webhook

 

It seems that there are `old_inventory_quantity` and `inventory_quantity` fields that can be used but in the responses, their values are the same. Is this a good strategy to use? Or do the webhooks not fire when inventory changes?

0 Likes
Shopify Staff
Shopify Staff
298 32 59

Hey there,

 

Edit: Since inventory information is now contained on the InventoryLevel object and no longer on the ProductVariant, you should subscribe to the `inventory_levels/update` webhook which will fire anytime there is an update to the `available` quantity.

 

The `products/update` webhook will still fire for overall inventory_quantity changes, but it won't specify which location that inventory is coming from.

0 Likes
Excursionist
24 1 2

@Zameer I'm looking at the `inventory_levels/update` webhook response:

 

{
  "inventory_item_id": 271878346596884015,
  "location_id": 48752903,
  "available": null,
  "updated_at": "2019-04-09T11:04:38-04:00",
  "admin_graphql_api_id": "gid:\/\/shopify\/InventoryLevel\/48752903?inventory_item_id=271878346596884015"
}

It looks like there's no quantity and there's no shop information, only `inventory_item_id`, which looks to be global all of Shopify. Is this the full response?

0 Likes
Shopify Staff
Shopify Staff
298 32 59

Yes, that's the full response. The InventoryLevel documentation shows all of the properties associated with the object, which is being returned in the webhook payload. 

 

When the `available` quantity is null, it mean's that the InventoryItem is not tracked.

0 Likes
Excursionist
24 1 2

@Zameer: a few questions:

 

  1. Do you suggest I keep track of all products with zero inventory quantity and when this webhook comes in, check, to see if the quantity has changed and if it has gone from 0 to n, then perform some business logic?
  2. What do you mean by if the `available` quantity is `null`, the `InventoryItem` is not tracked? Wouldn't all inventory items be tracked by Shopify?
0 Likes
Shopify Staff
Shopify Staff
298 32 59

1. If your ultimate goal is to be able to determine when a product goes from zero inventory to non-zero, you would have to store in your database all of the InventoryLevels associated with each product. Every time you receive a `inventory_levels/update` webhook, you would then have to update your database values and perform business logic to see if the `available` value was previously zero and is now no longer zero. I'm not sure of your apps use case and if it will also need to monitor products that go from non-zero to zero and then back to non-zero but in that case, you'd need to store all InventoryLevel data.

 

2. It's possible to have a ProductVariant where the inventory isn't being tracked, ie: `inventory_management` = null as shown in the ProductVariant documentation.

0 Likes
Excursionist
24 1 2

@Zameer thanks for the answers. It's looking like I'll have to monitor the products and their inventory levels in my DB based on the strategy in your comments.

 

Do you think it's possible for me to use the `inventory_levels/update` webhook and then immediately call the Product API to get the `old_inventory_quantity` and `inventory_quantity` values? Or will this not be reliable?

0 Likes
Shopify Staff
Shopify Staff
298 32 59

That wouldn't work the way you're describing it. 

 

`old_inventory_quantity` is deprecated and it isn't meant to (and doesn't) contain the previous inventory total.

0 Likes
Tourist
6 0 0

@ZameerI am observing a completely different behavior with my app. Everytime there is a sale that fires product/update hook. Is there possibly i have done something wrong? or maybe each order/sale modifies product inventory and that in turns fire the product/update webhook?

 

I am stuck with this issue and will be grateful if you can help me out.

 

Regards.

0 Likes
Highlighted
Shopify Staff
Shopify Staff
298 32 59

 Hey @Rafay ,

 

I tested the behaviour and can confirm what you're experiencing. Since a value change on the variants `inventory_quantity` and `old_inventory_quantity` fields still updates the `updated_at` property, the `products/update` webhook is triggered.

 

But as mentioned before, this is a deprecated field, meaning we don't know what support will look like for it going forward. It also doesn't provide you with information such as the location where the inventory was sold from, which is why we recommend that you instead use the `inventory_levels/update` webhook.

1 Like