# Recipe: stock and prices

Moving the product cards is the [catalog sync recipe](https://docs.bito.uz/en/guide/recipes/catalog-sync.md). This page is the next step:
reading stock and prices correctly and not letting them go stale in your catalog.

**Permissions needed:** `price`, `product_stock`, `warehouse`.

## 1. Pick the warehouses and price list

```http
GET /organization/get-all
```

```json
POST /warehouse/get-all

{ "organization_id": "6712f0a9c4d1e87b3a0f9911", "status": "active" }
```

```http
GET /price/get-all?type=sale
```

Keep in your settings which warehouses the storefront sells from and which price list it shows. A price
list's currency is its `currency_id`.

## 2. Read stock

```json
POST /product-warehouse/get-paging

{ "page": 1, "limit": 200, "organization_id": "6712f0a9c4d1e87b3a0f9911" }
```

`page` and `limit` are required, `limit` up to 200. Page until `page * limit >= data.total`. Each row is
a product × warehouse:

```json
{
    "_id": "6712f0a9c4d1e87b3a0f9944",
    "product_id": "6712f0a9c4d1e87b3a0f9933",
    "warehouse_id": "6712f0a9c4d1e87b3a0f9955",
    "organization_id": "6712f0a9c4d1e87b3a0f9911",
    "amount": 12,
    "booked": 2,
    "in_transit": 0,
    "on_the_way": 50,
    "in_trash": 1,
    "updated_at": "2026-11-05T09:12:00.000Z"
}
```

| Field | Meaning |
|---|---|
| `amount` | Available to sell. This is what your storefront shows |
| `booked` | Reserved |
| `in_transit` | In a transfer: left the sending warehouse, not yet received |
| `on_the_way` | Purchased, not yet received into stock |
| `in_trash` | Written off as defective |

`amount` includes none of the other four — neither add nor subtract them. Filters: `organization_id`,
`product_ids` (up to 500), `updated_at`. There is no warehouse filter — pick your `warehouse_id`s on
your side. When there is no row for a product × warehouse, treat its stock as `0`.

Two other sources are not for this job: `organizations[].amount` in `product/get-paging` is a summary
refreshed in the background, and `product-stock` holds batch-level rows.

## 3. Read prices

```json
POST /price/items/get-paging

{ "page": 1, "limit": 200, "organization_id": "6712f0a9c4d1e87b3a0f9911", "price_id": "6712f0a9c4d1e87b3a0f9966" }
```

Send **both** `organization_id` and `price_id` — otherwise rows of other organizations or price lists
are mixed into the response. Extra filters: `product_id`, `search` (name, SKU, barcode).

```json
{
    "_id": "6712f0a9c4d1e87b3a0f9977",
    "price_id": "6712f0a9c4d1e87b3a0f9966",
    "product": { "_id": "6712f0a9c4d1e87b3a0f9933", "name": "Espresso" },
    "amount": 45000,
    "min_price": 40000,
    "max_price": 50000
}
```

Here `amount` is the **price**, not stock. A product missing from the list has no price set in that
price list.

## 4. Keep the external catalog in step

| What | How | How often |
|---|---|---|
| Stock, incremental | `product-warehouse/get-paging` + `updated_at` | Every 5–15 minutes |
| Stock, full | The same method unfiltered, replace your values | Once a day |
| Prices | All of `price/items/get-paging`: there is **no** `updated_at` filter | On a schedule |

- For `updated_at`, store the time you **started** paging, not the time you finished: rows that changed
  while you were reading then come again next time.
- Upsert rows by `product_id` + `warehouse_id`: receiving a row twice changes nothing.
- Do not track price changes with the `updated_at` filter of `product/get-paging`: it filters the
  product record, and prices live in separate records.

## 5. Webhooks

- There is **no** event for stock (`product-warehouse`) — poll it.
- `productPrices.create`, `productPrices.update` and `productPrices.delete` say a price row changed.
  The `id` in the message is the `_id` of a `price/items/get-paging` row, not a product id. So keep an
  `_id` → `product._id` map; when an unknown `id` arrives, re-read the list.

Webhook delivery is not guaranteed and bulk operations send none ([webhooks](https://docs.bito.uz/en/guide/webhooks.md)) — you still
need a scheduled full reconcile.
An app that declares `required_permissions` cannot call the `webhook/*` methods — it can only poll.

## Errors

| Response | Cause |
|---|---|
| `400` validation | `page` or `limit` is missing, an id is wrong, or `limit` is above 200 on `product-warehouse` |
| `403`, `code: 10003` | One of the permissions was not approved; `data` names it |

## Methods

| Step | Method |
|---|---|
| Organization | [`GET /organization/get-all`](https://docs.bito.uz/en/api/organization.md) |
| Warehouses | [`POST /warehouse/get-all`](https://docs.bito.uz/en/api/warehouse.md#post-warehouse-get-all) |
| Price lists | [`GET /price/get-all`](https://docs.bito.uz/en/api/price.md#get-price-get-all) |
| Stock | [`POST /product-warehouse/get-paging`](https://docs.bito.uz/en/api/product-warehouse.md#post-product-warehouse-get-paging) |
| Prices | [`POST /price/items/get-paging`](https://docs.bito.uz/en/api/price.md#post-price-items-get-paging) |
