Inventory levels and quantity changes. Since API 2026-04 the
quantity mutations require an idempotency key (@idempotent) and a
changeFromQuantity on every change: the quantity you expect before
the write, or null to skip that compare-and-set check. These
functions send both: pass changeFromQuantity per change to guard
against concurrent writes, and pass idempotencyKey in options to
make a retried call safe (a fresh UUID is used otherwise). Needs
read_inventory / write_inventory.
Values
DEFAULT_QUANTITY_NAMES
DEFAULT_QUANTITY_NAMES: Vec [
"available",
"on_hand",
"committed",
"incoming",
"reserved"
]
Functions
adjust-quantities
fn (changes: Vec): Map
fn (changes: Vec, options: Map): Map
fn (changes: Vec, options: Map, opts: Map): Map
Change quantities by a delta (inventoryAdjustQuantities). Options:
name, reason, referenceDocumentUri, idempotencyKey. Returns
the adjustment group {createdAt, reason, changes: [{name, delta, quantityAfterChange}]}.
Example
::shopify::inventory/adjust-quantities([
{inventoryItemId: "gid://shopify/InventoryItem/1", locationId: "gid://shopify/Location/1", delta: -2, changeFromQuantity: 10}
], {reason: "damaged", idempotencyKey: "damage-8841"})
build-adjust-input
fn (changes: Vec, options: Map): Map
InventoryAdjustQuantitiesInput. Each change is {inventoryItemId, locationId, delta, changeFromQuantity?}; changeFromQuantity
defaults to an explicit null. Options: name (default
"available"), reason (default "correction"),
referenceDocumentUri. Exposed for testing.
Example
input ::shopify::inventory/build-adjust-input([
{inventoryItemId: "gid://shopify/InventoryItem/1", locationId: "gid://shopify/Location/1", delta: -2}
], {reason: "damaged"})
input.name // "available"
input.reason // "damaged"
first(input.changes).changeFromQuantity // null
build-set-input
fn (quantities: Vec, options: Map): Map
InventorySetQuantitiesInput. Each quantity is {inventoryItemId, locationId, quantity, changeFromQuantity?}; changeFromQuantity
defaults to an explicit null. Options: name ("available" default,
or "on_hand"), reason (default "correction"),
referenceDocumentUri. Exposed for testing.
Example
input ::shopify::inventory/build-set-input([
{inventoryItemId: "gid://shopify/InventoryItem/1", locationId: "gid://shopify/Location/1", quantity: 12}
], {name: "on_hand"})
input.name // "on_hand"
input.reason // "correction"
first(input.quantities).quantity // 12
get-inventory-levels
fn (inventory-item-id: Str): Map?
fn (inventory-item-id: Str, options: Map): Map?
fn (inventory-item-id: Str, options: Map, opts: Map): Map?
An inventory item's levels per location: {id, sku, tracked, inventoryLevels: {nodes: [{id, location: {id, name}, quantities: [{name, quantity}]}], pageInfo}}. The variant's
inventoryItem.id is the id to pass. Options: names (quantity
names, default available/on_hand/committed/incoming/reserved),
first, after.
Example
item ::shopify::inventory/get-inventory-levels("gid://shopify/InventoryItem/1", {names: ["available"]})
map(item.inventoryLevels.nodes, %.location.name)
set-on-hand-quantities
fn (quantities: Vec): Map
fn (quantities: Vec, options: Map): Map
fn (quantities: Vec, options: Map, opts: Map): Map
Set on-hand quantities: set-quantities with name: "on_hand" (Shopify
deprecated inventorySetOnHandQuantities in favour of this).
Example
::shopify::inventory/set-on-hand-quantities([
{inventoryItemId: "gid://shopify/InventoryItem/1", locationId: "gid://shopify/Location/1", quantity: 40}
])
set-quantities
fn (quantities: Vec): Map
fn (quantities: Vec, options: Map): Map
fn (quantities: Vec, options: Map, opts: Map): Map
Set absolute quantities (inventorySetQuantities). Options as in
build-set-input plus idempotencyKey. Returns the adjustment group.
Example
group ::shopify::inventory/set-quantities([
{inventoryItemId: "gid://shopify/InventoryItem/1", locationId: "gid://shopify/Location/1", quantity: 12, changeFromQuantity: 10}
], {reason: "correction", idempotencyKey: "count-8841"})
group.changes