#How to retrieve variant inventory quantity from cart?

8 messages · Page 1 of 1 (latest)

indigo yoke
#

I’m trying to retrieve the inventory quantity of a product variant from the SDK, but the field isn’t being returned in the response and I’m not sure why.

Here’s the function I’m using:

export async function retrieveCart(cartId?: string, fields?: string) {
  const id = cartId || (await getCartId())
  fields ??=
    "*items, *region, *items.product, *items.variant, *items.thumbnail, *items.metadata, +items.total, *promotions, +shipping_methods.name, +items.variant.inventory_quantity, +items.variant.manage_inventory, +items.variant.allow_backorder"

  return await sdk.client
    .fetch<HttpTypes.StoreCartResponse>(`/store/carts/${id}`, {
      method: "GET",
      query: {
        fields,
      },
      headers,
      next,
      cache: "force-cache",
    })
    .then(({ cart }: { cart: HttpTypes.StoreCart }) => {
      console.log("Retrieved cart:", cart)
      return cart
    })
    .catch(() => null)
}

Even though I’ve added +items.variant.inventory_quantity the inventory_quantity field still doesn’t show up in the response.

I’ve attached the full payload for reference.

Has anyone run into this before or knows if I’m missing something? Any help would be really appreciated 🙏
(I'm using storefront), I even try to call the endpoint cart manually but it didn't return the inventory_quantity as well.

✅ The stock location being linked to the sales channel
✅ The variant having manage_inventory: true
✅ The inventory item having available_quantity: 4
✅ You passing +items.variant.inventory_quantity in the fields
✅ Passing header with x-publishable-api-key correctly

sdk: "@medusajs/js-sdk": "latest"
admin: "@medusajs/admin-sdk": "2.13.1"
framework: "@medusajs/framework": "2.13.1"

quiet hull
indigo yoke
#

@quiet hull I've tried passing the region: "br" on the query params and I could no retrieve any cart anymore.
About the location levels, it has 2 products available at 1 location.

quiet hull
indigo yoke
indigo yoke
#

I've also tried using the cart.retrieve() method and the variant has no attribute inventory_quantity

  fields ??=
    "*items, *region, *items.product, *items.variant, *items.thumbnail, *items.metadata, +items.total, *promotions, +shipping_methods.name, +items.variant.inventory_quantity, +items.variant.manage_inventory, +items.variant.allow_backorder"


sdk.store.cart.retrieve(id, { fields }, headers).then(({ cart }) => {
    console.log(`Retrieved cart:`, cart.items[0].variant)
    return cart
  })

This is the output:

{
  id: 'variant_01KNT7RWWQTHBY8T28AR35M6BK',
  title: 'pfl',
  sku: 'me02-018-foil-NM-pt',
  barcode: null,
  ean: null,
  upc: null,
  allow_backorder: false,
  manage_inventory: true,
  hs_code: null,
  origin_country: null,
  mid_code: null,
  material: null,
  weight: null,
  length: null,
  height: null,
  width: null,
  metadata: {
    extra: 'foil',
  },
  variant_rank: 0,
  thumbnail: 'https://assets.myimage.net/pt/me/me02/018/high.png',
  product_id: 'prod_01KNT7RWVEVJJS0ASK69MX41KN',
  product: { id: 'prod_01KNT7RWVEVJJS0ASK69MX41KN' },
  created_at: '2026-04-09T23:03:26.359Z',
  updated_at: '2026-04-09T23:03:26.359Z',
  deleted_at: null
}
dusk pelican
#

I'm pretty sure inventory is a restricted field on the storefront by default since it's something competitors and scrapers would be very interested in.

If you want to get around it, you could duplicate the endpoint