Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

What webhooks do I need to listen to keep track of changes in inventory levels?

Solved

What webhooks do I need to listen to keep track of changes in inventory levels?

arjun_rajkumar
Shopify Partner
54 3 9

Hey everyone!

 

I want to be updated whenever the inventory level quantity changes for an inventory item.

From the docs, it says that each inventory level belongs to one inventory item and has a location.

 

I am subscribing to these webhooks to be notified:

  1. inventory_levels/connect
  2. inventory_levels/disconnect
  3. inventory_levels/update
 
My question is this:

As I am already listening to the inventory_levels webhooks - do I need to also listen to order/create webhooks? I am assuming that whenever an order is created/deleted - Shopify updates the inventory level for the item, and therefore triggers the 'inventory_levels/update' webhook also in the order flow - and therefore, I only need to listen to these webhooks.

Just wanted to check if my assumption is correct?

THank you.
Arjun

Accepted Solution (1)
ShopifyDevSup
Shopify Staff
1453 238 518

This is an accepted solution.

Hey @arjun_rajkumar - great question, thanks for getting in touch. You're on point here - generally the inventory_level update webhook should trigger when an order is created, updated or cancelled as long as the product variant is tied to an inventory item. The only edge case I can think of is if  an order is created with a custom line item that doesn't have an associated product or variant in the store. Here, you might want to consider listening to the order/create, order/updated, and order/cancelled webhooks as well to ensure you capture those if needed. 

The only other instance where the inventory_level/update webhook wouldn't trigger would be the rare case where the webhook itself isn't sent out. Our webhooks are generally pretty reliable, but as a general rule we can't always guarantee they'll be sent out (delays, etc.), so we do recommend building in regular data reconciliation for instances like this (polling the specific endpoints at a set intervals, for instance). There's a bit more info on best practices here if you haven't checked out that doc yet.

Hope this helps!

Al | Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

View solution in original post

Replies 5 (5)

arjun_rajkumar
Shopify Partner
54 3 9

I checked with a dummy draft order -- and it's good to know that the inventory_level update webhook gets triggers whenever an order is created.
get back a payload like this:

{"inventory_item_id"=>47167843205411, "location_id"=>78603518243, "available"=>33, "updated_at"=>"2023-06-06T03:19:54-04:00", "admin_graphql_api_id"=>"gid://shopify/InventoryLevel/114990874915?inventory_item_id=47167843205411"}


Just wanted to check if there are any instances when an inventory_level update webhook will not be triggered when an order is created/updated/cancelled?

ShopifyDevSup
Shopify Staff
1453 238 518

This is an accepted solution.

Hey @arjun_rajkumar - great question, thanks for getting in touch. You're on point here - generally the inventory_level update webhook should trigger when an order is created, updated or cancelled as long as the product variant is tied to an inventory item. The only edge case I can think of is if  an order is created with a custom line item that doesn't have an associated product or variant in the store. Here, you might want to consider listening to the order/create, order/updated, and order/cancelled webhooks as well to ensure you capture those if needed. 

The only other instance where the inventory_level/update webhook wouldn't trigger would be the rare case where the webhook itself isn't sent out. Our webhooks are generally pretty reliable, but as a general rule we can't always guarantee they'll be sent out (delays, etc.), so we do recommend building in regular data reconciliation for instances like this (polling the specific endpoints at a set intervals, for instance). There's a bit more info on best practices here if you haven't checked out that doc yet.

Hope this helps!

Al | Shopify Developer Support

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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

arjun_rajkumar
Shopify Partner
54 3 9

Thank you for the reply. Makes sense - great idea about polling specific end points, and and am also exploring Amazon Event Bridge. Thank you.

arjun_rajkumar
Shopify Partner
54 3 9

Thank you! One doubt I have with the same is also when fulfilment apps handle orders for a store - e.g. a dropshipping app, which fulfils orders for the store. Would the same inventory level webhooks be triggered the same for this?

From the docs - "For fulfillment orders which are assigned to a location that is managed by a fulfillment service, a merchant or an Order Management App can send a fulfillment request to the fulfillment service which operates the location to request that they fulfill the associated items. A fulfillment service has the option to accept or reject this fulfillment request.

Once the fulfillment service has accepted the request, the request can no longer be cancelled by the merchant or order management app and instead a cancellation request must be submitted to the fulfillment service.

Once a fulfillment service accepts a fulfillment request, then after they are ready to pack items and send them for delivery, they create fulfillments with the Create a fulfillment for one or many fulfillment orders endpoint. They can provide tracking information right away or create fulfillments without it and then update tracking information for fulfillments."

Would the inventory level webhook have been triggered normally as soon as the order is created in this case also?

damonrcr
Shopify Partner
3 0 0

hey, @arjun_rajkumar is it possible to provide full inventory webhook api code to me? i am new in this field so can you please help.