# Inventory

> Stock per variant and location, adjusted or counted as the Inventory page does.

| Operation | Method and path | Scope |
|---|---|---|
| [List stock locations](https://docs.kaizenaflow.com/reference/admin-api/inventory#inventory-locations) | `GET /inventory/locations` | [`inventory:read`](https://docs.kaizenaflow.com/reference/scopes#inventory-read) |
| [List stock levels](https://docs.kaizenaflow.com/reference/admin-api/inventory#inventory-levels) | `GET /inventory/levels` | [`inventory:read`](https://docs.kaizenaflow.com/reference/scopes#inventory-read) |
| [Adjust stock](https://docs.kaizenaflow.com/reference/admin-api/inventory#inventory-adjust) | `POST /inventory/adjust` | [`inventory:write`](https://docs.kaizenaflow.com/reference/scopes#inventory-write) |
| [Set stock to a count](https://docs.kaizenaflow.com/reference/admin-api/inventory#inventory-set) | `POST /inventory/set` | [`inventory:write`](https://docs.kaizenaflow.com/reference/scopes#inventory-write) |

## List stock locations {#inventory-locations}

`GET https://kaizenaflow.com/api/admin/v1/inventory/locations`

The store's stock locations, in the order stock is taken from them.

- **Operation:** `inventory.locations`
- **Scope:** [`inventory:read`](https://docs.kaizenaflow.com/reference/scopes#inventory-read), or [`inventory:write`](https://docs.kaizenaflow.com/reference/scopes#inventory-write), which reads too
- **Answers:** `200`, the answer under `data`.

### Answer {#inventory-locations-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].id` | string (uuid) |   |
| `data[].name` | string |   |
| `data[].country` | string or null |   |
| `data[].active` | boolean |   |
| `data[].priority` | integer | The order stock is taken in: lowest first. |

### Errors {#inventory-locations-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#inventory-locations-example}

**curl**

```shell
curl 'https://kaizenaflow.com/api/admin/v1/inventory/locations' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/inventory/locations", {
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
  },
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/inventory/locations",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## List stock levels {#inventory-levels}

`GET https://kaizenaflow.com/api/admin/v1/inventory/levels`

Stock per variant and location, the most recently changed first, with what can be sold now.

- **Operation:** `inventory.levels`
- **Scope:** [`inventory:read`](https://docs.kaizenaflow.com/reference/scopes#inventory-read), or [`inventory:write`](https://docs.kaizenaflow.com/reference/scopes#inventory-write), which reads too
- **Answers:** `200`, a page: the rows under `data`, and `next` for the page after.
- **Pages:** at most 100 rows, 50 when `limit` is left out; give an answer's `next` as `?after=` for the page after.

### Query parameters {#inventory-levels-query}

| Name | Type | Required | Description |
|---|---|---|---|
| `limit` | integer, 1 to 100 | no | Rows a page holds, at most 100; 50 when left out. A larger number gives 100. |
| `after` | string, at most 200 characters | no | The `next` cursor of the page before; the first page when left out. |
| `updated_after` | string (date-time) | no | Only what was made or changed after this time (ISO 8601 with its offset), for incremental sync. |
| `variant_id` | string (uuid) | no | Only this variant. |
| `location_id` | string (uuid) | no | Only this location. |

### Answer {#inventory-levels-answer}

| Field | Type | Description |
|---|---|---|
| `data` | list of objects |   |
| `data[].variant_id` | string (uuid) |   |
| `data[].location_id` | string (uuid) |   |
| `data[].sku` | string or null |   |
| `data[].on_hand` | integer |   |
| `data[].available` | number or null | What can be sold now across the store's locations: on hand less what open orders hold. |
| `data[].can_buy` | boolean or null |   |
| `data[].updated_at` | string (date-time) |   |
| `next` | string or null | The cursor of the next page, given as `?after=`; null on the last page. |

### Errors {#inventory-levels-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#inventory-levels-example}

**curl**

```shell
curl 'https://kaizenaflow.com/api/admin/v1/inventory/levels' \
  -H "Authorization: Bearer $KAIZENA_TOKEN"
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/inventory/levels", {
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
  },
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/inventory/levels",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
    },
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Adjust stock {#inventory-adjust}

`POST https://kaizenaflow.com/api/admin/v1/inventory/adjust`

Adds or takes away units per variant and location, as the Inventory page does, recorded with source `api`. Each row stands alone: one refused or in conflict never stops the others.

- **Operation:** `inventory.adjust`
- **Scope:** [`inventory:write`](https://docs.kaizenaflow.com/reference/scopes#inventory-write)
- **Answers:** `200`, the answer under `data`.
- **Once only:** with an [`Idempotency-Key`](https://docs.kaizenaflow.com/reference/admin-api#idempotency) header.

### Body {#inventory-adjust-body}

JSON, with `Content-Type: application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `reason` | string | no, default `"correction"` | Why: one of received, correction, count, damaged, lost, promotion; correction when left out. |
| `note` | string, at most 200 characters or null | no, default `null` |   |
| `rows` | list of objects, 1 to 250 items | yes |   |
| `rows[].variant_id` | string (uuid) | no | The variant, by its id. |
| `rows[].sku` | string, 1 to 64 characters | no | The variant, by its SKU. |
| `rows[].location_id` | string (uuid) | yes |   |
| `rows[].delta` | integer, -1,000,000 to 1,000,000 | yes | Units to add (negative to take away). |

### Answer {#inventory-adjust-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.written` | integer |   |
| `data.unchanged` | integer |   |
| `data.conflicts` | integer |   |
| `data.refused` | integer |   |
| `data.failed` | integer |   |
| `data.rows` | list of objects |   |
| `data.rows[].variant_id` | string (uuid) |   |
| `data.rows[].location_id` | string (uuid) |   |
| `data.rows[].outcome` | one of `written`, `unchanged`, `conflict`, `refused`, `failed` | conflict: the level moved since `compare` (or since it was read) and nothing was written for the row. |
| `data.rows[].before` | integer or null |   |
| `data.rows[].after` | integer or null |   |
| `data.rows[].problem` | string or null | For a row not written: why, in a sentence. |

### Errors {#inventory-adjust-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 409 | [`conflict`](https://docs.kaizenaflow.com/reference/errors#conflict) | Nothing was done: it clashes with how things are now (nothing left to send), or an `Idempotency-Key` is in use or was used for another request. |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#inventory-adjust-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/inventory/adjust' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"rows":[{"variant_id":"a9012318-1d02-4424-9f91-3c4f58cc1841","location_id":"316a8630-7456-426c-a5fd-70b56f8cd80d","delta":1}]}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/inventory/adjust", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "rows": [
      {
        "variant_id": "a9012318-1d02-4424-9f91-3c4f58cc1841",
        "location_id": "316a8630-7456-426c-a5fd-70b56f8cd80d",
        "delta": 1
      }
    ]
  }),
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/inventory/adjust",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "rows": [
            {
                "variant_id": "a9012318-1d02-4424-9f91-3c4f58cc1841",
                "location_id": "316a8630-7456-426c-a5fd-70b56f8cd80d",
                "delta": 1,
            },
        ],
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

## Set stock to a count {#inventory-set}

`POST https://kaizenaflow.com/api/admin/v1/inventory/set`

Sets levels to what was counted. A level that moved since the count (`compare`) is a conflict and is never overwritten.

- **Operation:** `inventory.set`
- **Scope:** [`inventory:write`](https://docs.kaizenaflow.com/reference/scopes#inventory-write)
- **Answers:** `200`, the answer under `data`.
- **Once only:** with an [`Idempotency-Key`](https://docs.kaizenaflow.com/reference/admin-api#idempotency) header.

### Body {#inventory-set-body}

JSON, with `Content-Type: application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `reason` | string | no, default `"count"` | Why: one of received, correction, count, damaged, lost, promotion; count when left out. |
| `note` | string, at most 200 characters or null | no, default `null` |   |
| `rows` | list of objects, 1 to 250 items | yes |   |
| `rows[].variant_id` | string (uuid) | no | The variant, by its id. |
| `rows[].sku` | string, 1 to 64 characters | no | The variant, by its SKU. |
| `rows[].location_id` | string (uuid) | yes |   |
| `rows[].on_hand` | integer, 0 to 10,000,000 | yes | The level as counted. |
| `rows[].compare` | integer, -10,000,000 to 10,000,000 | no | The level the count was made against: a level that moved since is a conflict, never overwritten. The level now when left out. |

### Answer {#inventory-set-answer}

| Field | Type | Description |
|---|---|---|
| `data` | object |   |
| `data.written` | integer |   |
| `data.unchanged` | integer |   |
| `data.conflicts` | integer |   |
| `data.refused` | integer |   |
| `data.failed` | integer |   |
| `data.rows` | list of objects |   |
| `data.rows[].variant_id` | string (uuid) |   |
| `data.rows[].location_id` | string (uuid) |   |
| `data.rows[].outcome` | one of `written`, `unchanged`, `conflict`, `refused`, `failed` | conflict: the level moved since `compare` (or since it was read) and nothing was written for the row. |
| `data.rows[].before` | integer or null |   |
| `data.rows[].after` | integer or null |   |
| `data.rows[].problem` | string or null | For a row not written: why, in a sentence. |

### Errors {#inventory-set-errors}

| Status | Code | When |
|---|---|---|
| 401 | [`unauthorized`](https://docs.kaizenaflow.com/reference/errors#unauthorized) | No valid token in `Authorization: Bearer kf_…`, or one that was revoked. |
| 403 | [`forbidden`](https://docs.kaizenaflow.com/reference/errors#forbidden) | The token does not hold the scope the operation needs, or its owner does not hold the staff permission it needs in the store now (a store that is not open, as in the admin, keeps open only its orders, customers, reports and the owner's own pages such as its webhooks; its products, discounts, website and settings, read or changed, are refused); the message names which. |
| 409 | [`conflict`](https://docs.kaizenaflow.com/reference/errors#conflict) | Nothing was done: it clashes with how things are now (nothing left to send), or an `Idempotency-Key` is in use or was used for another request. |
| 422 | [`invalid`](https://docs.kaizenaflow.com/reference/errors#invalid) | Nothing was done: a body, query or cursor that is not as described, or a check of the screen it goes through; the message says what. |
| 429 | [`rate_limited`](https://docs.kaizenaflow.com/reference/errors#rate-limited) | More calls than the budget allows; `Retry-After` says how many seconds to wait. |
| 500 | [`failed`](https://docs.kaizenaflow.com/reference/errors#failed) | Something went wrong on our side; nothing more was done. It is safe to try again. |

### Example request {#inventory-set-example}

**curl**

```shell
curl -X POST 'https://kaizenaflow.com/api/admin/v1/inventory/set' \
  -H "Authorization: Bearer $KAIZENA_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"rows":[{"variant_id":"a9012318-1d02-4424-9f91-3c4f58cc1841","location_id":"316a8630-7456-426c-a5fd-70b56f8cd80d","on_hand":1}]}'
```

**JavaScript**

```javascript
const response = await fetch("https://kaizenaflow.com/api/admin/v1/inventory/set", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KAIZENA_TOKEN}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "rows": [
      {
        "variant_id": "a9012318-1d02-4424-9f91-3c4f58cc1841",
        "location_id": "316a8630-7456-426c-a5fd-70b56f8cd80d",
        "on_hand": 1
      }
    ]
  }),
});
const answer = await response.json();
```

**Python**

```python
import json
import os
import urllib.request

request = urllib.request.Request(
    "https://kaizenaflow.com/api/admin/v1/inventory/set",
    method="POST",
    headers={
        "Authorization": "Bearer " + os.environ["KAIZENA_TOKEN"],
        "Content-Type": "application/json",
    },
    data=json.dumps({
        "rows": [
            {
                "variant_id": "a9012318-1d02-4424-9f91-3c4f58cc1841",
                "location_id": "316a8630-7456-426c-a5fd-70b56f8cd80d",
                "on_hand": 1,
            },
        ],
    }).encode(),
)
with urllib.request.urlopen(request) as response:
    answer = json.load(response)
```

---

https://docs.kaizenaflow.com/reference/admin-api/inventory · made from the API contract 1.57
