# Common scenarios

Most integrations are one of four kinds. For each one below: which way the data flows, which methods
you need, which webhooks to subscribe to, and how to reconcile. All of them start from
[Quick start](https://docs.bito.uz/en/guide/quick-start.md) and [Calling the API](https://docs.bito.uz/en/guide/api.md).

::: tip Two words, two different things
`sale-order` is a customer's **order**, not yet a sale. `trade` is **the sale itself**. An order from
an online shop is written as a `sale-order`.
:::

## 1. Storefront or marketplace: catalog out of Bito

Products, prices and stock flow from Bito to a website or a marketplace. Step by step:
[the catalog sync recipe](https://docs.bito.uz/en/guide/recipes/catalog-sync.md).

| Step | Method |
|---|---|
| Initial full load | [`POST /product/get-paging`](https://docs.bito.uz/en/api/product.md#post-product-get-paging), with `page` and `limit` |
| Changes only | The same method, `updated_at` = your last sync time |
| Deleted | [`GET /product/get-deleted`](https://docs.bito.uz/en/api/product.md#get-product-get-deleted) |
| Prices | [`POST /price/items/get-paging`](https://docs.bito.uz/en/api/price.md#post-price-items-get-paging) |
| Stock per warehouse | [`POST /product-warehouse/get-paging`](https://docs.bito.uz/en/api/product-warehouse.md#post-product-warehouse-get-paging), with `updated_at` |

In stock rows, `amount` is the quantity available to sell: reservations and goods in transit are not in
it. Webhooks: `products.*`, `productPrices.*`. They cut the number of calls, but they do not replace a
scheduled full re-read: bulk operations emit no webhooks.

## 2. Online order into Bito

A website, bot or courier app takes an order, and it has to show up in Bito. Step by step:
[the online order recipe](https://docs.bito.uz/en/guide/recipes/online-order.md).

| Step | Method |
|---|---|
| Find the customer | [`GET /customer/get-by-phone-number`](https://docs.bito.uz/en/api/customer.md#get-customer-get-by-phone-number) |
| Not found — create | [`POST /customer/create`](https://docs.bito.uz/en/api/customer.md#post-customer-create) |
| Create the order | [`POST /sale-order/create`](https://docs.bito.uz/en/api/sale-order.md#post-sale-order-create) |

Store the `_id` from the response next to your own order: if no response came back, read to check
whether the order exists before retrying. To follow the order's status, subscribe to the
`saleOrders.status_change` webhook.

## 3. Warehouse: movements from an accounting system

An accounting or ERP system writes stock movements into Bito.

| Document | Reference |
|---|---|
| Purchase | [Purchase](https://docs.bito.uz/en/api/purchase.md) |
| Income | [Income](https://docs.bito.uz/en/api/income.md) |
| Internal transfer | [Internal transfer](https://docs.bito.uz/en/api/internal-transfer.md) |
| Write-off | [Write-off](https://docs.bito.uz/en/api/write-off.md) |

Before every `create`, check on your side whether the document was already written: these methods are
not idempotent, and a retried call creates a second document.

## 4. BI and analytics: read only

Sales, cash flow and reports go out to a BI tool or 1C. Step by step:
[the export recipe](https://docs.bito.uz/en/guide/recipes/sales-export.md).

| Data | Method |
|---|---|
| Sales | [`POST /trade/get-paging`](https://docs.bito.uz/en/api/trade.md#post-trade-get-paging), with `updated_at` |
| Cash flow | [`POST /transaction/get-paging`](https://docs.bito.uz/en/api/transaction.md#post-transaction-get-paging) |
| Ready-made reports | [Sales reports](https://docs.bito.uz/en/api/report-sales.md), [finance reports](https://docs.bito.uz/en/api/report-finance.md) |

Webhooks: `trades.*`, `transactions.*`.

## What the API does not have

None of these exist, and there is no hidden method that works around them.

| Missing | Instead |
|---|---|
| An `idempotency-key` header | Before retrying a write, read to check whether it already exists |
| Webhook retries, ordering, and events from bulk operations | Treat a webhook as a signal to re-read, and reconcile with scheduled full reads — [webhooks](https://docs.bito.uz/en/guide/webhooks.md) |

Something not working? Start with the [symptom map](https://docs.bito.uz/en/guide/faq.md#symptoms).
