# Overview A Bito integration is an external application that uses the Integration API and may also ship a custom widget that runs inside the Bito admin panel. Start by choosing the right distribution path: | Path | Who can install it | Developer account | Moderation | |---|---|---|---| | Private integration or private widget | Your own Bito account | Not required | No marketplace review; the archive is still validated and the account owner must consent | | Public API integration | Any Bito tenant from the marketplace | Required | Marketplace card review | | Public integration with a custom widget | Any Bito tenant from the marketplace | Required | Marketplace card review **and** widget-release review | This is the same useful separation made in the [amoCRM integration overview](https://www.amocrm.ru/developers/content/integrations/intro): build privately first, then use a developer-only workflow for a public marketplace app. The field names, package format and moderation states below are Bito's own contracts. ## Public-widget journey ```text Developer account | | Create app -> copy credentials -> claim permanent app code v Marketplace card (name, listing, URLs, permissions, support/privacy) | | Create version -> upload widget.zip -> validate -> test locally v Release review: draft -> queued -> testing -> approved | | Submit the marketplace card for its separate review v Card review: draft/changed -> pending -> approved | v PUBLIC: tenants can find, install and consent to the approved release ``` The two reviews are intentionally independent: - the **app card** is the store-facing identity, listing, URLs, permissions and commercial information; - a **release** is one exact version of `widget.zip`, its release notes and a snapshot of the listing. Approving a release makes that code runnable. It does **not** publish the app by itself. Approving the card makes the app public, but a widget app cannot be published with a locally activated or otherwise unmoderated current release. ## Credentials do not change on publication Your `client_id`, `secret` and `api_key` are issued when the integration is created. Publication changes visibility and approved code; it does not mint a second production identity. ::: warning The secret is shown once, at creation, and cannot be read back. If the secret or the API key is lost or compromised, reissue both with **Reissue keys** on the **Keys** tab and update every caller immediately — see [Rotating credentials](https://docs.bito.uz/en/guide/rotate.md). ::: ## Start here - [Quick start](https://docs.bito.uz/en/guide/quick-start.md) for an API call against your own account - [Becoming a Bito developer](https://docs.bito.uz/en/guide/developer-account.md) for a public marketplace app - [Your app page](https://docs.bito.uz/en/guide/developer-app.md) for the complete public-widget workflow - [Custom widgets overview](https://docs.bito.uz/en/guide/widget.md) and [the widget.zip format](https://docs.bito.uz/en/guide/widget-package.md) for the runtime contract --- # Quick start Your first successful API call, in about five minutes. This uses the `api-key` path, which needs no OAuth flow — you are calling your own account. ## 1. Create an integration In the left menu of the Bito admin panel open **Integration → Integration** and press **Custom integration**. In the **Create integration** dialog press **+ Create** next to **External integration**. Fill in a name, leave the rest empty for now, and press **Save**. Field-by-field detail is in [Create an integration](https://docs.bito.uz/en/guide/create.md). ::: warning Install it A new integration is created but not yet **installed**. Open it in the **Integration** section and press **Install**. Until then requests return `400`, `code: 115004`. ::: ## 2. Copy the three values Saving shows `client_id`, `secret` and `api_key`. The `secret` is shown here **once** and never again — copy all three somewhere safe before closing the dialog, see [Your credentials](https://docs.bito.uz/en/guide/credentials.md). For this quick start you only need `api_key`. It looks like `mycompany:9ad41c0e7b3f28d5610ac94e7f1b26d8`. ## 3. Install it An integration is **created, not installed**. Until it is installed, every API call made with its credentials fails with `Integration is not installed`. On the **Integration** page, open your new integration from the **Installed** list and press **Install**. Installing also fires your `redirect_uri` and `webhook_uri` if you set them — see [Install & uninstall hooks](https://docs.bito.uz/en/guide/lifecycle-hooks.md#install). ## 4. Make a call List queries are `POST` — their filters travel in the body. Reads of a single record are `GET`, updates `PUT`, deletes `DELETE`. ```bash curl -X POST \ 'https://api.bito.uz/integration-api/integration/api/v2/product/get-paging' \ -H 'api-key: mycompany:9ad41c0e7b3f28d5610ac94e7f1b26d8' \ -H 'Content-Type: application/json' \ -H 'Accept-Language: en' \ -d '{ "page": 1, "limit": 5 }' ``` **Response** ```json { "code": 0, "message": "Success", "status_code": 200, "data": { "total": 1043, "data": [ { "_id": "6712f0a9c4d1e87b3a0f9911", "name": "Espresso" } ] }, "time": "2025-05-01T12:00:00Z" } ``` `code: 0` means success. The rows are at `data.data`, the count at `data.total`. ::: tip Got `401`? The header is `api-key`, not `Authorization`, and the value includes the username part before the colon. Got `404`? Check the base URL — it ends with `/integration/api/v2/`. ::: Where to see the result in the admin panel: [Verify in Bito](https://docs.bito.uz/en/guide/verify.md). ## 5. Pick your path from here | You are building | Read next | |---|---| | Something for your own account only | [Calling the API](https://docs.bito.uz/en/guide/api.md), then the [API reference](https://docs.bito.uz/en/api/index.md) — or [a widget for your own account](https://docs.bito.uz/en/guide/private-widget.md) if it needs a screen inside Bito | | A marketplace API integration many merchants install | [Become a Bito developer](https://docs.bito.uz/en/guide/developer-account.md), then read the [OAuth 2.0 overview](https://docs.bito.uz/en/guide/oauth/index.md) | | A public widget that appears inside Bito | [Your app page](https://docs.bito.uz/en/guide/developer-app.md), then [Custom widgets](https://docs.bito.uz/en/guide/widget.md) | | Something that reacts to data changes | [Data webhooks](https://docs.bito.uz/en/guide/webhooks.md) | When it works, [submit it for review](https://docs.bito.uz/en/guide/submit.md). Public widgets have separate app-card and release reviews; approval makes the app installable, never automatically installed. --- # First sale The step after [Quick start](https://docs.bito.uz/en/guide/quick-start.md): record one real sale and see it in the admin panel. ::: warning This is a real sale Warehouse stock goes down and money lands in a cashbox. Use a test account, or [cancel the sale](#cancel) at the end. ::: ## 0. Install the integration A new custom integration is created but not yet **installed**. Open it in the **Integration** section of the admin panel and press **Install**. Until then requests return `400`, `code: 115004`. For this walkthrough leave the integration's `required_permissions` list empty: an integration that declares a list cannot call `profile/getMe` from step 2. All paths below are relative to the base URL, with the `api-key` header: ``` https://api.bito.uz/integration-api/integration/api/v2/ ``` ## 1. Organization ```http GET /organization/get-all ``` From the `data` list, take the organization's `_id` and `currency_id`. ## 2. Seller ```http GET /profile/getMe ``` `data._id` is the account owner. It becomes the sale's `responsible_id`. ## 3. Currency and payment method ```http GET /currency/get-by-id/{currency_id} GET /payment-method/get-all ``` Take the currency's `name` from the first response, and a payment method's `_id` and `name` from the second (`data.data`). ## 4. A product in stock ```json POST /product-warehouse/get-paging { "page": 1, "limit": 50, "organization_id": "6712f0a9c4d1e87b3a0f9911" } ``` Pick a row with `amount` above zero and take its `product_id` and `warehouse_id`. Choose a plain product: a marked one also needs `marks`. To see its name, call `GET /product/get-by-id/{id}`. ## 5. Record the sale You send the price. The payment equals the sum of the lines: ```json POST /trade/create { "code": "TEST-1", "organization_id": "6712f0a9c4d1e87b3a0f9911", "responsible_id": "6712f0a9c4d1e87b3a0f9944", "state": "done", "currency": { "_id": "6712f0a9c4d1e87b3a0f9955", "name": "UZS", "value": 1 }, "products": [ { "product_id": "6712f0a9c4d1e87b3a0f9933", "warehouse_id": "6712f0a9c4d1e87b3a0f9966", "amount": 1, "price": 45000 } ], "payments": [ { "amount": 45000, "payment_method": { "_id": "6712f0a9c4d1e87b3a0f9977", "name": "Cash" }, "currency": { "_id": "6712f0a9c4d1e87b3a0f9955", "name": "UZS", "value": 1 } } ] } ``` `currency.value` is a required number, but the server sets the rate itself. Keep `_id`, `number` and `uuid` from the response's `data`, and check that `state` is `done` and `debt` is `0`. ::: warning Retries `trade/create` is not idempotent. If no response came back, before retrying check with `POST /trade/get-paging` (`{ "page": 1, "limit": 20, "search": "TEST-1" }`) that the sale was not recorded. ::: ## 6. See the result In the admin panel: **Sale › Sales**. Through the API: ```http GET /trade/get-by-id/{id} ``` ## Cancel the test sale ```json PUT /trade/set-state { "_id": "6712f0a9c4d1e87b3a0f9988", "state": "canceled" } ``` Canceling a sale that has no customer returns the goods to the warehouse and cancels the payment too. ## If it fails | Response | Cause | |---|---| | `400`, `code: 115004` | The integration is not installed — step 0 | | `400`, `code: 10001` | A required field is missing or wrong — read `message` | | `400`, `code: 149003` | Not enough stock in the warehouse | | `400`, `code: 149021` | Sale settings require a customer — send `customer_id` | | `400`, `code: 149005` or `149024` | The payment is below `total_to_pay` (for example, a tax was added to the product) | | `400`, `code: 236014` | The organization requires a cashbox session — a sale cannot be recorded in it through the Integration API | Other codes: [errors](https://docs.bito.uz/en/guide/errors.md). ## Next - [Recipe: record an external sale](https://docs.bito.uz/en/guide/recipes/sale.md) — customer, duplicate protection, refund - [Sale and order states](https://docs.bito.uz/en/guide/concepts/sale-lifecycle.md) - [API reference: Trade](https://docs.bito.uz/en/api/trade.md#post-trade-create) --- # Becoming a Bito developer You do not need developer status to build an API integration or widget for your own Bito account. You need it when you want to create an app that other tenants can discover and install from the Bito marketplace. | Goal | What to use | |---|---| | Integrate only your own company | **Integration → Integration → Custom integration** | | Run your own widget only in your account | [Private widget](https://docs.bito.uz/en/guide/private-widget.md) | | Publish an API integration or widget for other tenants | Request developer access, then use **Integration → My apps** | The public path follows the same broad model as an amoCRM technical account: a dedicated developer surface, versioned releases and a moderation queue. Unlike amoCRM's [technical-account process](https://www.amocrm.ru/developers/content/integrations/intro#1-регистрация-аккаунта), Bito grants developer status to the owner of your existing Bito account; you do not create a separate account for each app. ## Request access There is no self-service signup. Contact the platform owner through one of these channels: | Channel | Address | |---|---| | Email | `kahero@unical.uz` | | Phone | `+998 93 123 37 00` | | Telegram | `t.me/kahero_unical` | Include enough context to route the request: your Bito account, the product you plan to integrate, whether it includes a custom widget, and who will own support and the privacy policy. These details speed up review; they are not a second application form. ## What changes after approval An active developer gets **Integration → My apps**. From there the account owner can: - create API-only apps and apps that ship widget code; - claim a permanent app code; - manage store cards in the selected languages; - create semantic versions and upload `widget.zip` archives; - test a private version in the developer's own tenant; - submit or withdraw the app card and widget releases independently; - view release history, installation statistics, reviews and integration keys. Credentials belong to the app, not to a release. The `client_id` remains permanent; the secret and API key can be reissued from the **Keys** tab. ## Developer states | `developer_status` | What you can do | |---|---| | absent | Use private integrations and private widgets in your own account. **My apps** shows the contact channels above. | | `active` | Create and edit apps, test versions, submit cards and releases, and withdraw open reviews. | | `suspended` | Read-only access to your apps and release history. Existing tenant installations keep working, but you cannot publish changes. | Only the account owner can perform developer mutations. An ordinary employee of the same tenant cannot publish code in the company's name. ## Prepare before building a public app - a stable HTTPS backend for install, uninstall and webhook callbacks; - a support email or support page for every published language; - a public privacy-policy URL; - the narrowest Integration API permissions your app needs; - a versioned, reproducible `widget.zip` build if the app runs inside Bito; - a test case that a moderator can reproduce in your developer tenant. Next: [Your app page](https://docs.bito.uz/en/guide/developer-app.md). --- # Verify in Bito In the first days of an integration, check every call against the result in the Bito admin panel. The sections are in the left menu. | API action | In the admin panel | |---|---| | `product/create`, `product/update` | Warehouse › Reference › Products | | Price lists (`price/...`) | Reference › Prices | | Product prices (`price/items/...`) | Tools › Price list | | Stock per warehouse (`product-warehouse/...`) | Warehouse › Reports › Products quantity by warehouse | | `customer/create` | CRM › Customers | | `sale-order/create` | CRM › Orders | | `trade/create`, `trade/refund` | Sale › Sales | | `purchase/create` | Supply › Purchases | | `income/create` | Warehouse › Actions › Incomes | | `internal-transfer/create` | Warehouse › Transfers › Internal transfers — only with multiple warehouses enabled | | `write-off/create` | Warehouse › Actions › Write-offs | | `transaction/...` | Finance › Actions › Transactions | | Webhook subscriptions | Integration › Webhooks — visible to the account owner only | ## Finding what your integration created Every record your integration creates is stamped with its source ([the `source_id` header](https://docs.bito.uz/en/guide/api.md)). In **CRM › Customers** and **CRM › Orders**, pick your integration's source in the **Source** filter. Other lists have no such filter — find the record by date or search. ## Webhook health **Integration › Webhooks** shows, per destination, the time of the last successful delivery and the number of failures in a row; the error text is in a tooltip. There is no per-delivery history and no log of API calls — when debugging, see [what to send support](https://docs.bito.uz/en/guide/support.md). --- # 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). --- # Create an integration ### 1. Open the integrations screen In the left menu of the Bito admin panel go to **Integration → Integration** and press **Custom integration**. In the **Create integration** dialog pick the kind: - **External integration** — API only: your code runs on your own servers. Press **+ Create** on that row; this page describes this path. - **Integration with custom code** — the same form plus a `widget.zip` that runs inside Bito. See [a widget for your own account](https://docs.bito.uz/en/guide/private-widget.md). ### 2. Fill in the form Only the name is required at this stage, but a public listing needs most of the rest. You can edit any of it later — except while the card is in review (`pending`), when changes are refused. | Field | Required | Description | |---|---|---| | `name` | Yes | Per-language name shown in the marketplace. Fill at least one language; the rest are copied from the first one you fill. | | `description` | No | Per-language description shown before install. | | `thumbnail` | No | Logo URL. Upload the image first; the form gives you the URL. | | `role_id` | No | Legacy (**Integration role** in the form), kept so older clients that still send it keep working. Access to API methods is set by `required_permissions`. | | `required_permissions` | No | The ERP permissions this integration uses on the Integration API (the same keys roles are built from). The merchant sees exactly this list before installing, installing grants it to the integration, and every call is checked against it: a method outside it returns `403` (`code: 10003`). Empty or omitted means all permissions. **Once you declare even one permission**, resources with no permission key are closed: reports, sources, files, settings, webhooks and more (except `organization/get-all` and `get-by-id`). Each endpoint's page in the [API reference](https://docs.bito.uz/en/api/index.md) names the permission it needs; [Permissions](https://docs.bito.uz/en/api/permissions.md) lists them all. If you change the list later, existing installs keep the old one until the merchant [approves the new one](https://docs.bito.uz/en/guide/oauth/index.md#permissions). The plain form has no such field; set it under **My apps → app → General info** or over the API. | | `redirect_uri` | For OAuth | Your HTTPS endpoint. Bito POSTs the authorization code here when a merchant installs the integration. See [install hooks](https://docs.bito.uz/en/guide/lifecycle-hooks.md#install). | | `revoke_access_hook_uri` | Strongly advised | Your HTTPS endpoint for uninstall notifications. Without it you never learn that a merchant removed you. | | `webhook_uri` | No | A destination for data webhooks. On every install Bito automatically subscribes it to `create`/`update`/`delete` on a fixed set of collections. You can also register destinations over the API — see [data webhooks](https://docs.bito.uz/en/guide/webhooks.md). | | `iframe.url` | For widgets | The page Bito embeds in your integration's settings tab, authenticated with a [one-time token](https://docs.bito.uz/en/guide/oauth/one-time-tokens.md). This is not how a [custom widget](https://docs.bito.uz/en/guide/widget.md) works. | | `ip_whitelist` | No | An allowlist of source addresses: single IPv4 addresses or CIDR subnets (`203.0.113.0/24`), at most 50; IPv6 is not supported. Once the list is filled, an Integration API request from any address outside it is refused with `403`. Edit it in the form's **IP whitelist** field; for a developer app, under **My apps → app → Keys → Allowed IP addresses**. | | `duplicate_control` | No | Whether Bito should apply duplicate control to records this integration creates. | | `multiple_sources` | No | Whether the integration may have several sources. Every record the integration creates is stamped with its source; with several, the request's `source_id` header picks one ([headers](https://docs.bito.uz/en/guide/api.md#request-headers)). | ::: warning All URLs must be `https://` and publicly reachable. Bito refuses loopback, private-network and cloud-metadata addresses, and URLs that carry credentials. ::: ### 3. Save and copy the keys Press **Save**. The **Integration created** dialog shows `client_id`, `secret` and `api_key` — the `secret` is never shown anywhere again. See [Your credentials](https://docs.bito.uz/en/guide/credentials.md). ### 4. Install it A new integration is **not installed**, and every API call made with its keys fails with `Integration is not installed`. Open it from the **Installed** list on the **Integration** page and press **Install**. Installing sends the [install hook](https://docs.bito.uz/en/guide/lifecycle-hooks.md#install) and creates the `webhook_uri` subscription. --- # Your credentials Saving the form returns three values. **This is the only time the `secret` is shown** — Bito never returns it in any other response. The `api_key` is stored on the integration record: reading the integration (`getOne`) returns it in `response_fields` (the `api-key` field), even though the panel does not display it. Copy both into your secret store now anyway. **Response** ```json { "code": 0, "message": "Success", "data": { "_id": "6712f0a9c4d1e87b3a0f1122", "client_id": "69c50a2d50f7b939923a469b", "secret": "4f3c1a9e8b27d605f1ac93e7d284b6510ff7a3c9e15d8b2470a6cd91e83f4b27", "api_key": "mycompany:9ad41c0e7b3f28d5610ac94e7f1b26d8" }, "time": "2025-01-15T10:30:00.000Z" } ``` | Value | Used for | Rotatable | |---|---|---| | `client_id` | Identifies your integration in every OAuth call and in the widget token. Permanent. | No — it is the identity itself | | `secret` | OAuth client secret. Also the HS256 key you verify the [one-time token](https://docs.bito.uz/en/guide/oauth/one-time-tokens.md) with. | Yes — see [rotating credentials](https://docs.bito.uz/en/guide/rotate.md#client-secret) | | `api_key` | The simpler auth path: send it as the `api-key` header on Integration API calls. Format is `:`. Works once the integration is [installed](https://docs.bito.uz/en/guide/create.md#install). | Yes — in the panel together with the secret, or [on its own over the API](https://docs.bito.uz/en/guide/rotate.md#api-key) | ::: warning **If you lose the secret, it cannot be read back.** Rotate it to get a new one — which disconnects every merchant currently connected. Store it properly the first time. ::: --- # For AI agents If an AI agent writes your integration, give it the docs in a form it can read. ## Set up with one prompt Send the line below to your agent — Claude Code, Codex, Cursor, Windsurf, GitHub Copilot, or any other that can open a link: ```text Read https://docs.bito.uz/agent-setup/prompt.md and follow it to set up this project for the Bito Integration API. ``` The agent will: 1. Download the OpenAPI spec into your project as `docs/bito-openapi.json`. 2. Add a "Bito API" section to `AGENTS.md` or `CLAUDE.md`: base URL, auth, response envelope, paging, errors, and retry rules. 3. Ask whether it may call the production API — every write runs against a real business account. 4. Report what it did and suggest a first call. The prompt installs and changes nothing outside your project. Its text is public: [docs.bito.uz/agent-setup/prompt.md](https://docs.bito.uz/agent-setup/prompt.md). ## Files for agents | File | What it is | |---|---| | [`/en/llms.txt`](https://docs.bito.uz/en/llms.txt) | Index of the guide pages, per the [llmstxt.org](https://llmstxt.org/) standard. Uzbek — `/llms.txt`, Russian — `/ru/llms.txt` | | [`/en/llms-full.txt`](https://docs.bito.uz/en/llms-full.txt) | The whole guide in one file | | A page URL with `.md` instead of `.html` | The Markdown version of any page, e.g. `/en/guide/quick-start.md` | | [`/openapi.json`](https://docs.bito.uz/openapi.json) | Exact parameters, schemas and responses of all 464 methods | | [`/bito-api.postman_collection.json`](https://docs.bito.uz/bito-api.postman_collection.json) | A ready collection for Postman and Insomnia: `baseUrl` points at production; fill in only the `api_key` variable | The API reference is not in `llms.txt`: for methods, the agent's source of truth is `openapi.json`. When you ask the agent to write code for one method, hand it the spec or the relevant part of it. ## Page menu Every page has buttons at the top: copy the page as Markdown, open its Markdown version, and open the page in ChatGPT or Claude. --- # Recipe: online order A website, bot or courier app takes an order, and it has to show up in Bito under **CRM › Orders**. In Bito that is a `sale-order` — a customer's order, not yet a sale ([glossary](https://docs.bito.uz/en/guide/glossary.md#confusions)). **Permissions needed:** `customer`, `customer_create`, `price`, `sale_order_create`. `organization/get-all` is always allowed. ## 1. Find your organization An order belongs to one organization. Fetch its id once and keep it. ```http GET /organization/get-all ``` ## 2. Find the customer ```http GET /customer/get-by-phone-number?phone_number=901234567 ``` The number is normalised: 9 digits get `+998`, anything else gets a leading `+`. When no customer matches, `data` is `null`. ## 3. Not found — create the customer ```json POST /customer/create { "type": "natural", "name": "Aziz Karimov", "phone_number": "+998901234567", "organization_ids": ["6712f0a9c4d1e87b3a0f9911"] } ``` `type` is `natural` (a person) or `legal` (a company). Send the phone, or step 2 will not find the customer next time. Keep the `_id` from the response. ## 4. Get the price Bito does **not** look up the price of an order line — you send `price`. Take it from a price list: ```json POST /price/items/get-paging { "page": 1, "limit": 200, "organization_id": "…", "price_id": "…" } ``` Each row has the product's `amount`. The row carries no currency: it is the price list's `currency_id` (`price/get-by-id`). Syncing prices with the catalog: [catalog recipe](https://docs.bito.uz/en/guide/recipes/catalog-sync.md). ## 5. Create the order The smallest valid body: ```json POST /sale-order/create { "organization_id": "6712f0a9c4d1e87b3a0f9911", "customer_id": "6712f0a9c4d1e87b3a0f9922", "products": [ { "product_id": "6712f0a9c4d1e87b3a0f9933", "amount": 2, "price": 45000 } ], "delivery_address": "Tashkent, Chilanzar 9", "note": "Web #10482" } ``` The server fills in the rest: | Field | When you leave it out | |---|---| | `state`, `state_id` | `in_progress`, in the pipeline's first regular column | | `responsible_id` | The user the call runs as — usually the account owner | | `currency_id` | The organization's currency | | `date` | Now | | Line `price_id` | The main sale price list | | Line `warehouse_id` | The organization's main warehouse | To pick another column, send `state` and `state_id` **together** — a lone `state_id` is overwritten. If the organization has no pipeline columns, `create` returns an error. Store the response's `_id` next to your own order; `uuid` (like `A123`) is the order number in Bito. ::: warning Retries `create` is not idempotent: a repeated call creates a second order. If no response came back, first read to check whether the order exists (for example by your own order number in `note`). ::: ## 6. Is stock reserved? Only when Bito's sale setting to reserve goods in orders (`booking_product_in_order`) is on and the order is `new`, `accepted` or `in_progress`. Then the warehouse `amount` goes down and `booked` goes up. The setting is off by default, so an order does not touch stock. ## 7. Follow the status Subscribe to the `saleOrders.status_change` and `saleOrders.update` webhooks ([webhooks](https://docs.bito.uz/en/guide/webhooks.md)) and re-read the order with `GET /sale-order/get-by-id/{id}` when one arrives. A webhook is a signal, not the data: reconcile with `sale-order/get-paging` from time to time. ## 8. Turn it into a sale (optional) Usually Bito staff sell the order. If your system records the sale too, send `order_id` to `POST /trade/create`, and each line's `order_item_id` from the order. The reservation is released, the sold quantities are written to the order lines, and a fully sold order becomes `done`. Full body: [Trade](https://docs.bito.uz/en/api/trade.md#post-trade-create). `order_item_id` is the line's `item_id` in the order response (the line's `_id` is the product id). ## Errors | Response | Cause | |---|---| | `400` validation | A required field is missing or an id is wrong — read `message` | | `403`, `code: 10003` | One of the permissions was not approved; `data` names it | | `404` | Wrong method: `create` is `POST`, `get-by-phone-number` is `GET` | ## Methods | Step | Method | |---|---| | Organization | [`GET /organization/get-all`](https://docs.bito.uz/en/api/organization.md) | | Find customer | [`GET /customer/get-by-phone-number`](https://docs.bito.uz/en/api/customer.md#get-customer-get-by-phone-number) | | Create customer | [`POST /customer/create`](https://docs.bito.uz/en/api/customer.md#post-customer-create) | | Price | [`POST /price/items/get-paging`](https://docs.bito.uz/en/api/price.md#post-price-items-get-paging) | | Order | [`POST /sale-order/create`](https://docs.bito.uz/en/api/sale-order.md#post-sale-order-create) | | Check | [`POST /sale-order/get-paging`](https://docs.bito.uz/en/api/sale-order.md#post-sale-order-get-paging) | | Sale | [`POST /trade/create`](https://docs.bito.uz/en/api/trade.md#post-trade-create) | --- # 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](https://docs.bito.uz/en/guide/recipes/online-order.md). **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: | What | Method | |---|---| | `organization_id` and currency | `GET /organization/get-all`, `GET /currency/get-by-id/{id}` | | `responsible_id` — the seller | `POST /employee/get-paging` | | Payment methods | `GET /payment-method/get-all` | | Product, warehouse, stock | `POST /product-warehouse/get-paging` | If you need a customer, find or create one as in [steps 2–3 of the online order recipe](https://docs.bito.uz/en/guide/recipes/online-order.md). ## 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`). | Field | Rule | |---|---| | `state` | `done` for a completed sale. Other states: [lifecycle](https://docs.bito.uz/en/guide/concepts/sale-lifecycle.md#trade) | | `price` | Unit price — the one actually sold at | | Line `warehouse_id` | When left out, the organization's main warehouse | | `date` | When left out, now. A future date is rejected (`10031`); a past date may be disabled in sale settings (`149030`) | | `currency.value` | A 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 | | Cashbox | Cannot be chosen: money goes to the organization cashbox of the user the call runs as (the owner, or the `user_id` header) | ::: warning 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](https://docs.bito.uz/en/guide/concepts/sale-lifecycle.md#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 | Response | Cause | |---|---| | `400`, `code: 10001` | Validation — read `message` | | `403`, `code: 10003` | One of the permissions was not approved; `data` names it | | `400`, `code: 149003` | Not enough stock | | `400`, `code: 149016` | For a marked product, the number of `marks` differs from `amount` | | `400`, `code: 149021` | Sale settings require a customer | | `400`, `code: 26022` | The product is not available in this organization | Full list: [errors](https://docs.bito.uz/en/guide/errors.md). ## Methods | Step | Method | |---|---| | Seller | [`POST /employee/get-paging`](https://docs.bito.uz/en/api/employee.md#post-employee-get-paging) | | Payment method | [`GET /payment-method/get-all`](https://docs.bito.uz/en/api/payment-method.md#get-payment-method-get-all) | | Stock | [`POST /product-warehouse/get-paging`](https://docs.bito.uz/en/api/product-warehouse.md#post-product-warehouse-get-paging) | | Duplicate check | [`POST /trade/get-paging`](https://docs.bito.uz/en/api/trade.md#post-trade-get-paging) | | Sale | [`POST /trade/create`](https://docs.bito.uz/en/api/trade.md#post-trade-create) | | Check | [`GET /trade/get-by-id/{id}`](https://docs.bito.uz/en/api/trade.md#get-trade-get-by-id-id) | | Refund | [`POST /trade/refund`](https://docs.bito.uz/en/api/trade.md#post-trade-refund) | --- # Recipe: catalog sync Products, prices and stock flow from Bito to your storefront. You need two modes: a frequent **incremental** sync and a **full** reconcile once a day. **Permissions needed:** `product`, `price`, `product_stock`. ## 1. Pick the organization and price list ```http GET /organization/get-all GET /price/get-all ``` For a storefront, pick a sale-type price list. Keep both ids. ## 2. First full load ```json POST /product/get-paging { "page": 1, "limit": 200, "organization_id": "…", "price_id": "…" } ``` Page until `page * limit >= data.total`. When **both** `organization_id` and `price_id` are sent, each row's `prices` is filled: `amount`, `currency`, `min_price`, `max_price`. Without either, `prices` comes back empty. The main row fields: `name`, `sku`, `barcode`/`barcodes`, `measure`, `category`, `image`, `organizations[]` (a stock summary per organization) and `custom_fields`. **Variants.** Each variant of a variant product is its own row (`is_variant: true`, `parent_id`). Parent records (`is_parent`) are left out of the list. For plain products without variants only, send `"is_main": true`. ## 3. Incremental updates Store the time of your last successful sync and send it next time: ```json POST /product/get-paging { "page": 1, "limit": 200, "organization_id": "…", "price_id": "…", "updated_at": "2026-11-05T09:00:00Z" } ``` The response holds the products changed since then. ## 4. Deletes Deleted products drop out of `get-paging`: ```http GET /product/get-deleted?deleted_at=2026-11-05T09:00:00Z ``` The response is a list of ids of products deleted since then. Remove them from your storefront. ## 5. Stock per warehouse ```json POST /product-warehouse/get-paging { "page": 1, "limit": 200, "organization_id": "…", "updated_at": "2026-11-05T09:00:00Z" } ``` Each row is a product × warehouse: `amount`, `booked`, `in_transit`, `in_trash`. **`amount` is the quantity available to sell**: reserved goods and goods in transit are not in it. If your storefront sells from several warehouses, add up `amount`. For specific products, send `product_ids` (up to 500). There is no warehouse filter — pick the warehouses on your side. Use `product-warehouse`, not `product-stock`: `product-stock` holds batch-level rows ([glossary](https://docs.bito.uz/en/guide/glossary.md#confusions)). ## 6. Webhooks and the full reconcile Subscribe to the `products.*` and `productPrices.*` webhooks and re-read the product when one arrives. But bulk operations emit no webhooks and delivery is not guaranteed ([webhooks](https://docs.bito.uz/en/guide/webhooks.md)), so: | Mode | When | What | |---|---|---| | Incremental | Every 5–60 minutes | Steps 3–5 with `updated_at` | | Full | Once a day | Steps 2 and 5 without a filter, compared with your storefront | ## Methods | Step | Method | |---|---| | Organization | [`GET /organization/get-all`](https://docs.bito.uz/en/api/organization.md) | | Price lists | [`GET /price/get-all`](https://docs.bito.uz/en/api/price.md) | | Products and prices | [`POST /product/get-paging`](https://docs.bito.uz/en/api/product.md#post-product-get-paging) | | Deletes | [`GET /product/get-deleted`](https://docs.bito.uz/en/api/product.md#get-product-get-deleted) | | Stock | [`POST /product-warehouse/get-paging`](https://docs.bito.uz/en/api/product-warehouse.md#post-product-warehouse-get-paging) | | Prices only | [`POST /price/items/get-paging`](https://docs.bito.uz/en/api/price.md#post-price-items-get-paging) — no currency; it is on the price list | --- # 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) | --- # Recipe: write-off Your system knows that goods were damaged or lost — it has to show up in Bito under **Warehouse › Actions › Write-offs** and leave stock. That is a `write-off` document. It is created **directly** as `done`: there is no draft. **Permissions needed:** `write_off_create`, `write_off`, `warehouse`, `employee`. ## 1. Find the organization and warehouse ```http GET /organization/get-all ``` ```json POST /warehouse/get-all { "organization_id": "6712f0a9c4d1e87b3a0f9911", "status": "active" } ``` Keep the organization's `_id` and `currency_id` and the warehouse's `_id`. ## 2. Pick a reason ```json POST /reason/get-paging { "page": 1, "limit": 200, "type": "write_off" } ``` ::: warning Reasons and permissions `reason/*` methods have no permission key. If your app declares even one permission in `required_permissions`, they are **closed** to it ([Creating an integration](https://docs.bito.uz/en/guide/create.md)). In such an app, keep the reason id in your settings, or take it from existing documents: `write-off/get-paging` rows carry `reason._id`. ::: ## 3. Pick the responsible employee ```json POST /employee/get-paging { "page": 1, "limit": 200 } ``` ## 4. Create the document ```json POST /write-off/create { "organization_id": "6712f0a9c4d1e87b3a0f9911", "source_warehouse_id": "6712f0a9c4d1e87b3a0f9955", "currency_id": "6712f0a9c4d1e87b3a0f9988", "write_date": "2026-11-05T10:00:00Z", "responsible_id": "6712f0a9c4d1e87b3a0f99aa", "reason_id": "6712f0a9c4d1e87b3a0f99bb", "action": "remove", "products": [ { "product_id": "6712f0a9c4d1e87b3a0f9933", "amount": 2 } ], "code": "WMS-10482", "note": "Damaged packaging" } ``` | Field | Required | Description | |---|---|---| | `organization_id` | Yes | Organization | | `source_warehouse_id` | Yes | Warehouse the goods leave | | `currency_id` | Yes | The document's cost is calculated in it — usually the organization's currency | | `write_date` | Yes | ISO 8601 | | `responsible_id` | Yes | Responsible employee | | `reason_id` | Yes | Reason | | `action` | Yes | `remove` — write off for good, `defect` — move to defective goods | | `destination_warehouse_id` | For `defect` | Warehouse that accounts for the defective goods | | `products[].product_id` | Yes | Product | | `products[].amount` | Yes | A positive number in the product's unit of measure | | `products[].marks` | For marked goods | Codes; their count must equal `amount` | | `products[].expiration_date` | No | Take only from batches with this expiry date | | `code` | No | The document number in your system | | `note` | No | Comment | The reference lists `organization_id`, `source_warehouse_id` and `currency_id` as optional, but the call fails without them. Send an existing warehouse of the same organization as `destination_warehouse_id`. The response carries `_id`, `number`, `state: "done"`, `total_cost` and the `products` lines. ::: warning Retries `create` is not idempotent: a repeated call writes the goods off **a second time**. If no response came back, first read `write-off/get-paging` with `warehouse_id`, `date_from`, `date_to` and look for your `code` in the rows (`search` matches the Bito number only). ::: ## 5. What changes - `amount` goes down in the source warehouse. Reserved goods are not written off. - With `action: "defect"`, the same quantity is added to the `in_trash` counter of `destination_warehouse_id`. - Cost is calculated from the batches (`total_cost`), and Bito issues an expense-type invoice for it — it shows up in [`invoice/get-paging`](https://docs.bito.uz/en/api/invoice.md#post-invoice-get-paging) rows, where `write_off_id` is the write-off's id. No money leaves a cashbox. - There is no webhook event for write-offs. What the counters mean: [stock and prices](https://docs.bito.uz/en/guide/recipes/stock-prices.md). ## 6. Cancel ```json PUT /write-off/set-status/6712f0a9c4d1e87b3a0f99cc { "status": "canceled" } ``` The only transition is `done` → `canceled`. The goods return to the source warehouse (for `defect`, `in_trash` also goes down) and the invoice is cancelled. There is no method to edit or delete the document: if it is wrong, cancel it and create a new one. ## Errors | `code` | Cause | |---|---| | `10001` | Validation: a required field is missing or a value is wrong — read `message` | | `10003` (HTTP `403`) | A permission was not approved; `data` names it | | `26000`, `26022` | Product not found, or not available in this organization | | `26008`, `26014` | A compound product or a service cannot be written off | | `124000`, `124009` | No stock, or not enough of it | | `124003` | Wrong marking codes | | `125000` | Reason not found | | `132000` | Document not found | | `132002` | Cannot cancel: already cancelled, or the goods were used afterwards | On an error no document is created at all — lines are never partly written off. ## Methods | Step | Method | |---|---| | Organization | [`GET /organization/get-all`](https://docs.bito.uz/en/api/organization.md) | | Warehouse | [`POST /warehouse/get-all`](https://docs.bito.uz/en/api/warehouse.md#post-warehouse-get-all) | | Reason | [`POST /reason/get-paging`](https://docs.bito.uz/en/api/reason.md#post-reason-get-paging) | | Employee | [`POST /employee/get-paging`](https://docs.bito.uz/en/api/employee.md#post-employee-get-paging) | | Create | [`POST /write-off/create`](https://docs.bito.uz/en/api/write-off.md#post-write-off-create) | | Check | [`POST /write-off/get-paging`](https://docs.bito.uz/en/api/write-off.md#post-write-off-get-paging), [`GET /write-off/get-by-id/{id}`](https://docs.bito.uz/en/api/write-off.md#get-write-off-get-by-id-id) | | Cancel | [`PUT /write-off/set-status/{id}`](https://docs.bito.uz/en/api/write-off.md#put-write-off-set-status-id) | --- # Recipe: sales export to BI Sales, refunds and cash flow go out of Bito to a BI tool, a warehouse or 1C — read only. **Permissions needed:** `sale`, `transactions`. ::: warning Reports and permissions The `reports/*` and `sales/*` report endpoints have no permission key. Once an app declares even one permission in `required_permissions`, they are **closed** to it ([Create an integration](https://docs.bito.uz/en/guide/create.md)). If you need reports, declare no permissions, or build the data from the `get-paging` methods below. ::: ## 1. Sales ```json POST /trade/get-paging { "page": 1, "limit": 200, "organization_id": "…", "date_from": "2026-11-01T00:00:00Z", "date_to": "2026-11-05T23:59:59Z" } ``` `date_from`/`date_to` filter by sale time (`sold_at`). For an incremental export, send `updated_at` instead — that also returns sales that changed (cancelled, partly refunded). The main row fields: `number`, `state`, `sold_at`, `total_amount`, `total_to_pay`, `total_discount`, `total_cost`, `debt`, `total_refunded_amount`, `currency`, `customer`, `organization`, `responsible`, `order_id`. **POS receipts are sales too.** A receipt rung up at the till is written as a `trade` and shows up in this list — there is no separate receipts resource. ## 2. Sale lines ```http GET /trade/get-items/{id} ``` Each line has `item_id` (the line id), `_id` (the product id), `amount`, `refunded_amount`, `price`, `total_price`, `total_to_pay`, `discounts`, `taxes` and `warehouse`. ## 3. Refunds A refund is a separate sale with `is_refund: true`. Refunds only: ```json POST /trade/get-paging { "page": 1, "limit": 200, "is_refund": true, "updated_at": "2026-11-05T00:00:00Z" } ``` The original sale's `total_refunded_amount` grows; `"is_fully_refunded": true` returns fully refunded sales. List rows carry no `is_refund` field — separate refunds with the filter. ## 4. Cash flow ```json POST /transaction/get-paging { "page": 1, "limit": 200, "organization_id": "…", "date_from": "2026-11-01T00:00:00Z", "date_to": "2026-11-05T23:59:59Z" } ``` `type` is `income`, `expense`, `transfer`, `exchange` or `exchange_method`; filter state with `states`. This method has no `updated_at` — re-read the last few days and upsert by `_id`. ## 5. Ready-made reports For aggregates, see [sales reports](https://docs.bito.uz/en/api/report-sales.md): totals by product, customer, employee, payment method, category and supplier, plus unsold products. Mind the permissions warning above. ## Schedule | Mode | When | What | |---|---|---| | Incremental | Hourly | Step 1 with `updated_at`, step 2 for new sales | | By period | Once a day | Steps 1–4 for yesterday with `date_from`/`date_to` | ## Methods | Step | Method | |---|---| | Sales | [`POST /trade/get-paging`](https://docs.bito.uz/en/api/trade.md#post-trade-get-paging) | | Lines | [`GET /trade/get-items/{id}`](https://docs.bito.uz/en/api/trade.md#get-trade-get-items-id) | | Cash flow | [`POST /transaction/get-paging`](https://docs.bito.uz/en/api/transaction.md#post-transaction-get-paging) | | Reports | [Report sales](https://docs.bito.uz/en/api/report-sales.md) | --- # Data model The main entities an integration sees and the fields that link them. Every `_id` is a 24-character string. How the terms differ: [glossary](https://docs.bito.uz/en/guide/glossary.md#confusions). ```text organization ── warehouse ──┐ ├── stock (product × warehouse) product ────────────────────┘ product × price list × organization ── price customer ── order (sale-order) ── sale (trade) ── invoice ── transaction ``` ## Organization and warehouse | Entity | References | Read | |---|---|---| | Organization (`organization`) | `currency_id` — its accounting currency | [`GET /organization/get-all`](https://docs.bito.uz/en/api/organization.md#get-organization-get-all) | | Warehouse (`warehouse`) | `organization_id` — belongs to one organization; `is_main` — the main warehouse | [`POST /warehouse/get-all`](https://docs.bito.uz/en/api/warehouse.md#post-warehouse-get-all) | `warehouse/get-paging` returns an `organization` object instead of `organization_id`. ## Product, price, stock | Entity | References | Read | |---|---|---| | Product (`product`) | `category`, `measure`; `organizations[]` — where it is available; `parent_id` on a variant | [`POST /product/get-paging`](https://docs.bito.uz/en/api/product.md#post-product-get-paging) | | Price list (`price`) | `currency_id`; `type` — `sale` or `income` | [`GET /price/get-all`](https://docs.bito.uz/en/api/price.md#get-price-get-all) | | Product price | `product` × `price_id` × organization → `amount` | [`POST /price/items/get-paging`](https://docs.bito.uz/en/api/price.md#post-price-items-get-paging) | | Stock (`product-warehouse`) | `product_id` × `warehouse_id`, `organization_id` | [`POST /product-warehouse/get-paging`](https://docs.bito.uz/en/api/product-warehouse.md#post-product-warehouse-get-paging) | | Batch (`product-stock`) | `product`, `warehouse`, cost and its currency | [`POST /product-stock/get-paging`](https://docs.bito.uz/en/api/product-stock.md#post-product-stock-get-paging) | A product does not belong to a single organization: the catalog is shared, while availability, prices and stock are per organization. How to read stock: [stock and prices](https://docs.bito.uz/en/guide/recipes/stock-prices.md); what changes it: [warehouse documents](https://docs.bito.uz/en/guide/concepts/warehouse.md). ## Customer, order, sale, transaction | Entity | References | Read | |---|---|---| | Customer (`customer`) | `organization_ids`, `category_id` | [`POST /customer/get-paging`](https://docs.bito.uz/en/api/customer.md#post-customer-get-paging) | | Order (`sale-order`) | `organization_id`, `customer_id`, `price_id`; on a line `product_id`, `price_id`, `warehouse_id` | [`GET /sale-order/get-by-id/{id}`](https://docs.bito.uz/en/api/sale-order.md#get-sale-order-get-by-id-id) | | Sale (`trade`) | `organization`, `customer_id`, `warehouse_id`, `price_id`; `order_id` — the order it came from; `refund_id` — the original sale of a refund | [`GET /trade/get-by-id/{id}`](https://docs.bito.uz/en/api/trade.md#get-trade-get-by-id-id) | | Sale line | `_id` — the product, `item_id` — the line, `warehouse` | [`GET /trade/get-items/{id}`](https://docs.bito.uz/en/api/trade.md#get-trade-get-items-id) | | Transaction (`transaction`) | `organization_id`, `cashbox_id`, `payment_method`, `payment_type`; `customer_id`, `trade_id`, `invoice_id` | [`POST /transaction/get-paging`](https://docs.bito.uz/en/api/transaction.md#post-transaction-get-paging) | - `sale-order` is a customer's order, `trade` is the sale itself. How one becomes the other: [the sale lifecycle](https://docs.bito.uz/en/guide/concepts/sale-lifecycle.md). - A transaction is a movement of money. On a credit sale the payment can arrive later or in parts, so count sale totals and cash movement separately. ## Storing it in your system - Link records by `_id`. Names and numbers (`number`, `uuid`) are for display. - Deletes are [soft](https://docs.bito.uz/en/guide/api.md#soft-delete): a stored `_id` can point at a deleted record. Products, warehouses, customers and orders have a `get-deleted` method. - Track changes with the `updated_at` filter (where a method has it) and [webhooks](https://docs.bito.uz/en/guide/webhooks.md). --- # Sale and order states | Document | What it is | In the admin panel | |---|---|---| | `sale-order` | A customer's **order**: an intention, not yet a sale | CRM › Orders | | `trade` | **The sale itself**: it affects stock, money and the customer balance | Sale › Sales | On both, `state` is the status and `state_id` is the pipeline (kanban) column. To list the columns: ```json POST /states/get-all { "type": "saleOrders", "organization_id": "6712f0a9c4d1e87b3a0f9911" } ``` For sales, `type` is `trades`. Each column comes with `_id`, `default_key` and `is_default`. An integration with declared permissions cannot call this method. ## Sale (`trade`) | `state` | Stock | Can move to | |---|---|---| | `new` | Goods reserved: `amount` is down, `booked` is up | `in_progress`, `done`, `canceled` | | `in_progress` | Reserved the same way | `done`, `canceled` | | `done` | Goods sold, reservation released | `canceled` | | `canceled` | Goods returned | nowhere | `payments` are posted to the cashbox when the sale is created, whatever the state. | Action | Call | |---|---| | Create | [`POST /trade/create`](https://docs.bito.uz/en/api/trade.md#post-trade-create), `state`: `new`, `in_progress` or `done` | | Change state | [`PUT /trade/set-state`](https://docs.bito.uz/en/api/trade.md#put-trade-set-state): `{ "_id", "state" }` | | Move to a pipeline column | [`PUT /trade/set-state-id`](https://docs.bito.uz/en/api/trade.md#put-trade-set-state-id): `{ "_id", "state_id" }`. A default column sets its own state, any other sets `in_progress` | | Refund | [`POST /trade/refund`](https://docs.bito.uz/en/api/trade.md#post-trade-refund) — a new `trade` (`is_refund: true`, `done`); [recipe](https://docs.bito.uz/en/guide/recipes/sale.md#refund) | A move that is not in the table returns `code: 149002`; sending the current state again changes nothing. Moving to `done` with a debt checks the debt-sale rules. The Integration API has no method to edit or delete a sale. ## Cancel a sale ```json PUT /trade/set-state { "_id": "6712f0a9c4d1e87b3a0f9988", "state": "canceled", "with_transactions": true, "with_cashbacks": true } ``` - The goods return to the warehouse. - `with_transactions: true` cancels the payment transactions too. For a sale with a customer, if you leave it out the money stays in the cashbox. For a sale without a customer the payment is always canceled. - `with_cashbacks: true` reverses cashback as well. - A sale that has a refund cannot be canceled (`149009`). ## Order (`sale-order`) | `state` | Meaning | |---|---| | `in_progress` | Being worked on. An order created by an integration lands in the first regular column with this state | | `new` | New (a default column) | | `accepted`, `draft` | May appear in API responses | | `done` | Sold | | `canceled` | Canceled | | Action | Call | |---|---| | Create | [`POST /sale-order/create`](https://docs.bito.uz/en/api/sale-order.md#post-sale-order-create) | | Take into work | [`PUT /sale-order/accept/{id}`](https://docs.bito.uz/en/api/sale-order.md#put-sale-order-accept-id) — `in_progress`, first regular column | | Change column, cancel | `POST /sale-order/update-status-many`: `{ "ids": [], "state_id" }` | | Edit contents | [`PUT /sale-order/update`](https://docs.bito.uz/en/api/sale-order.md#put-sale-order-update) | | Sell | `POST /trade/create` with `order_id` | | Delete | [`DELETE /sale-order/delete/{id}`](https://docs.bito.uz/en/api/sale-order.md#delete-sale-order-delete-id) — soft delete | Details that matter: - **`create`:** an order cannot be created as `canceled`. If duplicate control is on in CRM settings, the response may be an **existing** order rather than a new one. - **`accept`**: do not call it on a `done` or `canceled` order. - **`update-status-many`:** to cancel, send the column with `default_key: "canceled"`. An order cannot be moved into the `new` column; a `canceled` order does not change; from `done` only to `canceled`; only an order that has a sale can enter the `done` column. The work runs in the background and the response does not carry the outcome — re-read the orders to check. - **`update`** does not change the state and replaces the lines entirely: send all of them. A `done` or `canceled` order cannot be edited (`151002`). **Reservation.** With `booking_product_in_order` on in sale settings, an order in `new`, `accepted` or `in_progress` reserves goods; `done`, `canceled` and deletion release them. ## From order to sale Send `order_id` to `POST /trade/create`, and `order_item_id` on each line. Its value is the line's **`item_id`** from the `sale-order/get-by-id` response (not `_id`, which is the product id). The other required fields are as for an [ordinary sale](https://docs.bito.uz/en/guide/recipes/sale.md). - Customer and organization are taken from the order; the currency must match the order's (`149015`). - The order's whole reservation is released. After a partial sale the remainder is not reserved again automatically. - `trade_status`: `zero` → `partial` → `fully`. A fully sold order becomes `done`, even when the sale is `new` or `in_progress`. - Selling more than was ordered is rejected unless overselling is allowed (`151005`). - Canceling the sale lowers the sold quantity, but the order stays `done`. - Do not record a sale against a canceled order. - An advance paid on the order is not applied to the sale automatically — send it from the customer's balance in `by_balance` ([reference](https://docs.bito.uz/en/api/trade.md#post-trade-create)). ## Tracking Get state changes through [webhooks](https://docs.bito.uz/en/guide/webhooks.md) (`saleOrders.status_change`, `trades.*`) and re-read the document with `get-by-id`. Terms: [glossary](https://docs.bito.uz/en/guide/glossary.md#confusions). --- # Warehouse documents You cannot write stock directly through the API — it changes as a result of documents. The counters per product × warehouse are `amount` (available to sell), `booked`, `in_transit`, `on_the_way` and `in_trash` — see [stock and prices](https://docs.bito.uz/en/guide/recipes/stock-prices.md). ## What the API exposes | Document | Create | State changes | Read permission | |---|---|---|---| | Order to a supplier (`purchase-order`) | Yes | `set-state` | `purchase_order` | | Purchase (`purchase`) | Yes | `set-state` | `purchase` | | Income (`income`) | Yes, against a purchase | `cancel` | `income` | | Return to a supplier (`purchase-return`) | No | No | `purchase_return` | | Internal transfer (`internal-transfer`) | Yes | `set-status`, `receive` | `internal_transfer` | | Transfer between organizations (`organizational-transfer`) | Yes | `set-status`, `receive` | `organizational_transfer` | | Write-off (`write-off`) | Yes | `set-status` | `write_off` | | Stocktaking (`revision`) | Yes | `set-status` | `revision_customer_cashback` | The exact permission of every method is in [Permissions](https://docs.bito.uz/en/api/permissions.md). All of them have `get-paging` and `get-by-id/{id}`. `create` methods are not idempotent. ## Order to a supplier `new` → `accepted` or `in_progress` → `done`; `canceled` only from `new`. `state: "new"` is required on create. **No effect on stock.** Methods: [`create`](https://docs.bito.uz/en/api/purchase-order.md#post-purchase-order-create), [`set-state`](https://docs.bito.uz/en/api/purchase-order.md#put-purchase-order-set-state). ## Purchase and income A purchase goes `new` → `in_progress` → `done`; `canceled` from any state. It is created as `new` or `in_progress`, and `update` works only while `new`. | Action | Stock | |---|---| | Purchase → `in_progress` | `on_the_way` goes up | | Purchase → `done` | Stock does not change: the supplier balance and an invoice are recorded | | Creating an income | `on_the_way` goes down, `amount` goes up in the income's warehouse | | Cancelling an income | The reverse. If the goods were already used, it fails | | Cancelling a purchase | `on_the_way` is rolled back; for a `done` purchase its incomes are cancelled too. If an `in_progress` purchase is already partly received, cancel those incomes first | ::: tip Which warehouse holds on_the_way `on_the_way` is recorded on the organization's first warehouse, which may not be the warehouse named in the purchase. If you need a product total, add the warehouses up. ::: Through the API an income is created only against a purchase: it needs `purchases[].purchase_id` and a `purchase_item_id` on every line, and the purchase must have been moved to `in_progress`. An income is `done` at once. A purchase created with `is_auto_income: true` becomes `done` and records its income itself. Methods: [`purchase/create`](https://docs.bito.uz/en/api/purchase.md#post-purchase-create), [`purchase/set-state`](https://docs.bito.uz/en/api/purchase.md#put-purchase-set-state), [`income/create`](https://docs.bito.uz/en/api/income.md#post-income-create), [`income/cancel`](https://docs.bito.uz/en/api/income.md#put-income-cancel). ## Return to a supplier States: `done`, `canceled`. A return lowers `amount` in the warehouse. The API is read-only here: [`get-paging`](https://docs.bito.uz/en/api/purchase-return.md#post-purchase-return-get-paging) — the document is created in Bito. ## Transfers An internal transfer moves goods between the warehouses of one organization; an organizational transfer sends them to another organization's warehouse. Both are created with `state: "new"` and can be edited while `new`. | Transition | How | Stock | |---|---|---| | `new` → `accepted` | `set-status` | In the sending warehouse `amount` goes down, `in_transit` goes up | | `accepted` → `in_progress` | `set-status` | No change | | `accepted`, `in_progress` → `done` | `receive` | Sender's `in_transit` goes down, receiver's `amount` goes up | | → `canceled` | `set-status` | From `new`, no change; otherwise the goods return to the sending warehouse | `done` cannot be set with `set-status` — only `receive` does it. Mind two differences: | | `set-status` body | `receive` body | |---|---|---| | Internal | `{ "status": "accepted" }` | empty | | Organizational | `{ "state": "accepted" }` | `{ "receiver_warehouse_id": "…" }` — a warehouse of the receiving organization | Methods: [Internal transfer](https://docs.bito.uz/en/api/internal-transfer.md), [Organizational transfer](https://docs.bito.uz/en/api/organizational-transfer.md). ## Write-off Created directly as `done`; the only transition is to `canceled`. `amount` goes down; for `defect`, `in_trash` goes up. Step by step: [write-off recipe](https://docs.bito.uz/en/guide/recipes/write-off.md). ## Stocktaking `pending` → `in_progress` → `done`; `canceled` from `pending` or `in_progress`. A `done` document cannot be cancelled. `update` works only while `pending`. Pass the state to `set-status` as `{ "status": "…" }`. Creating it and moving it to `in_progress` do not change stock. `done` sets the stock of every listed product to its **counted quantity** and issues invoices for the surplus or shortage. ::: danger Do not complete it uncounted The API has no method for entering counted quantities. Without `set_counted`, the counted quantity of every line is `0`: if you set `done` before staff have counted in Bito, **the stock of the listed products drops to zero**, and it cannot be cancelled. ::: Methods: [Revision](https://docs.bito.uz/en/api/revision.md). ## Webhooks There are events for `purchaseOrders`, `purchases`, `purchaseReturns` and `incomes` ([webhooks](https://docs.bito.uz/en/guide/webhooks.md)). There are none for transfers, write-offs or stocktaking — poll them with `get-paging`. An app that declares `required_permissions` cannot subscribe to webhooks. Sales documents are not covered here — see [the sale lifecycle](https://docs.bito.uz/en/guide/concepts/sale-lifecycle.md). --- # Calling the API The Integration API is the surface your integration reads and writes merchant data through. It is one base URL, one envelope and 464 endpoints. | Environment | Base URL | |---|---| | Production | `https://api.bito.uz/integration-api/integration/api/v2/` | | Dev | `https://api.systematicdev.uz/integration-api/integration/api/v2/` | The full endpoint list, with request and response schemas for each, is the [API reference](https://docs.bito.uz/en/api/index.md). ## Two ways to authenticate Both reach the same endpoints and the same data. Pick by how many merchants you serve. | | API key | OAuth 2.0 | |---|---|---| | Header | `api-key: :` | `Authorization: Bearer ` | | Serves | One account — yours | Many accounts | | Expires | Never | Access token 24h, refresh 90d | | Setup | Copy it from the integration | Merchant installs and approves | | Use for | Your own back office, scripts, one-merchant integrations | Marketplace integrations | ### API key Send your `api_key` in the `api-key` header. No token exchange, no expiry. ```http POST https://api.bito.uz/integration-api/integration/api/v2/product/get-paging api-key: mycompany:9ad41c0e7b3f28d5610ac94e7f1b26d8 Content-Type: application/json { "page": 1, "limit": 20 } ``` ### OAuth 2.0 Each merchant's install produces its own token pair, and the token carries the account context — so every call is automatically scoped to that merchant's data and you never pass an account id. ```http POST https://api.bito.uz/integration-api/integration/api/v2/product/get-paging Authorization: Bearer eyJhbGciOiJIUzI1NiIs... Content-Type: application/json { "page": 1, "limit": 20 } ``` Getting that token is its own chapter: [OAuth 2.0 overview](https://docs.bito.uz/en/guide/oauth/index.md). ## Conventions you have to know ### HTTP methods The method is part of each endpoint's contract: | Method | Used for | Example | |---|---|---| | `POST` | Create a record, and every list or filter query | `POST /product/create`, `POST /product/get-paging` | | `PUT` | Update a record, or change its state | `PUT /product/update`, `PUT /production-operation/set-state` | | `GET` | Read one record by id, and id-only reads | `GET /product/get-by-id/{id}`, `GET /product/get-deleted` | | `DELETE` | Delete a record | `DELETE /product/delete/{id}` | Lists are `POST` because their filters are a JSON body, not a query string. Every endpoint page in the [API reference](https://docs.bito.uz/en/api/index.md) states its own method. ::: warning The Bito **admin** API — the one the web panel talks to — is POST-only. The Integration API is not. Do not carry that assumption across. ::: ### Request headers | Header | Required | Description | |---|---|---| | `api-key` *or* `Authorization` | Yes | One of the two auth methods above | | `Content-Type` | Yes | `application/json` | | `Accept-Language` | No | `uz`, `uz_cyrillic`, `ru`, `en`, `kk`, `tg`, `ky`. Default `uz`. Sets the language of `message`. | | `organization_id` | No | Target organization inside the account. Used only when the integration's settings (`fields`) include the `organization_id` field — otherwise the header is ignored. When the header is absent, that field's value is used. | | `warehouse_id` | No | Target warehouse. Used only when the integration's settings (`fields`) include the `warehouse_id` field — otherwise the header is ignored. When the header is absent, that field's value is used. | | `price_id` | No | Price list to read prices from. Used only when the integration's settings (`fields`) include the `price_id` field — otherwise the header is ignored. When the header is absent, that field's value is used. | | `role_id` | No | Value for the `role_id` setting. Used only when the integration's settings (`fields`) include the `role_id` field — otherwise the header is ignored. When the header is absent, that field's value is used. Access to API methods is set by `required_permissions`. | | `user_id` | No | Run the request as this user. The user must belong to this account and not be blocked, otherwise the request is refused with `403`. When absent, the request runs as the account owner. | | `source_id` | No | Create calls only: attribute the new record to another source of your integration. The source must belong to your integration. Without the header, records get the source assigned at install. | Most methods expect the organization and price list in the request **body** — check each one in the [API reference](https://docs.bito.uz/en/api/index.md). ### The response envelope Every response, success or failure, has the same shape. ```json { "code": 0, "message": "Success", "status_code": 200, "messages": { "uz": "Muvaffaqiyatli", "ru": "Успешно", "en": "Successful" }, "data": { }, "time": "2025-05-01T12:00:00Z" } ``` | Field | Meaning | |---|---| | `code` | `0` on success, an error code otherwise. **Branch on this.** | | `message` | Human text in the `Accept-Language` language. Do not parse it. | | `messages` | The same text in `uz`, `ru` and `en`. | | `status_code` | HTTP status. | | `data` | The payload on success. Errors carry no payload; some put a detail here, such as the missing permission. | | `time` | Server time, ISO 8601. | ### Pagination Every `get-paging` endpoint takes `page` and `limit` and returns a total alongside the rows. **Request** ```json { "page": 1, "limit": 50 } ``` | Field | Type | Default | Limits | |---|---|---|---| | `page` | number | `1` | ≥ 1 | | `limit` | number | `20` | 1 – 200 | **Response** ```json { "code": 0, "message": "Success", "status_code": 200, "data": { "total": 1043, "data": [ { "_id": "6712f0a9c4d1e87b3a0f9911", "name": "Espresso" } ] }, "time": "2025-05-01T12:00:00Z" } ``` Note the nesting: the rows are at `data.data`, the count at `data.total`. Page until `page * limit >= total`. ::: tip Most `get-paging` endpoints also accept filters next to `page`/`limit` — `updated_at` in particular lets you pull only what changed since your last sync. Check the endpoint in the [API reference](https://docs.bito.uz/en/api/index.md). ::: ### Deletion is always soft Bito never physically deletes a record; a `delete` call marks it deleted. This matters for you in two ways: a `get-deleted` endpoint exists for most resources, and an id you cached can come back as deleted rather than disappearing. ### Identifiers Every `_id` is a 24-character MongoDB ObjectId, for example `6712f0a9c4d1e87b3a0f9911`. Treat it as an opaque string. ## Errors An error response carries a non-zero `code`. When there is more detail, it is in `data`. ```json { "code": 10004, "message": "Unauthorized user", "status_code": 401, "messages": { "uz": "...", "ru": "...", "en": "Unauthorized user" }, "time": "2025-05-01T12:00:00Z" } ``` | HTTP | What went wrong | What to do | |---|---|---| | 400 | Validation failed, a referenced record does not exist, or the API key is wrong (`115006`, `11000`) | Read `code`, `message` and `data` — [Error codes](https://docs.bito.uz/en/guide/errors.md) | | 401 | Missing, malformed or expired credentials | Re-check the header; [refresh the token](https://docs.bito.uz/en/guide/oauth/tokens.md#refresh) | | 403, `code: 10003` | The permission for this action was not approved at install; `data` names the permission key | Add it to `required_permissions`; it works once the merchant [approves the new list](https://docs.bito.uz/en/guide/oauth/index.md#permissions) | | 403, `code: 10024` | The request came from an address outside `ip_whitelist` | Add your server's address to the list — see [Create an integration](https://docs.bito.uz/en/guide/create.md) | | 404 | No such endpoint | Check the path against the [API reference](https://docs.bito.uz/en/api/index.md) | | 400, `code: 10021` | Rate limited — [Too Many Requests](https://docs.bito.uz/en/guide/faq.md#rate-limit) | Back off and retry | | 503, `code: 10032`, or 400, `code: 10000` | Bito-side failure or an unexpected error | Retry with backoff; if it persists, [contact support](https://docs.bito.uz/en/guide/support.md) | The common codes: [Error codes](https://docs.bito.uz/en/guide/errors.md). ::: warning Do not retry a `400` unchanged and do not retry a write blindly — Bito write endpoints are not idempotent, so a repeated `create` creates a second record. ::: ## Next - [Custom widgets](https://docs.bito.uz/en/guide/widget.md) — run your own app inside the Bito admin panel - [Data webhooks](https://docs.bito.uz/en/guide/webhooks.md) — get told when data changes instead of polling - [API reference](https://docs.bito.uz/en/api/index.md) — all 464 endpoints --- # OAuth 2.0 overview OAuth 2.0 lets your application call the Bito API **on behalf of a merchant account**. The tokens Bito issues carry the tenant context, so every call is automatically scoped to that merchant's data — you never pass an account id yourself. ::: tip If you only ever serve **one** account — your own — you do not need OAuth. Send the `api-key` header instead; see [Calling the API](https://docs.bito.uz/en/guide/api.md). ::: ## The two ways a code reaches you There are two ways your application can obtain an authorization code. Both end at the same token endpoint, and both give you the same `access_token` + `refresh_token` pair. | You are building | Use | Who starts it | |---|---|---| | A marketplace integration merchants install from inside Bito | [Install flow (Flow A)](https://docs.bito.uz/en/guide/oauth/install-flow.md) | The merchant, in the Bito admin panel | | Your own product, where the merchant clicks "Connect Bito" in *your* UI | [Connect flow (Flow B)](https://docs.bito.uz/en/guide/oauth/connect-flow.md) | Your application | | A background job with no user present, for a merchant that already installed you | [Client credentials grant](https://docs.bito.uz/en/guide/oauth/tokens.md#client-credentials) | Your server | ```text Flow A Flow B (Bito-initiated) (you-initiated) Merchant clicks Install in Bito Merchant clicks Connect in your app | | v v Bito POSTs the code to your You redirect to id.bito.uz, the redirect_uri merchant logs in, Bito redirects | back with ?code= | | +-----------------+-----------------+ | v POST /auth/oauth/token (grant_type=authorization_code) | v access_token + refresh_token ``` ## Scopes Scopes control how much access the merchant grants you. | Scope | Value | Description | |---|---|---| | Admin | `admin` | Full administrative access to all resources | | Read | `read` | Read-only access | | Write | `write` | Create and update resources | | Delete | `delete` | Delete resources | ## Permissions: the real control Every Integration API request — with an OAuth token or with an `api-key` — is checked like this: 1. **`required_permissions` → `granted_permissions`.** Your app declares the ERP permissions it uses on the Integration API (`required_permissions`, the same keys roles are built from). The merchant sees exactly that list before installing, and installing writes a copy of it onto the integration as `granted_permissions`. Every call is checked against that copy; a call outside it is refused. If you change `required_permissions` later, an account that already installed you keeps the old copy until the merchant approves the new list — by reinstalling or, for a widget, by accepting its consent screen again. An empty list means all permissions. Once the list is not empty, resources with no permission key are closed too (except `organization/get-all` and `get-by-id`). 2. **`available_scopes`.** A legacy check for clients that have `available_scopes` set: the scope matching the call's action (`read`, `write` or `delete`; `admin` covers all) must be on that list, or the call is refused. Either refusal is `403` with `code: 10003`. Declare the narrowest `required_permissions` list that works — it is what the merchant reads to know what they are agreeing to before installing. See [Create an integration](https://docs.bito.uz/en/guide/create.md). ## Endpoints | Method | Path | Auth | Purpose | |---|---|---|---| | `POST` | `/auth/oauth/auth` | None | Client credentials grant | | `POST` | `/auth/oauth/token` | None | Exchange an authorization code, or refresh a token pair | | `POST` | `/auth/get-one-time-token` | Bearer (user session) | Mint a [one-time token](https://docs.bito.uz/en/guide/oauth/one-time-tokens.md) | Base URL: `https://api.bito.uz/auth-api` in production, `https://api.systematicdev.uz/auth-api` on dev — for example, `POST https://api.bito.uz/auth-api/auth/oauth/token`. --- # Install flow (Flow A) This is the flow for a marketplace integration. It starts inside Bito: a merchant opens **Integration → Integration** (in web-pos, **Settings → Integrations**), finds your integration in the marketplace and presses its install button (**Install free** or **External payment**). Bito then delivers an authorization code straight to your server. Nothing is redirected through the merchant's browser, so you do not need a callback page — only a callback **endpoint**. ```text Merchant (in Bito) Bito Your server | | | | 1. presses Install | | |------------------------->| | | | 2. POST redirect_uri | | | { code, client_id, | | | account_id } | | |--------------------------->| | | | | | 3. POST /auth/oauth/token | | |<---------------------------| | | { access_token, | | | refresh_token } | | |--------------------------->| | | | | 4. uses your integration| | ``` ## 1. The merchant installs your integration Nothing to implement. The **Install** button appears for every merchant once your integration is `PUBLIC`; while it is `PRIVATE` only your own account sees it, which is exactly what you want while developing. ## 2. Bito posts the authorization code to your `redirect_uri` Bito sends a `POST` — not a redirect — to the `redirect_uri` you registered when you [created the integration](https://docs.bito.uz/en/guide/create.md). **Request Bito sends you** ```http POST https://your-app.example.com/bito/install Content-Type: application/json X-Bito-Signature: t=1736937000,v1=6b1f0a...c94e { "code": "abc123def456", "client_id": "69c50a2d50f7b939923a469b", "account_id": "507f1f77bcf86cd799439011" } ``` | Field | Description | |---|---| | `code` | The authorization code. Single use, expires in 20 minutes. | | `client_id` | Your OAuth client id — check it matches yours before acting. | | `account_id` | The merchant account that installed you. Store it: this is how you tell your tenants apart. | | `X-Bito-Signature` | Request signature — see below. | ::: warning Verify the request really came from Bito This POST is signed with your `client_secret`. Only Bito and you hold that secret, so a matching signature proves the request is genuine and a third party cannot forge an install. - Header format: `X-Bito-Signature: t=,v1=` - `v1 = HMAC_SHA256(client_secret, "{t}.{raw_body}")` — computed over the **exact raw request body**, byte for byte. Do not re-serialize the JSON. - Recompute `v1` and compare it with the header in constant time; reject the request if they differ. - Reject requests whose `t` is more than ~5 minutes from the current time — this blunts replay attacks. - Also confirm `client_id` and `account_id` match the tenant you expect. ::: **Example (Node.js)** ```js const crypto = require('crypto'); function verifyBitoSignature(rawBody, headers, clientSecret, now = Date.now()) { const m = /t=(\d+),v1=([a-f0-9]+)/.exec(headers['x-bito-signature'] || ''); if (!m) return false; const [, t, v1] = m; if (Math.abs(now / 1000 - Number(t)) > 5 * 60) return false; // stale / replay const expected = crypto .createHmac('sha256', clientSecret) .update(t + '.' + rawBody) .digest('hex'); const a = Buffer.from(expected, 'hex'); const b = Buffer.from(v1, 'hex'); return a.length === b.length && crypto.timingSafeEqual(a, b); } ``` ::: warning Answer with `2xx` quickly and do the token exchange in the background if you need to. Bito does not retry this call. ::: ## 3. Exchange the code for tokens Within 20 minutes, call the token endpoint from your server — never from a browser, because the call carries your `client_secret`. See [Working with tokens → Exchanging the authorization code](https://docs.bito.uz/en/guide/oauth/tokens.md#exchange). ## 4. Store the tokens against the account Keep `access_token`, `refresh_token` and `account_id` together. One merchant equals one token pair. When the access token expires, [refresh it](https://docs.bito.uz/en/guide/oauth/tokens.md#refresh). ::: tip Also implement the [uninstall hook](https://docs.bito.uz/en/guide/lifecycle-hooks.md#uninstall) so you can drop the merchant's data when they remove your integration. ::: --- # Connect flow (Flow B) This is the flow when the merchant starts from **your** product — a "Connect Bito" button in your own UI. You send the merchant to the Bito login page, Bito authenticates them, and Bito redirects back to you with an authorization code in the query string. ```text Your app Merchant browser Bito | | | | 1. redirect to | | | id.bito.uz/oauth/auth | | |--------------------------->| | | | 2. log in | | | (phone + password) | | |----------------------->| | | | | | 3. pick account, | | | approve scopes | | |----------------------->| | | | code, 20 min TTL | | 4. redirect back | | | ?code=X&state=Y | | |<-----------------------| | callback?code=X&state=Y | | |<---------------------------| | | | | 5. POST /auth/oauth/token | |---------------------------------------------------->| | { access_token, refresh_token, expires_in } | |<----------------------------------------------------| ``` ## 1. Send the merchant to Bito ```text https://id.bito.uz/oauth/auth ?response_type=code &client_id= &redirect_uri= &scope= &state= ``` **Example** ```text https://id.bito.uz/oauth/auth?response_type=code&client_id=69c50a2d50f7b939923a469b&redirect_uri=https%3A%2F%2Fexample-app.com%2Fcallback&scope=admin&state=xcoiv98y2kd22vusuye3kch ``` | Parameter | Required | Description | |---|---|---| | `response_type` | Yes | Must be `code` | | `client_id` | Yes | Your OAuth client id | | `redirect_uri` | Yes | URL-encoded callback. Send the `redirect_uri` registered on your integration. | | `scope` | Yes | Requested scopes: `admin`, `read`, `write`, `delete` | | `state` | Strongly recommended | Opaque random value. Bito returns it unchanged — compare it on the way back to stop CSRF. | `/oauth/auth` is the canonical authorize address. If the merchant is not signed in yet, Bito sends them to the login page with the same parameters and resumes the authorization after they sign in. ## 2. The merchant authenticates Bito owns this screen entirely. The merchant enters their phone number and password, picks which account to grant access to if they own several, and approves the scopes you asked for. The merchant must be the **owner or an additional owner** of the chosen account — an ordinary employee cannot connect it. The account's onboarding must also be complete, otherwise exchanging the code for tokens is refused. ::: info You do not implement any login UI, and you never see the merchant's password. ::: ## 3. Bito redirects back with the code ```text https://example-app.com/callback?code=abc123def456&state=xcoiv98y2kd22vusuye3kch ``` | Parameter | Description | |---|---| | `code` | The authorization code. Single use, expires in 20 minutes. | | `state` | The exact value you sent in step 1. **Reject the callback if it does not match.** | ## 4. Exchange the code for tokens Same call as Flow A: [Working with tokens → Exchanging the authorization code](https://docs.bito.uz/en/guide/oauth/tokens.md#exchange). ::: warning The exchange must happen server-side. Anything holding your `client_secret` is your backend, never the merchant's browser. ::: --- # Working with tokens Every flow ends at the same place: an `access_token` you send with each API call, and a `refresh_token` you use to get a new pair when it expires. ## Exchanging the authorization code Identical for [Flow A](https://docs.bito.uz/en/guide/oauth/install-flow.md) and [Flow B](https://docs.bito.uz/en/guide/oauth/connect-flow.md). **Request** ```http POST /auth/oauth/token Content-Type: application/json { "grant_type": "authorization_code", "code": "abc123def456", "client_id": "69c50a2d50f7b939923a469b", "client_secret": "4f3c1a9e8b27d605f1ac93e7d284b6510ff7a3c9e15d8b2470a6cd91e83f4b27" } ``` | Field | Type | Required | Description | |---|---|---|---| | `grant_type` | string | Yes | Must be `"authorization_code"` | | `code` | string | Yes | The authorization code Bito gave you | | `client_id` | string | Yes | Your OAuth client id | | `client_secret` | string | Yes | Your client secret | **Response** ```json { "code": 0, "message": "Success", "data": { "access_token": "eyJhbGciOiJIUzI1NiIs...", "refresh_token": "eyJhbGciOiJIUzI1NiIs...", "expires_in": 86400, "token_type": "Bearer", "scope": "read write" } } ``` `expires_in` is in seconds, counted from the moment of issue. ::: warning An authorization code is single-use and dies after 20 minutes. Exchanging it twice returns `Invalid credentials`, not a second token pair. ::: ## Refreshing tokens **Request** ```http POST /auth/oauth/token Content-Type: application/json { "grant_type": "refresh_token", "refresh_token": "eyJhbGciOiJIUzI1NiIs...", "client_id": "69c50a2d50f7b939923a469b", "client_secret": "4f3c1a9e8b27d605f1ac93e7d284b6510ff7a3c9e15d8b2470a6cd91e83f4b27" } ``` The response shape is identical to the code exchange. ::: warning **Both tokens rotate on every refresh.** The refresh token you just used stops working — persist the new pair atomically, or the next refresh will fail and the merchant will have to reinstall. ::: Refreshing never re-installs an integration the merchant removed. After an uninstall, API calls are rejected (`Integration is not installed`); treat your [uninstall hook](https://docs.bito.uz/en/guide/lifecycle-hooks.md#uninstall) as the signal to stop calling. ## Client credentials grant For server-to-server work with no user present. It goes to a different endpoint — `/auth/oauth/auth`, not `/auth/oauth/token` — and returns tokens immediately, with no authorization code in between. ::: warning **Prerequisite: the merchant must already have installed your integration.** This grant authenticates against the per-install integration record, so there is nothing to match before the first install. ::: **Request** ```http POST /auth/oauth/auth Content-Type: application/json { "response_type": "client_credentials", "client_id": "69c50a2d50f7b939923a469b", "client_secret": "4f3c1a9e8b27d605f1ac93e7d284b6510ff7a3c9e15d8b2470a6cd91e83f4b27", "redirect_uri": "https://example-app.com/callback", "scope": ["read", "write"], "state": "optional_state" } ``` | Field | Type | Required | Description | |---|---|---|---| | `response_type` | string | Yes | Must be `"client_credentials"` | | `client_id` | string | Yes | Your OAuth client id | | `client_secret` | string | Yes | The secret of the integration install | | `redirect_uri` | string | Yes | Must be a valid URL. Validated even though this grant never redirects — send your registered callback. | | `scope` | string[] | Yes | Requested scopes, as an array | | `state` | string | No | Opaque value, echoed back | **Response** ```json { "code": 0, "message": "Success", "data": { "access_token": "eyJhbGciOiJIUzI1NiIs...", "refresh_token": "eyJhbGciOiJIUzI1NiIs...", "expires_in": 86400, "token_type": "Bearer", "scope": "read write" } } ``` ## Using access tokens Send the token in the `Authorization` header on every call. ```http POST /integration/api/v2/product/get-paging Authorization: Bearer eyJhbGciOiJIUzI1NiIs... Content-Type: application/json Accept-Language: en { "limit": 20, "page": 1 } ``` | Header | Required | Description | |---|---|---| | `Authorization` | Yes | `Bearer ` | | `Accept-Language` | No | Response language: `uz`, `uz_cyrillic`, `ru`, `en`, `kk`, `tg`, `ky`. Default `uz`. | | `organization_id` | No | Target organization inside the account. Used only when the integration's settings (`fields`) include the `organization_id` field — otherwise the header is ignored. When the header is absent, that field's value is used. | | `warehouse_id` | No | Target warehouse. Used only when the integration's settings (`fields`) include the `warehouse_id` field — otherwise the header is ignored. When the header is absent, that field's value is used. | | `price_id` | No | Price list to read prices from. Used only when the integration's settings (`fields`) include the `price_id` field — otherwise the header is ignored. When the header is absent, that field's value is used. | | `role_id` | No | Value for the `role_id` setting. Used only when the integration's settings (`fields`) include the `role_id` field — otherwise the header is ignored. When the header is absent, that field's value is used. | | `user_id` | No | Run the request as this user. The user must belong to this account and not be blocked, otherwise the request is refused. When absent, the request runs as the account owner. | | `source_id` | No | Create calls only — same as with an API key, see [Request headers](https://docs.bito.uz/en/guide/api.md#request-headers). | You never send an account id — the token already carries it. ## Token lifetimes | Token | Lifetime | Notes | |---|---|---| | Authorization code | 20 minutes | Single use, must be exchanged inside the window | | Access token | 24 hours | Sent in the `Authorization` header | | Refresh token | 90 days | Exchanged for a new pair; rotates on every use | | One-time token | 24 hours | Single use, signed with your client secret — see [One-time tokens](https://docs.bito.uz/en/guide/oauth/one-time-tokens.md) | ::: warning [Rotating your client secret](https://docs.bito.uz/en/guide/rotate.md#client-secret) kills every access and refresh token issued under the old one, in **every** merchant account at once. ::: ## Rate limits `/auth/oauth/auth` and `/auth/oauth/token` allow **200 requests per minute per IP**. Refresh on expiry, not on a timer, and never per request. --- # One-time tokens A one-time token is a JWT signed with **your client secret**, so your application can verify it on its own without calling Bito. It is what Bito appends to your widget's iframe URL, and it is the right tool whenever Bito has to hand a browser something your backend must trust. ## Minting one Requires a logged-in Bito user session — not an integration token. The integration must be **installed** in that account, otherwise the call is refused with `Integration is not installed`. **Request** ```http POST /auth/get-one-time-token Authorization: Bearer Content-Type: application/json { "client_id": "69c50a2d50f7b939923a469b" } ``` **Response** ```json { "code": 0, "message": "Success", "data": "eyJhbGciOiJIUzI1NiIs..." } ``` ## Claims | Claim | Description | |---|---| | `iss` | Issuer: `https://{subdomain}.{domain}` | | `aud` | Audience: your client's `redirect_uri` | | `jti` | Unique token id (UUID) | | `nbf` | Not-before timestamp | | `account_id` | The merchant account | | `user_id` | The Bito user who opened your app | | `subdomain` | The account's subdomain | | `client_id` | Your OAuth client id | | `exp` | Expiry, 24 hours after issue | ## Verifying The token is signed **HS256 with your client secret**. Verify it before trusting anything in it. ```js import jwt from 'jsonwebtoken'; export function verifyOneTimeToken(token, secret, clientId) { // Throws on a bad signature, a expired token, or one issued before `nbf`. const claims = jwt.verify(token, secret, { algorithms: ['HS256'] }); if (claims.client_id !== clientId) throw new Error('token belongs to another client'); return { accountId: claims.account_id, userId: claims.user_id }; } ``` ::: warning Do not decode without verifying. `jwt.decode` reads the claims of any string the browser hands you; only `jwt.verify` proves Bito issued it. ::: ::: tip `jti` is unique per token — store the ones you have seen if you want single-use semantics enforced on your side. Bito does not track redemption. ::: See [Widget (iframe app)](https://docs.bito.uz/en/guide/widget.md) for the receiving side end to end. --- # OAuth reference ## Endpoints | Method | Path | Auth | Purpose | |---|---|---|---| | `POST` | `/auth/oauth/auth` | None | [Client credentials grant](https://docs.bito.uz/en/guide/oauth/tokens.md#client-credentials) | | `POST` | `/auth/oauth/token` | None | [Exchange a code](https://docs.bito.uz/en/guide/oauth/tokens.md#exchange) or [refresh](https://docs.bito.uz/en/guide/oauth/tokens.md#refresh) | | `GET` | `/auth/oauth/client` | Bearer (login session) | Client details for the consent screen | | `POST` | `/auth/get-one-time-token` | Bearer (user session) | Mint a [one-time token](https://docs.bito.uz/en/guide/oauth/one-time-tokens.md) | Base URLs: | Environment | Base URL | |---|---| | Production | `https://api.bito.uz/auth-api` | | Dev | `https://api.systematicdev.uz/auth-api` | Rate limit on `/auth/oauth/auth`, `/auth/oauth/token` and `/auth/oauth/client`: **200 requests per minute per IP**. On the Integration API, [`webhook/subscribe` and `webhook/unsubscribe`](https://docs.bito.uz/en/guide/webhooks.md) accept **1 request per second**. ## What Bito sends you | Event | Method | Sent to | Payload | |---|---|---|---| | Install | `POST` | your `redirect_uri` | `{ code, client_id, account_id }` | | Uninstall | `POST` | your `revoke_access_hook_uri` | `{ account_id }` | | Data change | `POST` | each webhook `destination` | `{ collection_name, action, id, organization_id }` | The first two are signed with your `client_secret` (see [Install & uninstall hooks](https://docs.bito.uz/en/guide/lifecycle-hooks.md) for the `X-Bito-Signature` verification); the third is covered in [Data webhooks](https://docs.bito.uz/en/guide/webhooks.md). ## Response envelope Every Bito response — success or failure — uses the same envelope. **Success** ```json { "code": 0, "message": "Success", "messages": { "uz": "...", "ru": "...", "en": "Success" }, "data": {}, "time": "2025-01-15T10:30:00.000Z" } ``` **Error** ```json { "code": 401, "message": "Unauthorized user", "messages": { "uz": "...", "ru": "...", "en": "Unauthorized user" }, "time": "2025-01-15T10:30:00.000Z" } ``` `code` is `0` on success. On failure it carries the error code, and `data` is absent. Branch on `code`, never on the text of `message`, which is localized. ## Common errors | HTTP | Error | What it means | Fix | |---|---|---|---| | 401 | Unauthorized | Missing or malformed `Authorization` header | Send `Bearer ` | | 401 | Token expired | The access token is past its 24 hours | [Refresh](https://docs.bito.uz/en/guide/oauth/tokens.md#refresh) | | 401 | Unauthorized | The session behind the token was terminated | Re-authorize. A [secret rotation](https://docs.bito.uz/en/guide/rotate.md) does exactly this. | | 400 | Invalid credentials | `client_id` and `client_secret` do not match, or the code was already used | Check the secret; request a fresh code | | 400 | Client not found | No client with that `client_id` | Check the id you copied at creation | | 400 | Auth code expired | More than 20 minutes passed | Restart the flow | | 400 | Invalid scope | A requested scope is not a known scope value | Fix the scope value | | 429 | Too many requests | More than 200 auth calls in a minute from one IP | Back off; refresh on expiry, not per request | --- # Custom widgets overview A custom widget is a small front-end app you package as a ZIP and upload to Bito. You can run it privately in your own account, or publish it after both its executable release and marketplace card pass moderation. Bito serves the approved files and loads them into the admin panel, where your code renders inside the product's own screens: a tab on a customer profile, an entry in a phone-number menu, an always-on background widget, or its own settings page. If you have written an amoCRM widget, the shape will be familiar: `script.js` is an AMD module that returns a `CustomWidget` constructor with a `callbacks` object, and it is handed jQuery 4 as `$`. ::: danger A widget runs with the signed-in user's access Your `script.js` is loaded with a plain `