Webhook whenever an item is out of stock or restocks.

Highlighted
New Member
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 :)

 

0 Likes
Highlighted
Highlighted
New Member
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

0 Likes
Highlighted
Shopify Partner
533 38 109

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. 

0 Likes