pify/inventory

Available stock per inventory item per location.

A write is a compare-and-set: each quantity carries the value read just before, and Shopify refuses the write when its value moved since. The request shape depends on the version. Before 2026-01 the compare value is compareQuantity. From 2026-01 it is changeFromQuantity, sent with an @idempotent key, which 2026-04 makes mandatory. The client’s version picks the shape.

Types

Up to max_batch_size quantities for one location. Only batches builds one, so no call can pass Shopify’s array limit.

pub opaque type Batch

One line of the adjustment Shopify recorded.

pub type Change {
  Change(name: String, delta: Int)
}

Constructors

  • Change(name: String, delta: Int)

The level of one item at one location.

pub type Level {
  Level(inventory_item_id: String, state: LevelState)
}

Constructors

  • Level(inventory_item_id: String, state: LevelState)
pub type LevelState {
  LevelStateActive(available: Int)
  LevelStateInactive(available: Int)
  LevelStateNotStocked
}

Constructors

  • LevelStateActive(available: Int)

    Stocked at the location, with its available quantity.

  • LevelStateInactive(available: Int)

    Stocked once and then taken off the location. From 2026-04 activate keeps this quantity, so the first write after it compares against it. Earlier versions read such a level as not stocked.

  • LevelStateNotStocked

    No level at the location. activate stocks the item at zero.

The available quantity to write for one item. change_from is the quantity read just before; None writes without the compare.

pub type Quantity {
  Quantity(
    inventory_item_id: String,
    available: Int,
    change_from: option.Option(Int),
  )
}

Constructors

  • Quantity(
      inventory_item_id: String,
      available: Int,
      change_from: option.Option(Int),
    )

The request shape a version takes.

pub type Shape {
  ShapeCompareQuantity
  ShapeIdempotent
}

Constructors

  • ShapeCompareQuantity

    Before 2026-01: compareQuantity on each quantity and no key. A batch with a quantity that has no compare value sends ignoreCompareQuantity: true instead.

  • ShapeIdempotent

    From 2026-01: changeFromQuantity on each quantity, null when there is no compare value, and an @idempotent key.

Values

pub fn activate(
  client: pify.Client,
  inventory_item_id inventory_item_id: String,
  location_id location_id: String,
  idempotency_key idempotency_key: String,
) -> effect.Effect(Result(Nil, error.ShopifyError), key)

Stock an item at a location that does not carry it yet. Before 2026-04 the level starts at zero; from 2026-04 an inactive level keeps its quantity.

pub fn activate_mutation(shape: Shape) -> String
pub fn activate_variables(
  shape: Shape,
  inventory_item_id: String,
  location_id: String,
  idempotency_key: String,
) -> json.Json
pub fn batch_quantities(batch: Batch) -> List(Quantity)
pub fn batches(quantities: List(Quantity)) -> List(Batch)
pub const idempotent_since: api_version.ApiVersion

From this version the writes take changeFromQuantity and an idempotency key.

pub const inactive_levels_since: api_version.ApiVersion

From this version a level read returns inactive levels on request, and activate keeps the quantity an inactive level holds.

pub fn is_stale(error: error.ShopifyError) -> Bool

Shopify’s quantity moved after it was read. Read the level again and retry on a later run.

pub fn levels(
  client: pify.Client,
  location_id location_id: String,
  inventory_item_ids inventory_item_ids: List(String),
) -> effect.Effect(Result(List(Level), error.ShopifyError), key)

The available quantity of each item at one location, max_batch_size items per call. Ids that match no inventory item are left out.

pub fn levels_decoder() -> decode.Decoder(List(Level))
pub fn levels_query(version: api_version.ApiVersion) -> String

From 2026-04 the read asks for inactive levels too, and whether each level is active.

pub fn levels_variables(
  location_id: String,
  ids: List(String),
) -> json.Json
pub const max_batch_size: Int
pub fn set_available(
  client: pify.Client,
  location_id location_id: String,
  batch batch: Batch,
  reference_document_uri reference_document_uri: option.Option(
    String,
  ),
  idempotency_key idempotency_key: String,
) -> effect.Effect(Result(List(Change), error.ShopifyError), key)

Set the available quantity with reason correction. A stale compare value fails the whole call; is_stale says so. Derive one idempotency key per batch and send the same key when retrying that batch; Shopify keeps a key for 24 hours. IDEMPOTENCY_CONCURRENT_REQUEST says the first attempt is still running, and the retry must reuse the same key.

pub fn set_available_mutation(shape: Shape) -> String
pub fn set_available_variables(
  shape shape: Shape,
  location_id location_id: String,
  batch batch: Batch,
  reference_document_uri reference_document_uri: option.Option(
    String,
  ),
  idempotency_key idempotency_key: String,
) -> json.Json
pub fn shape(version: api_version.ApiVersion) -> Shape
pub const stale_codes: List(String)

The userErrors codes of a compare value that differs from Shopify’s quantity: from 2026-01 and before it.

✨ Search Document