# Production task

Production tasks assigned to workers

::: info
Каждый ответ приходит в общем конверте — `code`, `message`, `messages`, `status_code`, `time` — а полезная нагрузка лежит в `data`. Таблицы ниже описывают содержимое `data`.
:::

## POST /production-task/create

Create a new production task with tech-map items and warehouse assignments. Returns the hydrated task including items, route-sheet steps, materials, and warehouse quantities.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/production-task/create' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "responsible_id": "string",
  "currency_id": "string",
  "organization_id": "string",
  "produced_warehouse_id": "string",
  "items": [
    {
      "tech_map_id": "string",
      "amount": 0
    }
  ],
  "used_warehouse_items": [
    {
      "used_warehouse_id": "string",
      "step_id": "string"
    }
  ]
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-task/create', {
  method: 'POST',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "responsible_id": "string",
    "currency_id": "string",
    "organization_id": "string",
    "produced_warehouse_id": "string",
    "items": [
      {
        "tech_map_id": "string",
        "amount": 0
      }
    ],
    "used_warehouse_items": [
      {
        "used_warehouse_id": "string",
        "step_id": "string"
      }
    ]
  }),
})
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/production-task/create",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "responsible_id": "string",
        "currency_id": "string",
        "organization_id": "string",
        "produced_warehouse_id": "string",
        "items": [
            {
                "tech_map_id": "string",
                "amount": 0,
            },
        ],
        "used_warehouse_items": [
            {
                "used_warehouse_id": "string",
                "step_id": "string",
            },
        ],
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "responsible_id": "string",
  "currency_id": "string",
  "organization_id": "string",
  "produced_warehouse_id": "string",
  "items": [
    {
      "tech_map_id": "string",
      "amount": 0
    }
  ],
  "used_warehouse_items": [
    {
      "used_warehouse_id": "string",
      "step_id": "string"
    }
  ]
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-task/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);
```

:::

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `responsible_id` | `string` | Да | Employee ObjectId responsible for the task (required) |
| `currency_id` | `string` | Да | Currency ObjectId for cost tracking (required) |
| `organization_id` | `string` | Да | Organization ObjectId the task belongs to (required) |
| `produced_warehouse_id` | `string` | Да | Warehouse ObjectId where finished goods land (required) |
| `items` | `object[]` | Да | Tech-map line items — at least one required |
| `items[].tech_map_id` | `string` | Да | ProductionTechMap ObjectId (recipe/BOM reference) |
| `items[].amount` | `number` | Да | Planned production quantity (positive number) |
| `used_warehouse_items` | `object[]` | Да | Per-step warehouse assignments — at least one required |
| `used_warehouse_items[].used_warehouse_id` | `string` | Да | Warehouse ObjectId materials are consumed from for this step |
| `used_warehouse_items[].step_id` | `string` | Да | ProductionStep ObjectId this warehouse assignment applies to |
| `code` | `string` | Нет | Optional human-readable task code |
| `note` | `string` | Нет | Optional free-text note |
| `date` | `string (date)` | Нет | Optional task date (ISO 8601 YYYY-MM-DD) |
| `attachments` | `object[]` | Нет | Optional pre-uploaded attachment object refs |

```json
{
  "responsible_id": "string",
  "currency_id": "string",
  "organization_id": "string",
  "produced_warehouse_id": "string",
  "items": [
    {
      "tech_map_id": "string",
      "amount": 0
    }
  ],
  "used_warehouse_items": [
    {
      "used_warehouse_id": "string",
      "step_id": "string"
    }
  ],
  "code": "string",
  "note": "string",
  "date": "string",
  "attachments": [
    {}
  ]
}
```

**Ответ**

| Поле | Тип | Описание |
|---|---|---|
| `_id` | `string` | Production task ObjectId |
| `number` | `string` | Auto-generated sequential task number |
| `code` | `string` | Human-readable task code |
| `note` | `string` | Free-text note |
| `date` | `string (date-time)` | Task date |
| `state` | `string` | Current task state. Допустимые значения: `new`, `in_progress`, `done`, `canceled` |
| `organization` | `object` |  |
| `organization._id` | `string` |  |
| `organization.name` | `string` |  |
| `produced_warehouse` | `object` |  |
| `produced_warehouse._id` | `string` |  |
| `produced_warehouse.name` | `string` |  |
| `responsible` | `object` |  |
| `responsible._id` | `string` |  |
| `responsible.full_name` | `string` |  |
| `responsible.number` | `string` |  |
| `used_warehouse_items` | `object[]` |  |
| `used_warehouse_items[].step_id` | `string` |  |
| `used_warehouse_items[].step` | `object` |  |
| `used_warehouse_items[].step._id` | `string` |  |
| `used_warehouse_items[].step.name` | `string` |  |
| `used_warehouse_items[].used_warehouse_id` | `string` |  |
| `used_warehouse_items[].used_warehouse` | `object` |  |
| `used_warehouse_items[].used_warehouse._id` | `string` |  |
| `used_warehouse_items[].used_warehouse.name` | `string` |  |
| `items` | `object[]` | Hydrated tech-map items with route-sheet steps, materials, and warehouse quantities |
| `attachments` | `object[]` |  |
| `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",
    "note": "string",
    "date": "2025-05-01T12:00:00Z",
    "state": "new",
    "organization": {
      "_id": "string",
      "name": "string"
    },
    "produced_warehouse": {
      "_id": "string",
      "name": "string"
    },
    "responsible": {
      "_id": "string",
      "full_name": "string",
      "number": "string"
    },
    "used_warehouse_items": [
      {
        "step_id": "string",
        "step": {
          "_id": null,
          "name": null
        },
        "used_warehouse_id": "string",
        "used_warehouse": {
          "_id": null,
          "name": null
        }
      }
    ],
    "items": [
      {}
    ],
    "attachments": [
      {}
    ],
    "created_at": "2025-05-01T12:00:00Z",
    "updated_at": "2025-05-01T12:00:00Z"
  },
  "time": "2025-05-01T12:00:00Z"
}
```

## GET /production-task/get-by-id/{id}

Fetch a single production task by ObjectId. Returns the same hydrated shape as create/update.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X GET 'https://api.bito.uz/integration-api/integration/api/v2/production-task/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/production-task/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/production-task/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/production-task/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);
```

:::

**Параметры пути**

| Параметр | Тип | Обязательно | Описание |
|---|---|---|---|
| `id` | `string` | Да | Production-task ObjectId |

**Тело запроса**

Тело запроса не требуется.

**Ответ**

Структура ответа совпадает с [POST /production-task/create](#post-production-task-create).

## POST /production-task/get-paging

Paginated list of production tasks, filterable by organization and state.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/production-task/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/production-task/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/production-task/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/production-task/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);
```

:::

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `page` | `number` | Да | По умолчанию: `1` |
| `limit` | `number` | Да | По умолчанию: `20` |
| `organization_id` | `string` | Нет | Filter by organization ObjectId |
| `state` | `string` | Нет | Filter by task state. Допустимые значения: `new`, `in_progress`, `done`, `canceled` |
| `search` | `string` | Нет | Free-text search across number and code fields |
| `sort_by` | `string` | Нет | Field to sort by (e.g. created_at) |
| `asc` | `number` | Нет | Sort direction: 1 ascending, -1 descending. Допустимые значения: `1`, `-1` |
| `updated_at` | `string (date-time)` | Нет | Only records updated at or after this time. |

```json
{
  "page": 1,
  "limit": 20,
  "organization_id": "string",
  "state": "new",
  "search": "string",
  "sort_by": "string",
  "asc": 1,
  "updated_at": "2025-05-01T12:00:00Z"
}
```

**Ответ**

| Поле | Тип | Описание |
|---|---|---|
| `total` | `number` |  |
| `list` | `object[]` |  |
| `list[]._id` | `string` | Production task ObjectId |
| `list[].number` | `string` | Auto-generated sequential task number |
| `list[].code` | `string` | Human-readable task code |
| `list[].note` | `string` | Free-text note |
| `list[].date` | `string (date-time)` | Task date |
| `list[].state` | `string` | Current task state. Допустимые значения: `new`, `in_progress`, `done`, `canceled` |
| `list[].organization` | `object` |  |
| `list[].organization._id` | `string` |  |
| `list[].organization.name` | `string` |  |
| `list[].produced_warehouse` | `object` |  |
| `list[].produced_warehouse._id` | `string` |  |
| `list[].produced_warehouse.name` | `string` |  |
| `list[].responsible` | `object` |  |
| `list[].responsible._id` | `string` |  |
| `list[].responsible.full_name` | `string` |  |
| `list[].responsible.number` | `string` |  |
| `list[].created_at` | `string (date-time)` |  |
| `list[].updated_at` | `string (date-time)` |  |

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": {
    "total": 0,
    "list": [
      {
        "_id": "string",
        "number": "string",
        "code": "string",
        "note": "string",
        "date": "2025-05-01T12:00:00Z",
        "state": "new",
        "organization": {
          "_id": null,
          "name": null
        },
        "produced_warehouse": {
          "_id": null,
          "name": null
        },
        "responsible": {
          "_id": null,
          "full_name": null,
          "number": null
        },
        "created_at": "2025-05-01T12:00:00Z",
        "updated_at": "2025-05-01T12:00:00Z"
      }
    ]
  },
  "time": "2025-05-01T12:00:00Z"
}
```

## PUT /production-task/update/{id}

Update an existing production task. Only allowed while the task is in state `new`. Replaces items and warehouse assignments; re-runs tech-map hydration. Returns the updated hydrated task.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X PUT 'https://api.bito.uz/integration-api/integration/api/v2/production-task/update/6712f0a9c4d1e87b3a0f9911' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "responsible_id": "string",
  "currency_id": "string",
  "organization_id": "string",
  "produced_warehouse_id": "string",
  "items": [
    {
      "tech_map_id": "string",
      "amount": 0
    }
  ],
  "used_warehouse_items": [
    {
      "used_warehouse_id": "string",
      "step_id": "string"
    }
  ]
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-task/update/6712f0a9c4d1e87b3a0f9911', {
  method: 'PUT',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "responsible_id": "string",
    "currency_id": "string",
    "organization_id": "string",
    "produced_warehouse_id": "string",
    "items": [
      {
        "tech_map_id": "string",
        "amount": 0
      }
    ],
    "used_warehouse_items": [
      {
        "used_warehouse_id": "string",
        "step_id": "string"
      }
    ]
  }),
})
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/production-task/update/6712f0a9c4d1e87b3a0f9911",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "responsible_id": "string",
        "currency_id": "string",
        "organization_id": "string",
        "produced_warehouse_id": "string",
        "items": [
            {
                "tech_map_id": "string",
                "amount": 0,
            },
        ],
        "used_warehouse_items": [
            {
                "used_warehouse_id": "string",
                "step_id": "string",
            },
        ],
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "responsible_id": "string",
  "currency_id": "string",
  "organization_id": "string",
  "produced_warehouse_id": "string",
  "items": [
    {
      "tech_map_id": "string",
      "amount": 0
    }
  ],
  "used_warehouse_items": [
    {
      "used_warehouse_id": "string",
      "step_id": "string"
    }
  ]
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-task/update/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);
```

:::

**Параметры пути**

| Параметр | Тип | Обязательно | Описание |
|---|---|---|---|
| `id` | `string` | Да | Production-task ObjectId to update |

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `responsible_id` | `string` | Да | Employee ObjectId responsible for the task (required) |
| `currency_id` | `string` | Да | Currency ObjectId for cost tracking (required) |
| `organization_id` | `string` | Да | Organization ObjectId the task belongs to (required) |
| `produced_warehouse_id` | `string` | Да | Warehouse ObjectId where finished goods land (required) |
| `items` | `object[]` | Да | Tech-map line items — at least one required |
| `items[].tech_map_id` | `string` | Да | ProductionTechMap ObjectId (recipe/BOM reference) |
| `items[].amount` | `number` | Да | Planned production quantity (positive number) |
| `used_warehouse_items` | `object[]` | Да | Per-step warehouse assignments — at least one required |
| `used_warehouse_items[].used_warehouse_id` | `string` | Да | Warehouse ObjectId materials are consumed from for this step |
| `used_warehouse_items[].step_id` | `string` | Да | ProductionStep ObjectId this warehouse assignment applies to |
| `code` | `string` | Нет | Optional human-readable task code |
| `note` | `string` | Нет | Optional free-text note |
| `date` | `string (date)` | Нет | Optional task date (ISO 8601 YYYY-MM-DD) |
| `attachments` | `object[]` | Нет | Optional pre-uploaded attachment object refs |

```json
{
  "responsible_id": "string",
  "currency_id": "string",
  "organization_id": "string",
  "produced_warehouse_id": "string",
  "items": [
    {
      "tech_map_id": "string",
      "amount": 0
    }
  ],
  "used_warehouse_items": [
    {
      "used_warehouse_id": "string",
      "step_id": "string"
    }
  ],
  "code": "string",
  "note": "string",
  "date": "string",
  "attachments": [
    {}
  ]
}
```

**Ответ**

Структура ответа совпадает с [POST /production-task/create](#post-production-task-create).

## PUT /production-task/set-status/{id}

Transition a production task to a new state. Valid transitions: new→[in_progress, canceled, done]; in_progress→[canceled, done]; done→[canceled]; canceled→[]. Transitioning to `canceled` cascades cancellation of all linked production operations. NOTE: the `reason` field is accepted by the contract but is NOT persisted (the model has no reason field).

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

Приложению, которое отменяет документ, стоит запросить и `production_task_cancel`.

**Пример запроса**

::: code-group

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

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-task/set-status/6712f0a9c4d1e87b3a0f9911', {
  method: 'PUT',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "status": "new"
  }),
})
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/production-task/set-status/6712f0a9c4d1e87b3a0f9911",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "status": "new",
    },
)
print(res.json())
```

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

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-task/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);
```

:::

**Параметры пути**

| Параметр | Тип | Обязательно | Описание |
|---|---|---|---|
| `id` | `string` | Да | Production-task ObjectId |

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `status` | `string` | Да | Target state for the production task (required). Valid transitions: new→[in_progress, canceled, done]; in_progress→[canceled, done]; done→[canceled]; canceled→[].. Допустимые значения: `new`, `in_progress`, `done`, `canceled` |

```json
{
  "status": "new"
}
```

**Ответ**

Структура ответа совпадает с [POST /production-task/create](#post-production-task-create).

## PUT /production-task/produce/{id}

Record production output against one step of the task's technological map. This is the write that actually moves material: the step's inputs are consumed from the used warehouse, `amount` of its output is produced into the produced warehouse, and the task advances. Reverse it with cancel-produced.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X PUT 'https://api.bito.uz/integration-api/integration/api/v2/production-task/produce/6712f0a9c4d1e87b3a0f9911' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "tech_map_id": "string",
  "step_id": "string",
  "responsible_id": "string",
  "amount": 0,
  "used_date": "2025-05-01T12:00:00Z",
  "produced_date": "2025-05-01T12:00:00Z",
  "items": [
    {
      "product_id": "64b7f4d9e2b3b6a0b7c5d7ff",
      "amount": 0,
      "type": "used",
      "cost_percentage": 0,
      "extra_costs": [],
      "expiration_date": "2025-05-01T12:00:00Z",
      "marks": [],
      "alternatives": [],
      "used_measure": {
        "_id": null,
        "ratio": null,
        "amount": null
      },
      "consumption_type": "variable"
    }
  ]
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-task/produce/6712f0a9c4d1e87b3a0f9911', {
  method: 'PUT',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "tech_map_id": "string",
    "step_id": "string",
    "responsible_id": "string",
    "amount": 0,
    "used_date": "2025-05-01T12:00:00Z",
    "produced_date": "2025-05-01T12:00:00Z",
    "items": [
      {
        "product_id": "64b7f4d9e2b3b6a0b7c5d7ff",
        "amount": 0,
        "type": "used",
        "cost_percentage": 0,
        "extra_costs": [],
        "expiration_date": "2025-05-01T12:00:00Z",
        "marks": [],
        "alternatives": [],
        "used_measure": {
          "_id": null,
          "ratio": null,
          "amount": null
        },
        "consumption_type": "variable"
      }
    ]
  }),
})
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/production-task/produce/6712f0a9c4d1e87b3a0f9911",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "tech_map_id": "string",
        "step_id": "string",
        "responsible_id": "string",
        "amount": 0,
        "used_date": "2025-05-01T12:00:00Z",
        "produced_date": "2025-05-01T12:00:00Z",
        "items": [
            {
                "product_id": "64b7f4d9e2b3b6a0b7c5d7ff",
                "amount": 0,
                "type": "used",
                "cost_percentage": 0,
                "extra_costs": [],
                "expiration_date": "2025-05-01T12:00:00Z",
                "marks": [],
                "alternatives": [],
                "used_measure": {
                    "_id": None,
                    "ratio": None,
                    "amount": None,
                },
                "consumption_type": "variable",
            },
        ],
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "tech_map_id": "string",
  "step_id": "string",
  "responsible_id": "string",
  "amount": 0,
  "used_date": "2025-05-01T12:00:00Z",
  "produced_date": "2025-05-01T12:00:00Z",
  "items": [
    {
      "product_id": "64b7f4d9e2b3b6a0b7c5d7ff",
      "amount": 0,
      "type": "used",
      "cost_percentage": 0,
      "extra_costs": [],
      "expiration_date": "2025-05-01T12:00:00Z",
      "marks": [],
      "alternatives": [],
      "used_measure": {
        "_id": null,
        "ratio": null,
        "amount": null
      },
      "consumption_type": "variable"
    }
  ]
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-task/produce/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);
```

:::

**Параметры пути**

| Параметр | Тип | Обязательно | Описание |
|---|---|---|---|
| `id` | `string` | Да | Production-task ObjectId |

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `tech_map_id` | `string` | Да | Technological-map ObjectId the step belongs to |
| `step_id` | `string` | Да | Production-step ObjectId being produced |
| `responsible_id` | `string` | Да | Employee ObjectId credited with the output |
| `amount` | `number` | Да | Quantity produced in this call |
| `used_date` | `string (date-time)` | Да | When the inputs were consumed (ISO 8601) |
| `produced_date` | `string (date-time)` | Да | When the output was produced (ISO 8601) |
| `code` | `string` | Нет | Optional external code for the resulting operation |
| `state` | `string` | Нет | Optional initial state for the resulting production operation |
| `note` | `string` | Нет | Optional free-text note |
| `create_reminder` | `boolean` | Нет | Create a follow-up reminder for the responsible employee |
| `additional_costs` | `object[]` | Нет | Extra costs to fold into the produced item's cost price |
| `additional_costs[].cost_id` | `string` | Да | Extra-cost ObjectId |
| `additional_costs[].amount` | `number` | Да | Cost amount |
| `additional_costs[].consumption_type` | `string` | Нет | Допустимые значения: `variable`, `fixed` |
| `additional_costs[].customer_id` | `string` | Нет |  |
| `additional_costs[].employee_id` | `string` | Нет |  |
| `additional_costs[].supplier_id` | `string` | Нет |  |
| `additional_costs[].person_id` | `string` | Нет |  |
| `items` | `object[]` | Да |  |
| `items[].product_id` | `string` | Да |  |
| `items[].amount` | `number` | Нет |  |
| `items[].type` | `string` | Да | Допустимые значения: `used`, `produced` |
| `items[].cost_percentage` | `number` | Нет |  |
| `items[].extra_costs` | `object[]` | Нет |  |
| `items[].extra_costs[].cost_id` | `string` | Да |  |
| `items[].extra_costs[].amount` | `number` | Да |  |
| `items[].extra_costs[].index` | `number` | Нет |  |
| `items[].expiration_date` | `string (date-time)` | Нет |  |
| `items[].marks` | `string[]` | Нет |  |
| `items[].alternatives` | `object[]` | Нет |  |
| `items[].alternatives[].product_id` | `string` | Да |  |
| `items[].alternatives[].amount` | `number` | Да |  |
| `items[].alternatives[].expiration_date` | `string (date-time)` | Нет |  |
| `items[].alternatives[].used_measure` | `object` | Нет |  |
| `items[].used_measure` | `object` | Нет |  |
| `items[].used_measure._id` | `string` | Да |  |
| `items[].used_measure.ratio` | `number` | Да |  |
| `items[].used_measure.amount` | `number` | Да |  |
| `items[].consumption_type` | `string` | Нет | Допустимые значения: `variable`, `fixed` |

```json
{
  "tech_map_id": "string",
  "step_id": "string",
  "responsible_id": "string",
  "amount": 0,
  "used_date": "2025-05-01T12:00:00Z",
  "produced_date": "2025-05-01T12:00:00Z",
  "code": "string",
  "state": "string",
  "note": "string",
  "create_reminder": false,
  "additional_costs": [
    {
      "cost_id": "string",
      "amount": 0,
      "consumption_type": "variable",
      "customer_id": "64b7f4d9e2b3b6a0b7c5d7ff",
      "employee_id": "64b7f4d9e2b3b6a0b7c5d7ff",
      "supplier_id": "64b7f4d9e2b3b6a0b7c5d7ff",
      "person_id": "64b7f4d9e2b3b6a0b7c5d7ff"
    }
  ],
  "items": [
    {
      "product_id": "64b7f4d9e2b3b6a0b7c5d7ff",
      "amount": 0,
      "type": "used",
      "cost_percentage": 0,
      "extra_costs": [],
      "expiration_date": "2025-05-01T12:00:00Z",
      "marks": [],
      "alternatives": [],
      "used_measure": {
        "_id": null,
        "ratio": null,
        "amount": null
      },
      "consumption_type": "variable"
    }
  ]
}
```

**Ответ**

Структура ответа совпадает с [POST /production-task/create](#post-production-task-create).

## PUT /production-task/cancel-produced/{id}

Reverse a previously recorded production for one step of the task. Cancels the operation the matching produce call created and returns the consumed material to stock. `tech_map_id` + `step_id` identify which produced step to undo.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

Приложению, которое отменяет документ, стоит запросить и `production_task_cancel`.

**Пример запроса**

::: code-group

```bash [curl]
curl -X PUT 'https://api.bito.uz/integration-api/integration/api/v2/production-task/cancel-produced/6712f0a9c4d1e87b3a0f9911' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "tech_map_id": "string",
  "step_id": "string"
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/production-task/cancel-produced/6712f0a9c4d1e87b3a0f9911', {
  method: 'PUT',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "tech_map_id": "string",
    "step_id": "string"
  }),
})
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/production-task/cancel-produced/6712f0a9c4d1e87b3a0f9911",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "tech_map_id": "string",
        "step_id": "string",
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "tech_map_id": "string",
  "step_id": "string"
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/production-task/cancel-produced/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);
```

:::

**Параметры пути**

| Параметр | Тип | Обязательно | Описание |
|---|---|---|---|
| `id` | `string` | Да | Production-task ObjectId |

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `tech_map_id` | `string` | Да | Technological-map ObjectId the produced step belongs to |
| `step_id` | `string` | Да | Production-step ObjectId whose production is being reversed |

```json
{
  "tech_map_id": "string",
  "step_id": "string"
}
```

**Ответ**

Структура ответа совпадает с [POST /production-task/create](#post-production-task-create).

## POST /production-task/state-report/by-product

Paginated production-task state report grouped by product. Answers how much of each product is planned, in progress, done or canceled across tasks — rather than listing the tasks themselves. Accepts the same filters as get-paging.

**Нужное разрешение:** `production` · [как работают разрешения](https://docs.bito.uz/ru/api/permissions.md)

**Пример запроса**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/production-task/state-report/by-product' \
  -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/production-task/state-report/by-product', {
  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/production-task/state-report/by-product",
    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/production-task/state-report/by-product');
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);
```

:::

**Тело запроса**

| Поле | Тип | Обязательно | Описание |
|---|---|---|---|
| `page` | `number` | Да | По умолчанию: `1` |
| `limit` | `number` | Да | По умолчанию: `20` |
| `organization_id` | `string` | Нет | Filter by organization ObjectId |
| `state` | `string` | Нет | Filter by task state. Допустимые значения: `new`, `in_progress`, `done`, `canceled` |
| `search` | `string` | Нет | Free-text search across number and code fields |
| `sort_by` | `string` | Нет | Field to sort by (e.g. created_at) |
| `asc` | `number` | Нет | Sort direction: 1 ascending, -1 descending. Допустимые значения: `1`, `-1` |

```json
{
  "page": 1,
  "limit": 20,
  "organization_id": "string",
  "state": "new",
  "search": "string",
  "sort_by": "string",
  "asc": 1
}
```

**Ответ**

| Поле | Тип | Описание |
|---|---|---|
| `total` | `number` |  |
| `list` | `object[]` |  |
| `list[].product_id` | `string` | Product ObjectId |
| `list[].product` | `object` | Hydrated product |
| `list[].product._id` | `string` |  |
| `list[].product.name` | `string` |  |
| `list[].new` | `number` | Quantity on tasks still in the new state |
| `list[].in_progress` | `number` | Quantity on tasks in progress |
| `list[].done` | `number` | Quantity on completed tasks |
| `list[].canceled` | `number` | Quantity on canceled tasks |
| `list[].total` | `number` | Total planned quantity across all states |

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": {
    "total": 0,
    "list": [
      {
        "product_id": "string",
        "product": {
          "_id": null,
          "name": null
        },
        "new": 0,
        "in_progress": 0,
        "done": 0,
        "canceled": 0,
        "total": 0
      }
    ]
  },
  "time": "2025-05-01T12:00:00Z"
}
```

---

*Эта страница сгенерирована из спецификации OpenAPI.*
