Adjust stock
Change stock levels in one batch (all items apply or none)
https://s.zo.sa/api/public/v1 /inventory/adjustments inventory.read_writeIdempotency-Key requiredThe Idempotency-Key header is required here (422 validation_failed without it). Each change is saved as a stock movement with reason api. A digital card product's stock is its unsold codes and cannot be changed here (422 stock_managed_by_codes). A decrement never clamps: if any item would take a level below zero the whole batch is refused with 409 insufficient_stock, naming the item in fields and the quantity on hand in available.
Request
Headers
| Name | Type | Required | Description |
|---|---|---|---|
Idempotency-Key | string | required | 1 to 120 visible ASCII characters. A write sent again with the same key runs once; the retry gets the first answer back with the header Idempotent-Replayed: true. Use a new key for each new write. 1 to 120 characters |
Request body
itemsarray of objectsrequiredApplied all together or not at all, in the order sent (two items for the same variant and branch see each other's change).6 fields
One of
skuorvariant_idis required; with both, they must name the same variant.skustringone ofThe variant's exact SKU. Either sku or variant_id is required; with both, the variant must match both.variant_idintegerone ofbranch_idintegerOne of the store's branches (GET /branches); the default branch when left out.modestringrequiredincrement adds quantity, decrement takes it away (never below zero: 409 insufficient_stock), set makes the branch's level exactly quantity.quantityintegerrequiredAt least 1 for increment and decrement.notestringnullableSaved on the stock movement.
cURL
curl -sS -X POST "https://s.zo.sa/api/public/v1/inventory/adjustments" \
-H "Authorization: Bearer $ZO_API_KEY" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: odoo-move-48213" \
-d '{
"items": [
{
"sku": "TSHIRT-BLUE-M",
"mode": "increment",
"quantity": 5,
"note": "Goods received, PO 7731"
}
]
}'JavaScript
const response = await fetch('https://s.zo.sa/api/public/v1/inventory/adjustments', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.ZO_API_KEY}`,
Accept: 'application/json',
'Content-Type': 'application/json',
'Idempotency-Key': 'odoo-move-48213',
},
body: JSON.stringify({
"items": [
{
"sku": "TSHIRT-BLUE-M",
"mode": "increment",
"quantity": 5,
"note": "Goods received, PO 7731"
}
]
}),
});
console.log(response.status, await response.json());PHP
<?php
$ch = curl_init('https://s.zo.sa/api/public/v1/inventory/adjustments');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('ZO_API_KEY'),
'Accept: application/json',
'Content-Type: application/json',
'Idempotency-Key: odoo-move-48213',
],
CURLOPT_POSTFIELDS => json_encode([
'items' => [
[
'sku' => 'TSHIRT-BLUE-M',
'mode' => 'increment',
'quantity' => 5,
'note' => 'Goods received, PO 7731',
],
],
]),
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
echo $status, PHP_EOL, $body, PHP_EOL;Python
import os
import requests
response = requests.post(
"https://s.zo.sa/api/public/v1/inventory/adjustments",
headers={
"Authorization": f"Bearer {os.environ['ZO_API_KEY']}",
"Accept": "application/json",
"Idempotency-Key": "odoo-move-48213",
},
json={
"items": [
{
"sku": "TSHIRT-BLUE-M",
"mode": "increment",
"quantity": 5,
"note": "Goods received, PO 7731",
},
],
},
timeout=30,
)
print(response.status_code, response.json())Five more on the default branch, with the movement number as the key.
{
"data": [
{
"variant_id": 811,
"branch_id": 1,
"quantity_after": 35
}
]
}Example. The default branch had 30; five came in.
Responses
Response schema
dataarray of objectsrequired3 fields
variant_idintegerrequiredbranch_idintegerrequiredquantity_afterintegerrequiredThe branch's level after this item.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.
An error object: {"error": {"code", "message", "fields"}}.