# Keep stock in sync

This guide keeps a store's stock in step with another system, such as a warehouse, an ERP or a second shop's point of sale.

Nepzio counts stock as the store sells, online and in the shop. Decide which system holds the true count:

- **The other system holds it:** push counts into Nepzio with `POST /v1/inventory/set`.
- **Nepzio holds it:** read Nepzio's counts with `GET /v1/inventory` and the `inventory.updated` webhook.

## Pushing counts into Nepzio

Needs a key with `write_inventory`. Name each variant by its **SKU** (or `variant_id`).

To make the count exactly what the other system says (after a stock count, say):

```bash
curl https://api.nepzio.com/v1/inventory/set \
  -H "Authorization: Bearer $NEPZIO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 3c9f..." \
  -d '{"sku": "PSH-RED", "stock": 42, "reason": "Warehouse count"}'
```

To add or take away (stock received, items damaged):

```bash
curl https://api.nepzio.com/v1/inventory/adjust \
  -H "Authorization: Bearer $NEPZIO_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 8a21..." \
  -d '{"sku": "PSH-RED", "delta": 10, "reason": "Received from supplier"}'
```

- **No lost sales:** both work out the change at the moment it is saved, under a lock, so a sale made at the same moment isn't lost.
- **Never below zero:** a change that would take stock below zero is refused with `insufficient_stock`.
- **On the record:** each change appears in the store's stock history with your reason, credited to your key.
- **Safe to retry:** send an [Idempotency-Key](/idempotency) with each change.

## Reading Nepzio's counts

Needs `read_inventory`. Each variant has one stock level:

```json
{
  "object": "inventory_level",
  "variant_id": "...",
  "product_id": "...",
  "sku": "PSH-RED",
  "tracked": true,
  "stock": 42,
  "reserved": 3,
  "available": 39,
  "updated_at": "2026-11-10T08:15:00Z"
}
```

- **`stock`:** units on hand.
- **`reserved`:** units held by orders not yet shipped.
- **`available`:** what can be sold now (stock less reserved). It is `null` for a variant whose quantity isn't tracked, meaning there is no limit.

Fetch only some variants with `?sku=PSH-RED,PSH-BLUE` (up to 100), or what changed with `?updated_at_min=...`. Listen for `inventory.updated` to hear about changes as they happen. Several changes within a few seconds arrive as one event.
