Missing inventory_levels/update webhook

Hey,

One of our customers created a product via Shopify Admin but we got only inventory_levels/connect webhook not an update. See the webhook that we got below.

Time we got the webhook: 2021-03-26 11:02:47.000Z
Topic: inventory_levels/connect
Inventory Item Id: 32753431773219
Location Id: 60897820707
available: null
x-shopify-webhook-id: ec593165-aeb8-4636-8e6a-c46c048c7c0d

After that there was no update webhook at all. But when we look at the graphql for this location we have seen the information below.

Inventory Item Id: 32753431773219
Location Id: 60897820707
Available: 11
updated_at: 2021-03-26 11:02:55.000Z

So my question here, in which cases available field becomes null in inventory_levels/connect webhook? Secondly, why Shopify didn't send this change.

Co-Founder / Developer at: merchbees
Merchbees Low Stock Alert - Keep track of your low stock items by email and slack
Merchbees Inventory Value - Know your inventory value and quantity in real-time
Push Down & Hide Out of Stock - Move out of stock products to the bottom of the collection to improve SEO & hide/ unhide automatically
0 Likes
_JCC_
Shopify Staff
Shopify Staff
151 20 27

Hey @Mete ,

Happy to help you out with this.

When creating a product via our Admin or API, an inventory_levels/connect hook will fire with an available of null when the product creation doesn't specify track quantity in the admin or inventory_management policy on the API. The inventory_levels/connect in this case is because we create a default variant and a corresponding inventory item for that variant.

Updating inventory quantities in the Admin and via API should trigger the inventory_levels/update hook. That being said, I have noticed that if you update quantities in the Admin on a new product, where you had just checked track quantity but not yet saved, the inventory_levels/update hook doesn't fire.  This explains what you experienced not seeing an inventory_levels/update hook come through for an inventory item that clearly had been updated as seen with the updated_at field. Unfortunately, the example you provided is outside of our log retention window so I can't verify your example mirrors what I'm seeing but I believe it's highly probable this is what happened.

I'll pass this issue along to the product team. 

Regards,

John

John C | Developer Support @ 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

@_JCC_ wrote:

Hey @Mete ,

Happy to help you out with this.

When creating a product via our Admin or API, an inventory_levels/connect hook will fire with an available of null when the product creation doesn't specify track quantity in the admin or inventory_management policy on the API. The inventory_levels/connect in this case because we create a default variant and a corresponding inventory item for that variant.

Updating inventory quantities in the Admin and via API should trigger the inventory_levels/update hook. That being said, I have noticed that if you update quantities in the Admin on a new product, where you had just checked track quantity but not yet saved, the inventory_levels/update hook doesn't fire.  This explains what you experienced not seeing an inventory_levels/update hook come through for an inventory item that clearly had been updated as seen with the updated_at field. Unfortunately, the example you provided is outside of our log retention window so I can't verify your example mirrors what I'm seeing but I believe it's highly probably this is what happened.

I'll pass this issue along to the product team. 

Regards,

John


Hey @_JCC_ ,

Thanks for the providing rootcause. You are right in the Shopify Admin, two sections works independently. When you click tracked it doesn't submit the change to backend because waits for the submit button. But stock change makes an ajax call to admin/internal/web/graphql/core?operation=InventoryAdjustQuantityMutation.

I believe to correct this at least for Shopify Admin. Status of "tracked" needs to be changed before inventory level change. Otherwise apps can't be notified by the change.

Could you please let us know if the product team has any intention to correct this behavior?

Thanks

Co-Founder / Developer at: merchbees
Merchbees Low Stock Alert - Keep track of your low stock items by email and slack
Merchbees Inventory Value - Know your inventory value and quantity in real-time
Push Down & Hide Out of Stock - Move out of stock products to the bottom of the collection to improve SEO & hide/ unhide automatically
0 Likes
_JCC_
Shopify Staff
Shopify Staff
151 20 27

Hey @Mete 

Just wanted to follow up on this. To ensure you're not missing updates to tracked, the suggestion is to use the web hook inventory_items/update. This will ensure as the user or an app changes the track quantity setting you get that notification. While inventory quantities are not included in the payload it allows you to based on the tracked setting to react and retrieve any inventory level type information you need.

Regards,

John

John C | Developer Support @ 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

Hey @_JCC_ 

I guess we are not on the same page. I will share the steps to reproduce the problem.

1- Create a product with track quantity field as disabled and save it.
2- Go to /admin/products/{{product_id}} (edit product screen).
3- Enable Track Quantity. Notice that it won't send you any inventory_items/update webhook because user didn't used the save button yet.
4- On the User Interface, set availability of a location to 5 for example. Click on save for this small popup window.

At this point inventory quantity has been updated. No webhook has been sent because Track Quantity field is still disabled on the backend of Shopify. As app developers we lose this change.

Next expected user behavior is to click on the save button at the top which will save the Track Quantity as enabled. It will send inventory_items/update webhook. Or user may leave the page here without saving it which happens as well. In both cases, we are not getting inventory_levels/update webhook.

So what you are saying to me to check all of the inventory levels for each location of an inventory item is not logical/feasible. The purpose of webhook is to listen the changes. Here in this use case, Shopify backend doesn't send the change to app developers but allow end users to change it when Track Quantity field is disabled.

The simplest solution here is using Ajax when enabling Track Quantity. Or it could be enabled in the time of putting a value to incoming/available fields. Or you can give us the option to listen the changes when Track Quantity is disabled as well via inventory_levels/update.

Best

Co-Founder / Developer at: merchbees
Merchbees Low Stock Alert - Keep track of your low stock items by email and slack
Merchbees Inventory Value - Know your inventory value and quantity in real-time
Push Down & Hide Out of Stock - Move out of stock products to the bottom of the collection to improve SEO & hide/ unhide automatically
0 Likes