# Write off

Stock write-offs

::: info
Every response arrives in the shared envelope — `code`, `message`, `messages`, `status_code`, `time` — with the payload in `data`. The tables below describe what is inside `data`.
:::

## POST /write-off/create

Create a new write-off (stock loss). The document is immediately persisted in DONE state; stock is decremented and a linked invoice is created inside the same transaction.

**Required permission:** `write_off_create` · [how permissions work](https://docs.bito.uz/en/api/permissions.md)

**Example request**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/write-off/create' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "write_date": "2025-05-01T12:00:00Z",
  "responsible_id": "string",
  "reason_id": "string",
  "action": "remove",
  "products": [
    {
      "product_id": "string",
      "amount": 0,
      "box_count": 0,
      "marks": [],
      "expiration_date": "2025-05-01T12:00:00Z",
      "used_measure": {
        "_id": null,
        "ratio": null,
        "amount": null
      }
    }
  ]
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/write-off/create', {
  method: 'POST',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "write_date": "2025-05-01T12:00:00Z",
    "responsible_id": "string",
    "reason_id": "string",
    "action": "remove",
    "products": [
      {
        "product_id": "string",
        "amount": 0,
        "box_count": 0,
        "marks": [],
        "expiration_date": "2025-05-01T12:00:00Z",
        "used_measure": {
          "_id": null,
          "ratio": null,
          "amount": null
        }
      }
    ]
  }),
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "POST",
    "https://api.bito.uz/integration-api/integration/api/v2/write-off/create",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "write_date": "2025-05-01T12:00:00Z",
        "responsible_id": "string",
        "reason_id": "string",
        "action": "remove",
        "products": [
            {
                "product_id": "string",
                "amount": 0,
                "box_count": 0,
                "marks": [],
                "expiration_date": "2025-05-01T12:00:00Z",
                "used_measure": {
                    "_id": None,
                    "ratio": None,
                    "amount": None,
                },
            },
        ],
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "write_date": "2025-05-01T12:00:00Z",
  "responsible_id": "string",
  "reason_id": "string",
  "action": "remove",
  "products": [
    {
      "product_id": "string",
      "amount": 0,
      "box_count": 0,
      "marks": [],
      "expiration_date": "2025-05-01T12:00:00Z",
      "used_measure": {
        "_id": null,
        "ratio": null,
        "amount": null
      }
    }
  ]
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/write-off/create');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Request body**

| Field | Type | Required | Description |
|---|---|---|---|
| `organization_id` | `string` | No | Organization ObjectId. Required when the tenant has multiple organizations. |
| `code` | `string` | No | Optional external reference code for the write-off |
| `write_date` | `string (date-time)` | Yes | Date the write-off occurred |
| `source_warehouse_id` | `string` | No | Source warehouse ObjectId — the warehouse stock is deducted from |
| `responsible_id` | `string` | Yes | Employee ObjectId responsible for this write-off |
| `reason_id` | `string` | Yes | Reason ObjectId explaining why the stock is being written off |
| `currency_id` | `string` | No | Currency ObjectId used for cost values. Defaults to the organization's base currency. |
| `action` | `string` | Yes | Write-off action type. `remove` — permanent stock removal; `defect` — defective goods moved to a destination warehouse.. One of: `remove`, `defect` |
| `destination_warehouse_id` | `string` | No | Destination warehouse ObjectId. Required when `action` is `defect`. |
| `note` | `string` | No | Optional free-text note |
| `products` | `object[]` | Yes | List of products to write off. At least one item is required. |
| `products[].product_id` | `string` | Yes | Product ObjectId |
| `products[].amount` | `number` | Yes | Quantity to write off (must be positive) |
| `products[].box_count` | `number` | No | Number of boxes (integer; defaults to 0) |
| `products[].marks` | `string[]` | No | Mark/serial codes for marked goods. Each mark must be unique within the request. |
| `products[].expiration_date` | `string (date-time)` | No | Expiration date — required for perishable products that have `has_expiration: true` |
| `products[].used_measure` | `object` | No |  |
| `products[].used_measure._id` | `string` | Yes |  |
| `products[].used_measure.ratio` | `number` | Yes |  |
| `products[].used_measure.amount` | `number` | Yes |  |
| `attachments` | `object[]` | No |  |
| `attachments[].name` | `string` | No |  |
| `attachments[].path` | `string` | Yes |  |
| `attachments[].size` | `number` | No |  |
| `attachments[].note` | `string` | No |  |

```json
{
  "organization_id": "string",
  "code": "string",
  "write_date": "2025-05-01T12:00:00Z",
  "source_warehouse_id": "string",
  "responsible_id": "string",
  "reason_id": "string",
  "currency_id": "string",
  "action": "remove",
  "destination_warehouse_id": "string",
  "note": "string",
  "products": [
    {
      "product_id": "string",
      "amount": 0,
      "box_count": 0,
      "marks": [],
      "expiration_date": "2025-05-01T12:00:00Z",
      "used_measure": {
        "_id": null,
        "ratio": null,
        "amount": null
      }
    }
  ],
  "attachments": [
    {
      "name": "string",
      "path": "string",
      "size": 0,
      "note": "string"
    }
  ]
}
```

**Response**

| Field | Type | Description |
|---|---|---|
| `_id` | `string` |  |
| `number` | `string` | Auto-generated write-off document number |
| `code` | `string` | Optional external reference code |
| `write_date` | `string (date-time)` |  |
| `action` | `string` | One of: `remove`, `defect` |
| `state` | `string` | One of: `done`, `canceled` |
| `note` | `string` |  |
| `total_cost` | `number` |  |
| `organization` | `object` |  |
| `organization._id` | `string` |  |
| `organization.name` | `string` |  |
| `responsible_employee` | `object` |  |
| `responsible_employee._id` | `string` |  |
| `responsible_employee.full_name` | `string` |  |
| `reason` | `object` |  |
| `reason._id` | `string` |  |
| `reason.name` | `string` |  |
| `currency` | `object` |  |
| `currency._id` | `string` |  |
| `currency.name` | `string` |  |
| `source_warehouse` | `object` |  |
| `source_warehouse._id` | `string` |  |
| `source_warehouse.name` | `string` |  |
| `destination_warehouse` | `object` | Populated only when action is `defect` |
| `destination_warehouse._id` | `string` |  |
| `destination_warehouse.name` | `string` |  |
| `products` | `object[]` |  |
| `products[]._id` | `string` |  |
| `products[].product_id` | `string` |  |
| `products[].name` | `string` |  |
| `products[].barcode` | `string` |  |
| `products[].amount` | `number` |  |
| `products[].box_count` | `number` |  |
| `products[].cost` | `number` |  |
| `products[].total_cost` | `number` |  |
| `products[].marks` | `string[]` |  |
| `products[].expiration_date` | `string (date-time)` |  |
| `created_at` | `string (date-time)` |  |
| `updated_at` | `string (date-time)` |  |

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": {
    "_id": "string",
    "number": "string",
    "code": "string",
    "write_date": "2025-05-01T12:00:00Z",
    "action": "remove",
    "state": "done",
    "note": "string",
    "total_cost": 0,
    "organization": {
      "_id": "string",
      "name": "string"
    },
    "responsible_employee": {
      "_id": "string",
      "full_name": "string"
    },
    "reason": {
      "_id": "string",
      "name": "string"
    },
    "currency": {
      "_id": "string",
      "name": "string"
    },
    "source_warehouse": {
      "_id": "string",
      "name": "string"
    },
    "destination_warehouse": {
      "_id": "string",
      "name": "string"
    },
    "products": [
      {
        "_id": "string",
        "product_id": "string",
        "name": "string",
        "barcode": "string",
        "amount": 0,
        "box_count": 0,
        "cost": 0,
        "total_cost": 0,
        "marks": [],
        "expiration_date": "2025-05-01T12:00:00Z"
      }
    ],
    "created_at": "2025-05-01T12:00:00Z",
    "updated_at": "2025-05-01T12:00:00Z"
  },
  "time": "2025-05-01T12:00:00Z"
}
```

## PUT /write-off/set-status/{id}

Transition a write-off to CANCELED state. This is the only valid state transition — it reverses stock, cancels the linked invoice, and posts a CREDIT reconciliation act. Only `status: "canceled"` is accepted; write-offs are created directly in DONE state.

**Required permission:** `write_off` · [how permissions work](https://docs.bito.uz/en/api/permissions.md)

An app that cancels documents should request `write_off_cancel` as well.

**Example request**

::: code-group

```bash [curl]
curl -X PUT 'https://api.bito.uz/integration-api/integration/api/v2/write-off/set-status/6712f0a9c4d1e87b3a0f9911' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "status": "canceled"
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/write-off/set-status/6712f0a9c4d1e87b3a0f9911', {
  method: 'PUT',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "status": "canceled"
  }),
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "PUT",
    "https://api.bito.uz/integration-api/integration/api/v2/write-off/set-status/6712f0a9c4d1e87b3a0f9911",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "status": "canceled",
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "status": "canceled"
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/write-off/set-status/6712f0a9c4d1e87b3a0f9911');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'PUT',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Path parameters**

| Parameter | Type | Required | Description |
|---|---|---|---|
| `id` | `string` | Yes | Write-off ObjectId |

**Request body**

| Field | Type | Required | Description |
|---|---|---|---|
| `status` | `string` | Yes | Target status. Only `canceled` is accepted — write-offs are created directly in DONE state and the only permitted transition is DONE → canceled.. One of: `canceled` |
| `reason` | `string` | No | Optional free-text reason for the cancellation |

```json
{
  "status": "canceled",
  "reason": "string"
}
```

**Response**

Same response shape as [POST /write-off/create](#post-write-off-create).

## GET /write-off/get-by-id/{id}

Fetch a single write-off by ObjectId with full detail (products, organization, responsible employee, reason, currency, warehouses, attachments).

**Required permission:** `write_off` · [how permissions work](https://docs.bito.uz/en/api/permissions.md)

**Example request**

::: code-group

```bash [curl]
curl -X GET 'https://api.bito.uz/integration-api/integration/api/v2/write-off/get-by-id/6712f0a9c4d1e87b3a0f9911' \
  -H "api-key: $BITO_API_KEY"
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/write-off/get-by-id/6712f0a9c4d1e87b3a0f9911', {
  method: 'GET',
  headers: { 'api-key': process.env.BITO_API_KEY },
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "GET",
    "https://api.bito.uz/integration-api/integration/api/v2/write-off/get-by-id/6712f0a9c4d1e87b3a0f9911",
    headers={"api-key": os.environ["BITO_API_KEY"]},
)
print(res.json())
```

```php [PHP]
<?php
$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/write-off/get-by-id/6712f0a9c4d1e87b3a0f9911');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'GET',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY')],
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Path parameters**

| Parameter | Type | Required | Description |
|---|---|---|---|
| `id` | `string` | Yes | Write-off ObjectId |

**Request body**

No request body.

**Response**

Same response shape as [POST /write-off/create](#post-write-off-create).

## POST /write-off/get-paging

Paginated list of write-offs. Filterable by organization, warehouse, responsible employee, action type, and date range.

**Required permission:** `write_off` · [how permissions work](https://docs.bito.uz/en/api/permissions.md)

**Example request**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/write-off/get-paging' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "page": 1,
  "limit": 20
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/write-off/get-paging', {
  method: 'POST',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "page": 1,
    "limit": 20
  }),
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "POST",
    "https://api.bito.uz/integration-api/integration/api/v2/write-off/get-paging",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "page": 1,
        "limit": 20,
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "page": 1,
  "limit": 20
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/write-off/get-paging');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY'), 'Content-Type: application/json'],
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Request body**

| Field | Type | Required | Description |
|---|---|---|---|
| `page` | `number` | Yes | Default: `1` |
| `limit` | `number` | Yes | Default: `20` |
| `organization_id` | `string` | No | Filter by organization ObjectId |
| `warehouse_id` | `string` | No | Filter by source warehouse ObjectId |
| `responsible_id` | `string` | No | Filter by responsible employee ObjectId |
| `action` | `string` | No | Filter by write-off action type. One of: `remove`, `defect` |
| `search` | `string` | No | Free-text search. |
| `updated_at` | `string (date-time)` | No | Only records updated at or after this time. |
| `date_from` | `string (date-time)` | No | Start of the date range. |
| `date_to` | `string (date-time)` | No | End of the date range. |

```json
{
  "page": 1,
  "limit": 20,
  "organization_id": "string",
  "warehouse_id": "string",
  "responsible_id": "string",
  "action": "remove",
  "search": "string",
  "updated_at": "2025-05-01T12:00:00Z",
  "date_from": "2025-05-01T12:00:00Z",
  "date_to": "2025-05-01T12:00:00Z"
}
```

**Response**

| Field | Type | Description |
|---|---|---|
| `total` | `number` |  |
| `list` | `object[]` |  |
| `list[]._id` | `string` |  |
| `list[].number` | `string` |  |
| `list[].code` | `string` |  |
| `list[].write_date` | `string (date-time)` |  |
| `list[].action` | `string` | One of: `remove`, `defect` |
| `list[].state` | `string` | One of: `done`, `canceled` |
| `list[].total_cost` | `number` |  |
| `list[].organization` | `object` |  |
| `list[].organization._id` | `string` |  |
| `list[].organization.name` | `string` |  |
| `list[].responsible_employee` | `object` |  |
| `list[].responsible_employee._id` | `string` |  |
| `list[].responsible_employee.full_name` | `string` |  |
| `list[].reason` | `object` |  |
| `list[].reason._id` | `string` |  |
| `list[].reason.name` | `string` |  |
| `list[].source_warehouse` | `object` |  |
| `list[].source_warehouse._id` | `string` |  |
| `list[].source_warehouse.name` | `string` |  |
| `list[].created_at` | `string (date-time)` |  |

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": {
    "total": 0,
    "list": [
      {
        "_id": "string",
        "number": "string",
        "code": "string",
        "write_date": "2025-05-01T12:00:00Z",
        "action": "remove",
        "state": "done",
        "total_cost": 0,
        "organization": {
          "_id": null,
          "name": null
        },
        "responsible_employee": {
          "_id": null,
          "full_name": null
        },
        "reason": {
          "_id": null,
          "name": null
        },
        "source_warehouse": {
          "_id": null,
          "name": null
        },
        "created_at": "2025-05-01T12:00:00Z"
      }
    ]
  },
  "time": "2025-05-01T12:00:00Z"
}
```

---

*This page is generated from the OpenAPI spec.*
