# Custom field

::: 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`.
:::

## GET /custom-field/get-all

List custom fields, optionally filtered by the target collection (table_name).

**Required permission:** none — closed to an app that declares permissions · [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/custom-field/get-all' \
  -H "api-key: $BITO_API_KEY"
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/custom-field/get-all', {
  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/custom-field/get-all",
    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/custom-field/get-all');
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);
```

:::

**Query parameters**

| Parameter | Type | Required | Description |
|---|---|---|---|
| `table_name` | `string` | No | Filter by target collection (e.g. customers, products, trades). |

**Request body**

No request body.

**Response**

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": [
    {
      "_id": "string",
      "table_name": "string",
      "type": "string",
      "name": "string",
      "code": "string",
      "regex": "string",
      "error_message": "string",
      "is_required": false,
      "is_api_only": false,
      "is_visible": false,
      "order": 0,
      "options": [
        {
          "position": null,
          "value": null
        }
      ],
      "organization_specs": [
        {
          "organization_id": null,
          "required_state_id": null
        }
      ],
      "accessed_user_ids": [
        "string"
      ],
      "created_at": "2025-05-01T12:00:00Z",
      "updated_at": "2025-05-01T12:00:00Z"
    }
  ],
  "time": "2025-05-01T12:00:00Z"
}
```

## POST /custom-field/create

Create a custom field on a target collection.

**Required permission:** none — closed to an app that declares permissions · [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/custom-field/create' \
  -H "api-key: $BITO_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
  "table_name": "customers",
  "type": "text",
  "name": "Loyalty tier",
  "is_required": false,
  "code": "loyalty_tier"
}'
```

```js [JavaScript]
const res = await fetch('https://api.bito.uz/integration-api/integration/api/v2/custom-field/create', {
  method: 'POST',
  headers: { 'api-key': process.env.BITO_API_KEY, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    "table_name": "customers",
    "type": "text",
    "name": "Loyalty tier",
    "is_required": false,
    "code": "loyalty_tier"
  }),
})
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/custom-field/create",
    headers={"api-key": os.environ["BITO_API_KEY"]},
    json={
        "table_name": "customers",
        "type": "text",
        "name": "Loyalty tier",
        "is_required": False,
        "code": "loyalty_tier",
    },
)
print(res.json())
```

```php [PHP]
<?php
$body = <<<'JSON'
{
  "table_name": "customers",
  "type": "text",
  "name": "Loyalty tier",
  "is_required": false,
  "code": "loyalty_tier"
}
JSON;

$ch = curl_init('https://api.bito.uz/integration-api/integration/api/v2/custom-field/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 |
|---|---|---|---|
| `table_name` | `string` | Yes | Target collection (e.g. customers, products, trades, saleOrders). |
| `type` | `string` | Yes | One of: `text`, `number`, `date`, `boolean`, `select`, `multi_select`, `radio_button`, `textarea` |
| `name` | `string` | Yes |  |
| `code` | `string` | Yes |  |
| `regex` | `string` | No | Optional regex for client-side validation. |
| `error_message` | `string` | No | Error message shown when regex fails. |
| `is_required` | `boolean` | Yes | Default: `false` |
| `is_api_only` | `boolean` | No | Hide from UI; only available via API.. Default: `false` |
| `is_visible` | `boolean` | No | Default: `true` |
| `organization_specs` | `object[]` | No | Per-organization required-state overrides. |
| `organization_specs[].organization_id` | `string` | Yes |  |
| `organization_specs[].required_state_id` | `string` | No |  |
| `accessed_user_ids` | `string[]` | No |  |
| `options` | `object[]` | No | Required when type is select / multi_select / radio_button. |
| `options[].position` | `number` | Yes |  |
| `options[].value` | `string` | Yes |  |

```json
{
  "table_name": "customers",
  "type": "text",
  "name": "Loyalty tier",
  "code": "loyalty_tier",
  "regex": "string",
  "error_message": "string",
  "is_required": false,
  "is_api_only": false,
  "is_visible": true,
  "organization_specs": [
    {
      "organization_id": "64b7f4d9e2b3b6a0b7c5d80a",
      "required_state_id": "64b7f4d9e2b3b6a0b7c5d80a"
    }
  ],
  "accessed_user_ids": [
    "64b7f4d9e2b3b6a0b7c5d80a"
  ],
  "options": [
    {
      "position": 1,
      "value": "Gold"
    }
  ]
}
```

**Response**

| Field | Type | Description |
|---|---|---|
| `_id` | `string` |  |
| `table_name` | `string` |  |
| `type` | `string` |  |
| `name` | `string` |  |
| `code` | `string` |  |
| `regex` | `string` |  |
| `error_message` | `string` |  |
| `is_required` | `boolean` |  |
| `is_api_only` | `boolean` |  |
| `is_visible` | `boolean` |  |
| `order` | `number` |  |
| `options` | `object[]` |  |
| `options[].position` | `number` |  |
| `options[].value` | `string` |  |
| `organization_specs` | `object[]` |  |
| `organization_specs[].organization_id` | `string` |  |
| `organization_specs[].required_state_id` | `string` |  |
| `accessed_user_ids` | `string[]` |  |
| `created_at` | `string (date-time)` |  |
| `updated_at` | `string (date-time)` |  |

```json
{
  "code": 0,
  "message": "Success",
  "status_code": 200,
  "data": {
    "_id": "string",
    "table_name": "string",
    "type": "string",
    "name": "string",
    "code": "string",
    "regex": "string",
    "error_message": "string",
    "is_required": false,
    "is_api_only": false,
    "is_visible": false,
    "order": 0,
    "options": [
      {
        "position": 0,
        "value": "string"
      }
    ],
    "organization_specs": [
      {
        "organization_id": "string",
        "required_state_id": "string"
      }
    ],
    "accessed_user_ids": [
      "string"
    ],
    "created_at": "2025-05-01T12:00:00Z",
    "updated_at": "2025-05-01T12:00:00Z"
  },
  "time": "2025-05-01T12:00:00Z"
}
```

---

*This page is generated from the OpenAPI spec.*
