Store Hugs Developers

Inventory

Stock levels for up to 100 products in one call, each named by id or SKU; all or nothing.

Call it on the client itself: $admin->setInventory(). It needs the inventory:write scope. To change a product's other fields, use products.

Set stock

$admin->setInventory(array $items, string|false|null $idempotencyKey = null): array

Sets stock for up to 100 products, each named by productId or sku. A stockQuantity turns stock tracking on, a stockStatus (in_stock or out_of_stock) turns it off. All or nothing: an unknown product, or a sku several products share, fails the call with an items.N error (name such a product by productId). Scope: inventory:write.

Parameters

Parameter Type
$items array A list of items, each with the fields below (without items[].).
$idempotencyKey string|false|null Your own Idempotency-Key, or false for none. One is made for you when null.

Request fields

The SDK sends the list you pass as the body's items:

FieldTypeDescription
items requiredarray of InventoryItemInputAt most 100 items.
items[].productIdinteger or null
items[].skustring or nullAt most 255 characters.
items[].stockQuantityinteger or nullTurns stock tracking on. At least 0. At most 99999999.
items[].stockStatusstring or nullTurns stock tracking off. One of in_stock, out_of_stock.

Returns

The products' stock after the change.

FieldTypeDescription
[].idinteger
[].skustring or null
[].manageStockboolean
[].stockQuantityinteger or null
[].stockStatusstring or null
[].updatedAtstring (date-time) or null

Errors

StatusWhen
401invalid_api_key: no active Admin key in Authorization: Bearer.
403admin_key_in_browser (an Origin header was sent), ip_not_allowed, plan_required(the shop's plan lacks the Integration API, or the feature the endpoint needs), orinsufficient_scope.
409idempotency_in_progress: a request with this Idempotency-Key is still running. Retry with the same key after Retry-After seconds; the first answer is then replayed.
422Validation errors ({ message, errors }), or an idempotency refusal(idempotency_key_reused, idempotency_key_invalid).
429Rate limited.

Example

$admin->setInventory([
    ['sku' => 'MUG-01', 'stockQuantity' => 40],
    ['productId' => 12, 'stockStatus' => 'out_of_stock'],
]);