To read inventory quantity from the Shopify Storefront API, query quantityAvailable on ProductVariant. It needs a Storefront access token with the unauthenticated_read_product_inventory scope, and it can come back null, so treat null as unknown rather than zero. Pair it with availableForSale and currentlyNotInStock, and let the cart’s MERCHANDISE_NOT_ENOUGH_STOCK warning settle what a buyer can actually order.
Everything below was written against Storefront API 2026-10, which Shopify’s versioning page lists as the latest stable release as of November 2026. We ran the queries against mock.shop, Shopify’s public demo store, so you can paste them without a store of your own.
Which Storefront API fields hold inventory quantity?
Three fields on ProductVariant do the work, and they answer different questions.
availableForSale is a non-null boolean: can this variant be bought at all? currentlyNotInStock, also non-null, is described by Shopify as “out of stock but still available for purchase (used for backorders)”. That is the flag that tells you the merchant has set the variant to keep selling at zero. quantityAvailable is a nullable Int, “the total sellable quantity of the variant for online sales channels”. It is the only one of the three that gives you a number.
On Product, availableForSale means at least one variant is buyable, and totalInventory gives a product-wide count. Both totalInventory and the variant’s quantityAvailable are marked “Token access required” in the reference.
For local pickup there is a fourth source, which we come back to further down: storeAvailability, a per-location connection with its own available and quantityAvailable.
Why does quantityAvailable return null?
Usually because of how the request was authenticated. The access scopes page ties quantityAvailable on ProductVariant to the unauthenticated_read_product_inventory scope. That scope is separate from unauthenticated_read_product_listings, which is enough to read the product itself, so a token can see every product and still get no stock numbers back.
Tokenless requests are the other trap. The Storefront API authentication docs say tokenless access covers products, collections, search, pages and cart, with a query complexity limit of 1,000. Inventory counts are not on that list, and the field reference flags quantityAvailable as needing a token. If your storefront started life on tokenless requests, stock counts are the point where you need a token.
The fix depends on where the token came from. A custom app’s token gets the scope added in its configuration. For the Headless channel, Shopify says storefront permissions are managed in the Shopify admin, so the merchant (or whoever holds admin access) enables the inventory permission there.
One thing we have not verified: what quantityAvailable returns for a variant whose inventory is not tracked at all. The reference does not say. Code for null anyway. On mock.shop, quantityAvailable came back populated while totalInventory on the same products returned null, which is a good reminder that demo data is not a contract.
How should stock map to what the product page shows?
Collapse the three fields into one state before any component sees them. Ordering matters: check availableForSale first, because a variant that cannot be bought should never show a count, then the backorder flag, then the number.
type Variant = {
id: string;
availableForSale: boolean;
currentlyNotInStock: boolean;
quantityAvailable: number | null;
};
type StockState =
| { kind: "sold-out" }
| { kind: "backorder" }
| { kind: "in-stock"; count: number | null }
| { kind: "low"; count: number };
const LOW_STOCK = 5;
/** Turn the three Storefront API fields into one UI state. */
export function stockState(v: Variant): StockState {
if (!v.availableForSale) return { kind: "sold-out" };
if (v.currentlyNotInStock) return { kind: "backorder" };
const n = v.quantityAvailable;
if (n === null) return { kind: "in-stock", count: null }; // unknown, not zero
if (n <= LOW_STOCK) return { kind: "low", count: n };
return { kind: "in-stock", count: n };
}
const VARIANT_STOCK = `#graphql
query VariantStock($handle: String!) {
product(handle: $handle) {
variants(first: 100) {
nodes {
id
availableForSale
currentlyNotInStock
quantityAvailable
}
}
}
}
`;
The null branch is the one people skip. Render “In stock” with no number. Rendering “0 left” next to an enabled Add to cart button is how a missing scope turns into a support ticket.
We first wrote this against node(id:) and got null back from mock.shop for a variant ID that the product query had just returned. A handle lookup worked. The Storefront API documents node, so this looks like a gap in the demo store, but it is a fair argument for typing every Storefront response as possibly null.
Should you cache inventory on a product page?
Not for long. Product copy and images change when someone edits them; a stock count changes with every order. If the whole page is cached for an hour, “Only 3 left” is an hour old.
Split the request. Fetch title, images and description with a long cache, and fetch the stock fields in a second, short-lived query, or from the browser once the variant is selected. In Hydrogen (the classic line, 2026.4.x), CacheShort stores data for 1 second with a further 9 seconds of stale-while-revalidate, which suits the stock query. Our Hydrogen caching guide covers how sub-request caching sits alongside full-page caching.
Even an uncached count is a snapshot. Two buyers can see the same last unit. That is why the cart is the authority, and why the number on the page should be treated as a hint.
What happens when a buyer adds more than you have?
The cart mutation succeeds, and the line is quietly reduced. We sent cartCreate to mock.shop asking for 500 of a variant whose quantityAvailable was 48. There was no user error. The cart came back with a line quantity of 48 and this in warnings:
{
"code": "MERCHANDISE_NOT_ENOUGH_STOCK",
"target": "gid://shopify/CartLine/198394",
"message": "Only 48 items were added to your cart due to availability."
}
Shopify’s cart warnings guide explains the split: a user error means the mutation failed, while a warning “confirms the mutation’s success and the automatic changes it has made to the cart”. Its own example is MERCHANDISE_OUT_OF_STOCK, raised when a line already in the cart sells out while another product is being added, with the line left at quantity 0 and its ID in target. Both codes are in the CartWarningCode enum.
So select warnings on every cart mutation, not just userErrors, and tell the buyer what changed:
for (const w of cartCreate.warnings) {
if (w.code === "MERCHANDISE_NOT_ENOUGH_STOCK" || w.code === "MERCHANDISE_OUT_OF_STOCK") {
console.log(`Cart changed line ${w.target}: ${w.message}`);
}
}
In a real storefront that console.log becomes a notice next to the cart line, and an out-of-stock target is a candidate for cartLinesRemove. Our Storefront API cart walkthrough covers the rest of the mutation set.
The cart can also cap lower than the product page suggests. A July 2025 changelog entry says cart limits now follow the inventory available in the buyer’s market region, for shops set to sell only within their configured shipping zones. Shopify’s description of quantityAvailable does not mention markets, so on those shops the count you display can be higher than what a particular buyer may add, and the warning is where you find out.
How do you show stock for local pickup?
Use storeAvailability on the variant, sorted by distance with near:
query PickupStock($handle: String!, $near: GeoCoordinateInput) {
product(handle: $handle) {
selectedOrFirstAvailableVariant {
storeAvailability(first: 5, near: $near) {
nodes {
available
quantityAvailable
pickUpTime
location { name }
}
}
}
}
}
Read the two fields carefully. Per the StoreAvailability reference, quantityAvailable counts only stock physically at that location, while available is also true when a store transfer can supply it or the inventory is untracked or oversellable. “Available” with a count of 0 is a valid answer and means “can be collected here, later”. Show pickUpTime, which in the transfer case reflects transit time, rather than the count. mock.shop returned an empty list for this query, so test it against a store that has pickup locations.
What we would do
Request the inventory scope on day one, even if the first design has no stock counts, because adding it later is a permission change that someone has to remember to make. Map the three fields through one function with an explicit null branch. Keep stock out of the long-lived page cache. Read warnings on every cart mutation and treat the cart as the final word. If a merchant’s stock moves slowly and they only care about in or out, skip the count entirely: availableForSale and currentlyNotInStock need no extra scope and cannot drift into a misleading number.
We build headless Shopify storefronts and the theme and app work around them, including the inventory and cart plumbing described here. If your product pages are promising stock the cart will not honour, our Shopify development team can trace where the numbers diverge.