# Kpi settings

Employee KPI configuration

::: info
Har bir javob umumiy konvertda qaytadi — `code`, `message`, `messages`, `status_code`, `time` — foydali yuk esa `data` ichida. Quyidagi jadvallar faqat `data` ichini tavsiflaydi.
:::

## POST /kpi-settings/create

Create a new KPI settings record for a given period and set of employees.

**Kerakli ruxsat:** `kpi_settings_create` · [ruxsatlar qanday ishlaydi](https://docs.bito.uz/api/permissions.md)

**So‘rov namunasi**

::: code-group

```bash [curl]
curl -X POST 'https://api.bito.uz/integration-api/integration/api/v2/kpi-settings/create' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "organization_id": "string",
  "user_ids": [
    "string"
  ],
  "period": "week",
  "calculation_method": "progressive",
  "date_from": "2025-05-01T12:00:00Z",
  "conditions": [
    {
      "logical_operator": false,
      "source_metric_code": "net_sales",
      "tiers": []
    }
  ],
  "bonus_metric_code": "percent_of_net_sales",
  "bonuses": [
    0
  ],
  "filter_enabled": false,
  "state": "draft"
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/kpi-settings/create', {
  method: 'POST',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "organization_id": "string",
    "user_ids": [
      "string"
    ],
    "period": "week",
    "calculation_method": "progressive",
    "date_from": "2025-05-01T12:00:00Z",
    "conditions": [
      {
        "logical_operator": false,
        "source_metric_code": "net_sales",
        "tiers": []
      }
    ],
    "bonus_metric_code": "percent_of_net_sales",
    "bonuses": [
      0
    ],
    "filter_enabled": false,
    "state": "draft"
  }),
})
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/kpi-settings/create",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "organization_id": "string",
        "user_ids": [
            "string",
        ],
        "period": "week",
        "calculation_method": "progressive",
        "date_from": "2025-05-01T12:00:00Z",
        "conditions": [
            {
                "logical_operator": False,
                "source_metric_code": "net_sales",
                "tiers": [],
            },
        ],
        "bonus_metric_code": "percent_of_net_sales",
        "bonuses": [
            0,
        ],
        "filter_enabled": False,
        "state": "draft",
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "organization_id": "string",
  "user_ids": [
    "string"
  ],
  "period": "week",
  "calculation_method": "progressive",
  "date_from": "2025-05-01T12:00:00Z",
  "conditions": [
    {
      "logical_operator": false,
      "source_metric_code": "net_sales",
      "tiers": []
    }
  ],
  "bonus_metric_code": "percent_of_net_sales",
  "bonuses": [
    0
  ],
  "filter_enabled": false,
  "state": "draft"
}
JSON;

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

:::

**So‘rov tanasi**

| Maydon | Tur | Majburiy | Tavsif |
|---|---|---|---|
| `organization_id` | `string` | Ha | Organization ObjectId this KPI setting belongs to |
| `name` | `string` | Yo‘q | Optional display name for the KPI setting |
| `user_ids` | `string[]` | Ha | ObjectIds of the employees this KPI setting applies to |
| `period` | `string` | Ha | KPI evaluation period. Mumkin qiymatlar: `week`, `month`, `quarter`, `year` |
| `calculation_method` | `string` | Ha | How the bonus is calculated across tiers: progressive (each tier adds to the previous) or threshold (only the matched tier applies). Mumkin qiymatlar: `progressive`, `threshold` |
| `date_from` | `string (date-time)` | Ha | Start date of the KPI period |
| `filter_enabled` | `boolean` | Ha | Whether product/customer filters are active for this KPI setting. Standart: `false` |
| `filter` | `object` | Yo‘q | Optional product and customer scope filters |
| `filter.is_all_categories` | `boolean` | Yo‘q |  |
| `filter.customer_category_ids` | `string[]` | Yo‘q | Customer category ObjectIds to include |
| `filter.customer_ids` | `string[]` | Yo‘q | Specific customer ObjectIds to include |
| `filter.product_category_ids` | `string[]` | Yo‘q |  |
| `filter.product_ids` | `string[]` | Yo‘q | Specific product ObjectIds to include |
| `conditions` | `object[]` | Ha | One or more KPI plan conditions defining the performance metric and tier thresholds |
| `conditions[].logical_operator` | `boolean` | Ha | true = AND with the next condition, false = OR |
| `conditions[].source_metric_code` | `string` | Ha | The performance metric used to evaluate this condition. Mumkin qiymatlar: `net_sales`, `sales_count`, `avg_net_sales`, `profit`, `paid`, `paid_percent`, `items_sold` |
| `conditions[].tiers` | `object[]` | Ha | Threshold tiers for this condition |
| `conditions[].tiers[].min_value` | `number` | Ha | Minimum metric value for this tier to activate |
| `conditions[].tiers[].max_value` | `number` | Yo‘q | Maximum metric value for this tier (omit for the top tier) |
| `bonus_metric_code` | `string` | Ha | How the bonus amount is computed from the employee's results. Mumkin qiymatlar: `percent_of_net_sales`, `percent_of_payment`, `percent_of_profit`, `per_sale`, `fixed_amount`, `per_item_sold` |
| `bonuses` | `number[]` | Ha | Bonus amounts or percentages, one entry per tier in the conditions |
| `responsible_id` | `string` | Yo‘q |  |
| `state` | `string` | Ha | Mumkin qiymatlar: `draft`, `active` |
| `attachments` | `object[]` | Yo‘q |  |
| `attachments[].name` | `string` | Yo‘q |  |
| `attachments[].path` | `string` | Ha |  |
| `attachments[].size` | `number` | Yo‘q |  |
| `attachments[].note` | `string` | Yo‘q |  |

```json
{
  "organization_id": "string",
  "name": "string",
  "user_ids": [
    "string"
  ],
  "period": "week",
  "calculation_method": "progressive",
  "date_from": "2025-05-01T12:00:00Z",
  "filter_enabled": false,
  "filter": {
    "is_all_categories": false,
    "customer_category_ids": [
      "string"
    ],
    "customer_ids": [
      "string"
    ],
    "product_category_ids": [
      "string"
    ],
    "product_ids": [
      "string"
    ]
  },
  "conditions": [
    {
      "logical_operator": false,
      "source_metric_code": "net_sales",
      "tiers": []
    }
  ],
  "bonus_metric_code": "percent_of_net_sales",
  "bonuses": [
    0
  ],
  "responsible_id": "64b7f4d9e2b3b6a0b7c5d7ff",
  "state": "draft",
  "attachments": [
    {
      "name": "string",
      "path": "string",
      "size": 0,
      "note": "string"
    }
  ]
}
```

**Javob**

| Maydon | Tur | Tavsif |
|---|---|---|
| `_id` | `string` | KPI settings ObjectId |
| `organization_id` | `string` |  |
| `name` | `string` |  |
| `currency_id` | `string` |  |
| `user_ids` | `string[]` |  |
| `period` | `string` | Mumkin qiymatlar: `week`, `month`, `quarter`, `year` |
| `calculation_method` | `string` | Mumkin qiymatlar: `progressive`, `threshold` |
| `state` | `string` | Mumkin qiymatlar: `draft`, `active`, `locked`, `approved`, `canceled` |
| `date_from` | `string (date-time)` |  |
| `date_to` | `string (date-time)` |  |
| `year` | `number` |  |
| `quarter` | `string` |  |
| `month` | `string` |  |
| `week` | `string` |  |
| `filter_enabled` | `boolean` |  |
| `filter` | `object` |  |
| `filter.is_all_categories` | `boolean` |  |
| `filter.customer_category_ids` | `string[]` |  |
| `filter.customer_nested_category_ids` | `string[]` |  |
| `filter.customer_ids` | `string[]` |  |
| `filter.product_category_ids` | `string[]` |  |
| `filter.product_nested_category_ids` | `string[]` |  |
| `filter.product_ids` | `string[]` |  |
| `conditions` | `object[]` |  |
| `conditions[].logical_operator` | `boolean` |  |
| `conditions[].source_metric_code` | `string` | Mumkin qiymatlar: `net_sales`, `sales_count`, `avg_net_sales`, `profit`, `paid`, `paid_percent`, `items_sold` |
| `conditions[].tiers` | `object[]` |  |
| `conditions[].tiers[].min_value` | `number` |  |
| `conditions[].tiers[].max_value` | `number` |  |
| `bonus_metric_code` | `string` | Mumkin qiymatlar: `percent_of_net_sales`, `percent_of_payment`, `percent_of_profit`, `per_sale`, `fixed_amount`, `per_item_sold` |
| `bonuses` | `number[]` |  |
| `created_at` | `string (date-time)` |  |
| `updated_at` | `string (date-time)` |  |
| `is_deleted` | `boolean` |  |

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": {
    "_id": "string",
    "organization_id": "string",
    "name": "string",
    "currency_id": "string",
    "user_ids": [
      "string"
    ],
    "period": "week",
    "calculation_method": "progressive",
    "state": "draft",
    "date_from": "2025-05-01T12:00:00Z",
    "date_to": "2025-05-01T12:00:00Z",
    "year": 0,
    "quarter": "string",
    "month": "string",
    "week": "string",
    "filter_enabled": false,
    "filter": {
      "is_all_categories": false,
      "customer_category_ids": [
        "string"
      ],
      "customer_nested_category_ids": [
        "string"
      ],
      "customer_ids": [
        "string"
      ],
      "product_category_ids": [
        "string"
      ],
      "product_nested_category_ids": [
        "string"
      ],
      "product_ids": [
        "string"
      ]
    },
    "conditions": [
      {
        "logical_operator": false,
        "source_metric_code": "net_sales",
        "tiers": []
      }
    ],
    "bonus_metric_code": "percent_of_net_sales",
    "bonuses": [
      0
    ],
    "created_at": "2025-05-01T12:00:00Z",
    "updated_at": "2025-05-01T12:00:00Z",
    "is_deleted": false
  },
  "time": "2025-05-01T12:00:00Z"
}
```

## GET /kpi-settings/get-by-id/{id}

Fetch a single KPI settings record by ObjectId.

**Kerakli ruxsat:** `kpi_settings` · [ruxsatlar qanday ishlaydi](https://docs.bito.uz/api/permissions.md)

**So‘rov namunasi**

::: code-group

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

:::

**Yo‘l parametrlari**

| Parametr | Tur | Majburiy | Tavsif |
|---|---|---|---|
| `id` | `string` | Ha | KPI settings ObjectId |

**So‘rov tanasi**

So‘rov tanasi talab qilinmaydi.

**Javob**

Javob tuzilishi quyidagi bilan bir xil: [POST /kpi-settings/create](#post-kpi-settings-create).

## POST /kpi-settings/get-paging

Paginated list of KPI settings records, optionally filtered by organization or period.

**Kerakli ruxsat:** `kpi_settings` · [ruxsatlar qanday ishlaydi](https://docs.bito.uz/api/permissions.md)

**So‘rov namunasi**

::: code-group

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

:::

**So‘rov tanasi**

| Maydon | Tur | Majburiy | Tavsif |
|---|---|---|---|
| `page` | `number` | Ha | Standart: `1` |
| `limit` | `number` | Ha | Standart: `20` |
| `organization_id` | `string` | Yo‘q | Filter by organization ObjectId |
| `period` | `string` | Yo‘q | Filter by KPI period. Mumkin qiymatlar: `week`, `month`, `quarter`, `year` |
| `state` | `string` | Yo‘q | Filter by KPI settings state. Mumkin qiymatlar: `draft`, `active`, `locked`, `approved`, `canceled` |
| `bonus_metric_code` | `string` | Yo‘q | Mumkin qiymatlar: `percent_of_net_sales`, `percent_of_payment`, `percent_of_profit`, `per_sale`, `fixed_amount`, `per_item_sold`, `per_item_produced` |
| `search` | `string` | Yo‘q | Free-text search. |
| `updated_at` | `string (date-time)` | Yo‘q | Only records updated at or after this time. |
| `date_from` | `string (date-time)` | Yo‘q | Start of the date range. |
| `date_to` | `string (date-time)` | Yo‘q | End of the date range. |

```json
{
  "page": 1,
  "limit": 20,
  "organization_id": "string",
  "period": "week",
  "state": "draft",
  "bonus_metric_code": "percent_of_net_sales",
  "search": "string",
  "updated_at": "2025-05-01T12:00:00Z",
  "date_from": "2025-05-01T12:00:00Z",
  "date_to": "2025-05-01T12:00:00Z"
}
```

**Javob**

| Maydon | Tur | Tavsif |
|---|---|---|
| `total` | `number` |  |
| `list` | `object[]` |  |
| `list[]._id` | `string` | KPI settings ObjectId |
| `list[].organization_id` | `string` |  |
| `list[].name` | `string` |  |
| `list[].currency_id` | `string` |  |
| `list[].user_ids` | `string[]` |  |
| `list[].period` | `string` | Mumkin qiymatlar: `week`, `month`, `quarter`, `year` |
| `list[].calculation_method` | `string` | Mumkin qiymatlar: `progressive`, `threshold` |
| `list[].state` | `string` | Mumkin qiymatlar: `draft`, `active`, `locked`, `approved`, `canceled` |
| `list[].date_from` | `string (date-time)` |  |
| `list[].date_to` | `string (date-time)` |  |
| `list[].year` | `number` |  |
| `list[].quarter` | `string` |  |
| `list[].month` | `string` |  |
| `list[].week` | `string` |  |
| `list[].filter_enabled` | `boolean` |  |
| `list[].filter` | `object` |  |
| `list[].filter.is_all_categories` | `boolean` |  |
| `list[].filter.customer_category_ids` | `string[]` |  |
| `list[].filter.customer_nested_category_ids` | `string[]` |  |
| `list[].filter.customer_ids` | `string[]` |  |
| `list[].filter.product_category_ids` | `string[]` |  |
| `list[].filter.product_nested_category_ids` | `string[]` |  |
| `list[].filter.product_ids` | `string[]` |  |
| `list[].conditions` | `object[]` |  |
| `list[].conditions[].logical_operator` | `boolean` |  |
| `list[].conditions[].source_metric_code` | `string` | Mumkin qiymatlar: `net_sales`, `sales_count`, `avg_net_sales`, `profit`, `paid`, `paid_percent`, `items_sold` |
| `list[].conditions[].tiers` | `object[]` |  |
| `list[].bonus_metric_code` | `string` | Mumkin qiymatlar: `percent_of_net_sales`, `percent_of_payment`, `percent_of_profit`, `per_sale`, `fixed_amount`, `per_item_sold` |
| `list[].bonuses` | `number[]` |  |
| `list[].created_at` | `string (date-time)` |  |
| `list[].updated_at` | `string (date-time)` |  |
| `list[].is_deleted` | `boolean` |  |

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": {
    "total": 0,
    "list": [
      {
        "_id": "string",
        "organization_id": "string",
        "name": "string",
        "currency_id": "string",
        "user_ids": [],
        "period": "week",
        "calculation_method": "progressive",
        "state": "draft",
        "date_from": "2025-05-01T12:00:00Z",
        "date_to": "2025-05-01T12:00:00Z",
        "year": 0,
        "quarter": "string",
        "month": "string",
        "week": "string",
        "filter_enabled": false,
        "filter": {
          "is_all_categories": null,
          "customer_category_ids": null,
          "customer_nested_category_ids": null,
          "customer_ids": null,
          "product_category_ids": null,
          "product_nested_category_ids": null,
          "product_ids": null
        },
        "conditions": [],
        "bonus_metric_code": "percent_of_net_sales",
        "bonuses": [],
        "created_at": "2025-05-01T12:00:00Z",
        "updated_at": "2025-05-01T12:00:00Z",
        "is_deleted": false
      }
    ]
  },
  "time": "2025-05-01T12:00:00Z"
}
```

## PUT /kpi-settings/update/{id}

Update an existing KPI settings record.

**Kerakli ruxsat:** `kpi_settings_update` · [ruxsatlar qanday ishlaydi](https://docs.bito.uz/api/permissions.md)

**So‘rov namunasi**

::: code-group

```bash [curl]
curl -X PUT 'https://api.bito.uz/integration-api/integration/api/v2/kpi-settings/update/6712f0a9c4d1e87b3a0f9911' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "organization_id": "string",
  "user_ids": [
    "string"
  ],
  "period": "week",
  "calculation_method": "progressive",
  "date_from": "2025-05-01T12:00:00Z",
  "conditions": [
    {
      "logical_operator": false,
      "source_metric_code": "net_sales",
      "tiers": []
    }
  ],
  "bonus_metric_code": "percent_of_net_sales",
  "bonuses": [
    0
  ],
  "filter_enabled": false,
  "state": "draft"
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/kpi-settings/update/6712f0a9c4d1e87b3a0f9911', {
  method: 'PUT',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "organization_id": "string",
    "user_ids": [
      "string"
    ],
    "period": "week",
    "calculation_method": "progressive",
    "date_from": "2025-05-01T12:00:00Z",
    "conditions": [
      {
        "logical_operator": false,
        "source_metric_code": "net_sales",
        "tiers": []
      }
    ],
    "bonus_metric_code": "percent_of_net_sales",
    "bonuses": [
      0
    ],
    "filter_enabled": false,
    "state": "draft"
  }),
})
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/kpi-settings/update/6712f0a9c4d1e87b3a0f9911",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "organization_id": "string",
        "user_ids": [
            "string",
        ],
        "period": "week",
        "calculation_method": "progressive",
        "date_from": "2025-05-01T12:00:00Z",
        "conditions": [
            {
                "logical_operator": False,
                "source_metric_code": "net_sales",
                "tiers": [],
            },
        ],
        "bonus_metric_code": "percent_of_net_sales",
        "bonuses": [
            0,
        ],
        "filter_enabled": False,
        "state": "draft",
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "organization_id": "string",
  "user_ids": [
    "string"
  ],
  "period": "week",
  "calculation_method": "progressive",
  "date_from": "2025-05-01T12:00:00Z",
  "conditions": [
    {
      "logical_operator": false,
      "source_metric_code": "net_sales",
      "tiers": []
    }
  ],
  "bonus_metric_code": "percent_of_net_sales",
  "bonuses": [
    0
  ],
  "filter_enabled": false,
  "state": "draft"
}
JSON;

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

:::

**Yo‘l parametrlari**

| Parametr | Tur | Majburiy | Tavsif |
|---|---|---|---|
| `id` | `string` | Ha | KPI settings ObjectId |

**So‘rov tanasi**

| Maydon | Tur | Majburiy | Tavsif |
|---|---|---|---|
| `organization_id` | `string` | Ha | Organization ObjectId this KPI setting belongs to |
| `name` | `string` | Yo‘q | Optional display name for the KPI setting |
| `user_ids` | `string[]` | Ha | ObjectIds of the employees this KPI setting applies to |
| `period` | `string` | Ha | KPI evaluation period. Mumkin qiymatlar: `week`, `month`, `quarter`, `year` |
| `calculation_method` | `string` | Ha | How the bonus is calculated across tiers: progressive (each tier adds to the previous) or threshold (only the matched tier applies). Mumkin qiymatlar: `progressive`, `threshold` |
| `date_from` | `string (date-time)` | Ha | Start date of the KPI period |
| `filter_enabled` | `boolean` | Ha | Whether product/customer filters are active for this KPI setting. Standart: `false` |
| `filter` | `object` | Yo‘q | Optional product and customer scope filters |
| `filter.is_all_categories` | `boolean` | Yo‘q |  |
| `filter.customer_category_ids` | `string[]` | Yo‘q | Customer category ObjectIds to include |
| `filter.customer_ids` | `string[]` | Yo‘q | Specific customer ObjectIds to include |
| `filter.product_category_ids` | `string[]` | Yo‘q |  |
| `filter.product_ids` | `string[]` | Yo‘q | Specific product ObjectIds to include |
| `conditions` | `object[]` | Ha | One or more KPI plan conditions defining the performance metric and tier thresholds |
| `conditions[].logical_operator` | `boolean` | Ha | true = AND with the next condition, false = OR |
| `conditions[].source_metric_code` | `string` | Ha | The performance metric used to evaluate this condition. Mumkin qiymatlar: `net_sales`, `sales_count`, `avg_net_sales`, `profit`, `paid`, `paid_percent`, `items_sold` |
| `conditions[].tiers` | `object[]` | Ha | Threshold tiers for this condition |
| `conditions[].tiers[].min_value` | `number` | Ha | Minimum metric value for this tier to activate |
| `conditions[].tiers[].max_value` | `number` | Yo‘q | Maximum metric value for this tier (omit for the top tier) |
| `bonus_metric_code` | `string` | Ha | How the bonus amount is computed from the employee's results. Mumkin qiymatlar: `percent_of_net_sales`, `percent_of_payment`, `percent_of_profit`, `per_sale`, `fixed_amount`, `per_item_sold` |
| `bonuses` | `number[]` | Ha | Bonus amounts or percentages, one entry per tier in the conditions |
| `responsible_id` | `string` | Yo‘q |  |
| `state` | `string` | Ha | Mumkin qiymatlar: `draft`, `active` |
| `attachments` | `object[]` | Yo‘q |  |
| `attachments[].name` | `string` | Yo‘q |  |
| `attachments[].path` | `string` | Ha |  |
| `attachments[].size` | `number` | Yo‘q |  |
| `attachments[].note` | `string` | Yo‘q |  |

```json
{
  "organization_id": "string",
  "name": "string",
  "user_ids": [
    "string"
  ],
  "period": "week",
  "calculation_method": "progressive",
  "date_from": "2025-05-01T12:00:00Z",
  "filter_enabled": false,
  "filter": {
    "is_all_categories": false,
    "customer_category_ids": [
      "string"
    ],
    "customer_ids": [
      "string"
    ],
    "product_category_ids": [
      "string"
    ],
    "product_ids": [
      "string"
    ]
  },
  "conditions": [
    {
      "logical_operator": false,
      "source_metric_code": "net_sales",
      "tiers": []
    }
  ],
  "bonus_metric_code": "percent_of_net_sales",
  "bonuses": [
    0
  ],
  "responsible_id": "64b7f4d9e2b3b6a0b7c5d7ff",
  "state": "draft",
  "attachments": [
    {
      "name": "string",
      "path": "string",
      "size": 0,
      "note": "string"
    }
  ]
}
```

**Javob**

Javob tuzilishi quyidagi bilan bir xil: [POST /kpi-settings/create](#post-kpi-settings-create).

## DELETE /kpi-settings/delete/{id}

Soft-delete a KPI settings record by ObjectId.

**Kerakli ruxsat:** `kpi_settings_delete` · [ruxsatlar qanday ishlaydi](https://docs.bito.uz/api/permissions.md)

**So‘rov namunasi**

::: code-group

```bash [curl]
curl -X DELETE 'https://api.bito.uz/integration-api/integration/api/v2/kpi-settings/delete/6712f0a9c4d1e87b3a0f9911' \
  -H "api-key: $BITO_API_KEY"
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/kpi-settings/delete/6712f0a9c4d1e87b3a0f9911', {
  method: 'DELETE',
  headers: { 'api-key': process.env.BITO_API_KEY },
})
const { code, data } = await res.json()
```

```python [Python]
import os
import requests

res = requests.request(
    "DELETE",
    "https://api.bito.uz/integration-api/integration/api/v2/kpi-settings/delete/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/kpi-settings/delete/6712f0a9c4d1e87b3a0f9911');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'DELETE',
    CURLOPT_HTTPHEADER => ['api-key: ' . getenv('BITO_API_KEY')],
    CURLOPT_RETURNTRANSFER => true,
]);
$response = json_decode(curl_exec($ch), true);
```

:::

**Yo‘l parametrlari**

| Parametr | Tur | Majburiy | Tavsif |
|---|---|---|---|
| `id` | `string` | Ha | KPI settings ObjectId |

**So‘rov tanasi**

So‘rov tanasi talab qilinmaydi.

**Javob**

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": "ok",
  "time": "2025-05-01T12:00:00Z"
}
```

## PUT /kpi-settings/set-status/{id}

Change the status (state) of a KPI settings record. Allowed transitions: locked, approved, canceled.

**Kerakli ruxsat:** `kpi_settings_update` · [ruxsatlar qanday ishlaydi](https://docs.bito.uz/api/permissions.md)

**So‘rov namunasi**

::: code-group

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

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

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

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

:::

**Yo‘l parametrlari**

| Parametr | Tur | Majburiy | Tavsif |
|---|---|---|---|
| `id` | `string` | Ha | KPI settings ObjectId |

**So‘rov tanasi**

| Maydon | Tur | Majburiy | Tavsif |
|---|---|---|---|
| `status` | `string` | Ha | New status for the KPI settings record. Mumkin qiymatlar: `locked`, `approved`, `canceled` |

```json
{
  "status": "locked"
}
```

**Javob**

Javob tuzilishi quyidagi bilan bir xil: [POST /kpi-settings/create](#post-kpi-settings-create).

---

*Bu sahifa OpenAPI spetsifikatsiyasidan yaratilgan.*
