Sifr Wahid Developers

API reference / Inventory

Adjust stock

Change stock levels in one batch (all items apply or none)

POST https://s.zo.sa/api/public/v1/inventory/adjustments
Scope inventory.read_writeIdempotency-Key required

The 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

NameTypeRequiredDescription
Idempotency-Keystringrequired1 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

application/json required

  • itemsarray of objectsrequired
    Applied all together or not at all, in the order sent (two items for the same variant and branch see each other's change).
    1 to 100 items
    6 fields

    One of sku or variant_id is required; with both, they must name the same variant.

    • skustringone of
      The variant's exact SKU. Either sku or variant_id is required; with both, the variant must match both.
      Up to 64 characters
    • variant_idintegerone of
    • branch_idinteger
      One of the store's branches (GET /branches); the default branch when left out.
    • modestringrequired
      increment adds quantity, decrement takes it away (never below zero: 409 insufficient_stock), set makes the branch's level exactly quantity.
      One of increment, decrement, set
    • quantityintegerrequired
      At least 1 for increment and decrement.
      0 to 1000000
    • notestringnullable
      Saved on the stock movement.
      Up to 255 characters

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.

Response 200
{
  "data": [
    {
      "variant_id": 811,
      "branch_id": 1,
      "quantity_after": 35
    }
  ]
}

Example. The default branch had 30; five came in.

Responses

200One result per item, in the order sent.
Response schema
  • dataarray of objectsrequired
    3 fields
    • variant_idintegerrequired
    • branch_idintegerrequired
    • quantity_afterintegerrequired
      The branch's level after this item.
401Missing, unknown, revoked or expired key.

An error object: {"error": {"code", "message", "fields"}}.

402The store's plan does not include this feature (error code feature_locked, with the feature and the plan that has it). Every operation answers it with feature public_api when the key's store is not on the Pro plan.

An error object: {"error": {"code", "message", "fields"}}.

403The key lacks the scope (code insufficient_scope, naming it in scope), the caller's address is not allowed (ip_not_allowed), or the store is suspended (store_suspended: reads stay allowed, every write answers this).

An error object: {"error": {"code", "message", "fields"}}.

409insufficient_stock (a decrement would go below zero; fields names items.N.quantity and available gives the quantity on hand; nothing was applied), or duplicate_request (the same Idempotency-Key is still running).

An error object: {"error": {"code", "message", "fields"}}.

422validation_failed (fields names items.N.sku or items.N.variant_id for a variant this store does not have, items.N.branch_id for a branch it does not have), or stock_managed_by_codes (a digital card product; fields names the item). Nothing was applied.

An error object: {"error": {"code", "message", "fields"}}.

429Too many requests (code rate_limited); see Retry-After.

An error object: {"error": {"code", "message", "fields"}}.