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

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

pthieu
Excursionist
24 1 11

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?

Replies 14 (14)

Zameer
Shopify Staff
297 31 90

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.

To learn more visit the Shopify Help Center or the Community Blog.

pthieu
Excursionist
24 1 11

@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?

Zameer
Shopify Staff
297 31 90

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.

To learn more visit the Shopify Help Center or the Community Blog.

pthieu
Excursionist
24 1 11

@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?
Zameer
Shopify Staff
297 31 90

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.

To learn more visit the Shopify Help Center or the Community Blog.

pthieu
Excursionist
24 1 11

@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?

Zameer
Shopify Staff
297 31 90

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.

To learn more visit the Shopify Help Center or the Community Blog.

power777
Tourist
9 1 5

@Zameer thanks for this explanation! Doesn't all this make the current implementation of the products/update webhook incredibly useless? 

 

Not only is it difficult to track updates to the availability status of a product/variant. But it's also quite impossible to focus on updates that matter if you wish to utilize the webhook for something else than inventory tracking. Since the webhook ALWAYS fires on sales, it's quite impossible to filter out update events that actually matter (i.e. actual changes to the products, like price, tags, or any other edits...)

Is there a solution to this issue, maybe by combining rules for different webhooks???

Zameer
Shopify Staff
297 31 90

Hey @power777 - I agree that the current overlap between some webhook subscription topics makes it challenging to process the data Shopify sends out.

 

We're working on improving this process, however, when it comes to deprecations, it's not easy to just "shut off" the behaviour as many partners are currently relying on the `products/update` webhook to fire on inventory adjustments. That being said, I'm going to pass along your feedback to our development team so they're aware of the pain point, and so they can see what changes can be made going forward to help deal with it.

To learn more visit the Shopify Help Center or the Community Blog.

JoshHighland
Shopify Partner
213 12 76

hi @Zameer I came her with the same issue. I would like to be notified of product changes only, not sales.

 

It may make sense to create 2 new webhooks in the next API release

 

- products/update_nonsales

- products/update_inventory

 

or something else along the way - keeping the existing webhook in place.

SEO Manager - The all-in-One SEO solution for Shopify
A powerful suite of SEO tools that gets you found in Google results

- Install SEO Manager -
Mike_Moore
Shopify Partner
4 0 5

In my situation, I am noticing that the `products/update` webhook is firing when products are sold even though those products are not set to track quantity? Is this the expected behaviour?

Rafay
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.

Zameer
Shopify Staff
297 31 90

 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.

To learn more visit the Shopify Help Center or the Community Blog.

Rafay
Tourist
6 0 0

@Zameer 

 

Thanks a lot for confirming the behavior, that helps. 

 

Best reagrds.