Inventory Changes & Product/Update Webhook Triggers

Solved
pmooney-extend
Tourist
3 0 4

Hello,

We provide a Shopify App to enable Shopify merchants to sell extended warranties for their products. Part of the process in providing this service to merchants is to ensure we have an accurate representation of the variants in a merchant's Shopify store. As part of our integration, we add a webhook for the `product/update` topic that POSTs to our endpoint to see if there are price changes for the variant we need to account for when we offer the extended warranty.

However, we noticed that there is an influx of webhook `product/update` requests coming into our system when we do this. After investigating, it seems that every time an order is made on a product that is inventory-tracked, the webhook is called, since Shopify seems to consider this a "product" update.

Therefore, I have the following questions:

1. Is there some way we can only receive a webhook request from Shopify when just the product's fields are changed (such as description, price, title, etc.), and not inventory?

2. Is there a way to tell in the 'product/update' webhook request body what field changed, so we can decide whether or not this webhook is actionable on our part? Preferably the solution would not involve managing our own version of the merchant's Shopify product catalog and querying against our database every time to compare fields and see what changed.

3. If the answers to questions 1. and 2. are no, is there anything on the developer roadmap to change the behavior of these webhooks to conform to the requests I spelled out here?

james-langille
Shopify Staff
Shopify Staff
54 12 14

This is an accepted solution.

Hello @pmooney-extend, to answer your questions:

  1. Currently, no. Webhooks are fired whenever a model is created, deleted, or anything within it is changed, including the inventory level for products.
  2. Currently, no. Update webhooks only report the current state of the model, not what field(s) changed. I agree something like that would be useful, and it's not ideal to ask apps to track their own state to figure out what changed.
  3. Yes. Although I cannot commit to any timelines here, we are currently looking at different alternatives to make Webhooks more relevant to downstream apps. We aim to strike a balance between complexity and relevance to simplify application development.

james-langille | Developer @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

gdarrigo
Tourist
4 0 3

There is some news to check if the update is due to inventory change?

Thanks

Gabriele

0 Likes
james-langille
Shopify Staff
Shopify Staff
54 12 14

Sadly, no. However, there are more topics you can listen to that are inventory-specific if that helps, such as 'inventory_levels/update' or 'inventory_items/update'

james-langille | Developer @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
gdarrigo
Tourist
4 0 3

My goal is to filter the events due to inventory update and keep only others, cause I have hundreds of update events that I don't need and that give me a lot of unusefull traffic that send my system in crysis. Can you give some advice to solve?

Thanks

Gabriele

cYberSport91
Tourist
7 0 2

The variants seem to have `old_inventory_quantity` alongside with `inventory_quantity`. 

If you update a product in Shopify Admin, and Product Update webhook gets fired, and all the quantities are the same - could you safely assume that you updated something outside of quantity?

If an order is placed, it seems safe to assume the only thing that's going to change is an inventory.

If so, a very simple serverless function could solve this in ~10 LOC

0 Likes
pmooney-extend
Tourist
3 0 4

We noticed this too @cYberSport91 , but when testing this same concept in our lambda, for whatever reason, Shopify was ALWAYS returning the same value for old_inventory_quantity and inventory_quantity  . We were gonna report it as a bug, but then we saw in their API documentation that these fields are deprecated and will be removed, so it wouldn't have been a long-term solution for us anyways.

0 Likes
cYberSport91
Tourist
7 0 2

@pmooney-extend noooo.  dang.  do you have a solution you've come up with?  I'm hacking on a rails proxy to just cache everything and trigger the netlify rebuilds for me. 

0 Likes
pmooney-extend
Tourist
3 0 4

@cYberSport91 No solution yet. Hoping Shopify ( cc @james-langille ) addresses this common use case.

JoshHighland
Shopify Expert
70 1 26

I'm also looking for this solution and have a lambda checking the inventory changes - but as you pointed out the numbers are always the same

0 Likes