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"