Webhook whenever an item is out of stock or restocks.

centrall_mtl
Visitor
2 0 0

Hi,

I want to develop an app that would determine whenever an item is out of stock, or whenever an item is restocked.

My first approach to determine if an item is out of stock was to read every HTTP request from the orders/paid Webhook and extract every variant_id of each items in line_items.

Once I get every variant_id of the order, I make an API call that includes them.

/admin/api/2020-04/variants/{variant_id}.json

My app extracts the following data from the API call.

  • option1
  • sku
  • inventory_quantity

To determine if the item that was just purchased is out of stock, I would only need to compare the inventory_quantity to the value of 0. If the value is equal to 0, then I can trigger whatever I want (update a row in a spreadsheet, send an sms notification and much more).

Now, the problem is that I can't figure a manner to determine if a product is restocked. The inventory_levels/update Webhook gives me the available field where I can see how many times we have a specific item, but I can't see if the old inventory level was 0 or 2. (where 2 would mean that the quantity of that item is not restocked, but decreased by 1). 

I'll take every suggestions, and I hope every has a great day 🙂

 

Replies 3 (3)

Gregarican
Shopify Partner
1033 86 285
centrall_mtl
Visitor
2 0 0

Thank you for answering. I've seen this thread before but what I've noticed from it is that I would need to have a database with every InventoryLevels of each product. That would be a lot of work and it would take time for every product's InventoryLevels to be initially updated.

 

Therefore, I'm wondering if there is a way to search for the inventory of an item at a certain date through your API. With this information, I could know if the item in question is either restocking or out of stock.

Thanks again,
Mohamed

Gregarican
Shopify Partner
1033 86 285

You could add the updated_at_min as a query parameter when fetching products via the REST API. That would only pull products that had been edited on or after the date/time you specify. That's behind a lot of our logic that syncs up records between various systems.