Unlocking Your Shopify Inventory History: A Community Guide to Tracking Stock Adjustments & Costs
Hey everyone! As a Shopify migration expert and someone who spends a lot of time digging into the community forums, I often come across discussions that really hit home for store owners. Recently, there was a particularly insightful thread that caught my eye, titled initially: "Feature Request: Queryable Inventory Adjustment History via Admin API."
It sounds a bit technical, right? But the core problem it addresses is something almost every merchant struggles with: reliably tracking exactly when stock came in, how much it cost at that moment, and its value over time. Without this data, planning cash flow, managing vendor payments, and even accurate Cost of Goods Sold (COGS) reporting becomes a massive headache. As one member, Mubashir-Ali, eloquently put it, this gap makes it incredibly hard to "model vendor payment obligations against cash generation" or build "cash flow forecasting tools natively within Shopify data."
The Core Challenge: Why Shopify's API Falls Short (Right Now)
The discussion quickly highlighted a couple of key issues with the current Shopify Admin API that prevent merchants from getting this granular historical data:
-
Missing Queryable Adjustment History: While Shopify has
InventoryAdjustmentGroup, it's primarily a mutation return type. This means you can see the result of an adjustment, but you can't easily query a historical list of all adjustments with filters (like by date range or type). You can get some data through Bulk Operation exports under InventoryActivity, but it’s not ideal for real-time, programmatic access. -
Mutable Cost Data: This is the trickier part. Shopify's
InventoryItem.costis mutable. If your supplier's prices change and you update the cost basis in Shopify, all your prior inventory adjustments — which were recorded with the old cost — suddenly lose their true historical unit cost. This makes accurate COGS modeling nearly impossible if you're relying solely on the currentInventoryItem.cost.
As lumine, a partner-side contributor, pointed out, this “gap is real and it bites everyone trying to model COGS or cash flow off Shopify data alone.” It’s clear this isn’t just a minor inconvenience; it’s a significant barrier to proper financial and operational reporting for small and mid-size merchants.
The Community's Smart Workaround: Real-Time Data Capture
Thankfully, the community didn't just stop at identifying the problem. They also shared a really smart, actionable workaround that many are using today. The core idea is to intercept inventory changes as they happen and store that critical historical data yourself.
The recommended approach centers around using Shopify's inventory_levels/update webhook. This webhook fires every time an inventory level changes for a variant at a specific location. By subscribing to it, you can capture the "delta" (the change in quantity) and, crucially, a snapshot of the unit cost at that exact moment. This solves both problems: you get a historical record of adjustments, and you capture the cost when the adjustment occurred, preserving its true value.
Step-by-Step: Setting Up Your Inventory History Tracker
Implementing this solution might sound complex, but it's surprisingly achievable — lumine even suggested it could be “roughly an afternoon of work” for a single store. Here’s how you can set it up:
-
Choose Your External Database: You'll need somewhere to store this historical data. Popular, relatively easy-to-use options mentioned include Cloudflare D1 or Supabase, but any database you're comfortable with (like PostgreSQL, MySQL, or even a simple spreadsheet for very small operations) will work. The goal is to have a place where you can write and query your own inventory history.
-
Create a Webhook Endpoint: This is a specific URL on your server or a serverless function that Shopify will send data to when an inventory change occurs. You'll need to set this up to receive HTTP POST requests.
-
Subscribe to the
inventory_levels/updateWebhook:- Go to your Shopify Admin.
- Navigate to Settings > Notifications.
- Scroll down to the Webhooks section and click Create webhook.
- For the Event, select
Inventory levels > Update. - For the URL, enter the endpoint you created in Step 2.
- Choose your preferred API version (always best to use the latest stable version).
- Click Save webhook.
-
Process the Webhook Data: When your endpoint receives an
inventory_levels/updatewebhook, it will contain information about the variant and the new inventory level. Crucially, in your webhook handler code, you need to:- Extract the
variant_id,location_id, and theavailablequantity (after the update). - Calculate the
delta(the change in quantity) by comparing the newavailablequantity to the previous quantity you've stored (if you're tracking it). If you're just starting, the first recorded change will be the initial stock. - Immediately query the Shopify Admin API (using GraphQL or REST, whatever you prefer) for the
InventoryItem.costassociated with thatvariant_idat that exact moment. This is your cost snapshot! - Note the
timestampof the webhook event.
- Extract the
-
Store the Data: Take all this collected information —
variant_id,location_id,delta,timestamp,available_after, and your crucial cost snapshot — and save it as a new record in your external database. This record now represents a single, historical inventory adjustment event with its cost at that time. -
Query Your Data for Insights: Once you have data flowing into your database, you can query it to generate the reports you need: total value of inventory received in the last 30 days, COGS calculations based on actual historical costs, detailed stock movement reports, and more. This empowers your forecasting and financial planning.
What This Unlocks for Your Business
Implementing this workaround, though it requires a bit of initial setup, provides invaluable benefits:
- Accurate COGS: You'll finally have reliable historical cost data to calculate your true Cost of Goods Sold, leading to more accurate profit margins.
- Better Cash Flow Forecasting: By tracking when inventory was received and its value, you can much more accurately predict your cash outflow for vendor payments and understand your working capital needs.
- Informed Vendor Payments: Knowing the exact value of received goods over a period helps you align payments with actual inventory intake and sales cycles.
- Granular Operational Reporting: Beyond finance, you gain a deeper understanding of stock movement, identifying trends in receipts, returns, and adjustments.
While this solution doesn't backfill data from before you set it up, it ensures you stop losing critical information going forward. It's a powerful way to take control of your inventory data and gain the financial visibility every merchant needs. Hopefully, Shopify will eventually provide a native queryable API for this, but until then, the community has given us a solid path forward. Give it a shot — your finance team (and your bottom line) will thank you!