Skip to content
View as Markdown

Recipe: external sale ​

The sale has already happened at your till or on a marketplace, and it has to show up in Bito under Sale › Sales, in stock and in the cashbox. That is a trade. For an order that is not sold yet, see the online order recipe.

Permissions needed: sale_create, sale, employee, currency, payment_methods, product_stock; customer, customer_create if you write customers; sale_update for refunds. organization/get-all is always allowed.

1. Collect the ids ​

Fetch them once and map them to your own values:

WhatMethod
organization_id and currencyGET /organization/get-all, GET /currency/get-by-id/{id}
responsible_id — the sellerPOST /employee/get-paging
Payment methodsGET /payment-method/get-all
Product, warehouse, stockPOST /product-warehouse/get-paging

If you need a customer, find or create one as in steps 2–3 of the online order recipe.

2. First check it is not recorded yet ​

trade/create is not idempotent. Put your system's sale number in code and search for it before every send (especially a retry):

json
POST /trade/get-paging

{ "page": 1, "limit": 20, "search": "MP-10482" }

search matches part of code, number and uuid, so check yourself that code is an exact match. Bito does not enforce a unique code. Do not send one sale from two processes in parallel.

3. Record the sale ​

json
POST /trade/create

{
    "code": "MP-10482",
    "organization_id": "6712f0a9c4d1e87b3a0f9911",
    "responsible_id": "6712f0a9c4d1e87b3a0f9944",
    "customer_id": "6712f0a9c4d1e87b3a0f9922",
    "state": "done",
    "date": "2026-11-30T14:25:00+05:00",
    "currency": { "_id": "6712f0a9c4d1e87b3a0f9955", "name": "UZS", "value": 1 },
    "products": [
        {
            "product_id": "6712f0a9c4d1e87b3a0f9933",
            "warehouse_id": "6712f0a9c4d1e87b3a0f9966",
            "amount": 2,
            "price": 45000
        }
    ],
    "payments": [
        {
            "amount": 90000,
            "payment_method": { "_id": "6712f0a9c4d1e87b3a0f9977", "name": "Card" },
            "currency": { "_id": "6712f0a9c4d1e87b3a0f9955", "name": "UZS", "value": 1 }
        }
    ],
    "note": "Marketplace #10482"
}

Required: organization_id, responsible_id, state, currency (_id, name, value), payments ([] when nothing was paid) and at least one products line (product_id, amount, price).

FieldRule
statedone for a completed sale. Other states: lifecycle
priceUnit price — the one actually sold at
Line warehouse_idWhen left out, the organization's main warehouse
dateWhen left out, now. A future date is rejected (10031); a past date may be disabled in sale settings (149030)
currency.valueA required number; the server sets the rate itself
payments[]Several payments are allowed (cash + card). For a payment in another currency, amount is in that currency and paid in the sale currency; without paid the server converts at the current rate
CashboxCannot be chosen: money goes to the organization cashbox of the user the call runs as (the owner, or the user_id header)

Cashbox session

If the organization requires a cashbox session, trade/create and trade/refund return code: 236014: these methods do not accept cashbox_session_id.

4. Check the response ​

Keep _id, number, total_to_pay and debt from data. The server computes total_to_pay: a tax, a promotion or the minimum price rule can make it differ from your amount. So compare total_to_pay with the amount in your system.

When the payment is below total_to_pay, the difference becomes debt: a customer is required (149005), the call is rejected if debt sales are off (149024), and paying_date is needed if a debt return date is required (149036).

5. What changes ​

  • Stock: for a done sale amount goes down. For new or in_progress the goods move to booked. With not enough stock the sale is not recorded (149003).
  • Money: each payments entry creates an income transaction into the cashbox — whatever the state.
  • Customer: debt is written to the balance; cashback is earned if enabled.
  • Promotions: active promotions apply automatically — a free gift line may be added.
  • Fiscalization: if the organization has it enabled, a done sale is also sent for fiscalization. If the marketplace already issues the receipt, agree this with your customer first.

Refund ​

A refund is a separate trade (is_refund: true); it does not replace the original. If the sale was recorded by mistake, cancel it instead.

Get a refund reason (an integration with declared permissions cannot call this method):

json
POST /reason/get-paging

{ "page": 1, "limit": 50, "type": "customer_return" }

Read the original with GET /trade/get-by-id/{id}. The _id of a refund line is the original line's item_id (products[]._id in the response is the product id):

json
POST /trade/refund

{
    "refund_id": "6712f0a9c4d1e87b3a0f9988",
    "reason_id": "6712f0a9c4d1e87b3a0f99aa",
    "organization_id": "6712f0a9c4d1e87b3a0f9911",
    "responsible_id": "6712f0a9c4d1e87b3a0f9944",
    "currency": { "_id": "6712f0a9c4d1e87b3a0f9955", "name": "UZS", "value": 1 },
    "products": [
        {
            "_id": "6712f0a9c4d1e87b3a0f99bb",
            "product_id": "6712f0a9c4d1e87b3a0f9933",
            "warehouse_id": "6712f0a9c4d1e87b3a0f9966",
            "amount": 1,
            "price": 45000
        }
    ],
    "payments": [
        {
            "amount": 45000,
            "payment_method": { "_id": "6712f0a9c4d1e87b3a0f9977", "name": "Card" },
            "currency": { "_id": "6712f0a9c4d1e87b3a0f9955", "name": "UZS", "value": 1 }
        }
    ]
}

payments is the money returned to the customer. The goods go back to the warehouse; if the reason has is_trash on, they go to defective stock instead of sellable stock. You cannot return more than was sold (149004). trade/refund is not idempotent either.

Errors ​

ResponseCause
400, code: 10001Validation — read message
403, code: 10003One of the permissions was not approved; data names it
400, code: 149003Not enough stock
400, code: 149016For a marked product, the number of marks differs from amount
400, code: 149021Sale settings require a customer
400, code: 26022The product is not available in this organization

Full list: errors.

Methods ​

StepMethod
SellerPOST /employee/get-paging
Payment methodGET /payment-method/get-all
StockPOST /product-warehouse/get-paging
Duplicate checkPOST /trade/get-paging
SalePOST /trade/create
CheckGET /trade/get-by-id/{id}
RefundPOST /trade/refund

Bito 2.0 Integration API