> ## Documentation Index
> Fetch the complete documentation index at: https://developers.fibery.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fields

> Learn how to create and manage Fields using the Fibery API.

A Field is a part of a [Database](/guides/http-api/databases). Learn more about it in the [Schema guide](/guides/http-api/schema).

<Note>
  The API uses `type` for Database and `app` for Space. See [Terminology](/guides/general/terminology#api-naming).
</Note>

## Create Field

### Primitive Field

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/commands', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      command: 'fibery.schema/batch',
      args: {
        commands: [
          {
            command: 'schema.field/create',
            args: {
              'fibery/holder-type': 'Cricket/Player',
              'fibery/name': 'Cricket/Salary',
              'fibery/type': 'fibery/int',
              'fibery/meta': {
                'fibery/readonly?': false,
                'fibery/default-value': 1000,
                'ui/number-unit': 'USD'
              }
            }
          }
        ]
      }
    })
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/commands \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '
    {
      "command": "fibery.schema/batch",
      "args": {
        "commands": [
          {
            "command": "schema.field/create",
            "args": {
              "fibery/holder-type": "Cricket/Player",
              "fibery/name": "Cricket/Salary",
              "fibery/type": "fibery/int",
              "fibery/meta": {
                "fibery/readonly?": false,
                "fibery/default-value": 1000,
                "ui/number-unit": "USD"
              }
            }
          }
        ]
      }
    }
    '
  ```
</CodeGroup>

Response:

```json theme={null}
{
  "success": true,
  "result": "ok"
}
```

Primitive Field types

| Field type               | Example                                                                                                                                                                                           | Comments                                                                                            |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| `fibery/int`             | `42`                                                                                                                                                                                              |                                                                                                     |
| `fibery/decimal`         | `0.33`                                                                                                                                                                                            |                                                                                                     |
| `fibery/bool`            | `true`                                                                                                                                                                                            |                                                                                                     |
| `fibery/text`            | `Don't panic`                                                                                                                                                                                     | Up to 1k characters. Can be styled using `ui/type` meta flag: `text` \| `email` \| `phone` \| `url` |
| `~~fibery/email~~`       | [~~contact@megadodo.com~~](mailto:contact@megadodo.com)                                                                                                                                           | Deprecated. Use a `fibery/text` field with `ui/type` meta set to `"email"`: `{"ui/type": "email"}`  |
| `fibery/emoji`           | 🏏                                                                                                                                                                                                |                                                                                                     |
| `fibery/date`            | `1979-10-12`                                                                                                                                                                                      |                                                                                                     |
| `fibery/date-time`       | `2019-06-24T12:25:20.812Z`                                                                                                                                                                        |                                                                                                     |
| `fibery/date-range`      | `{"start": "2019-06-27", "end": "2019-06-30"}`                                                                                                                                                    |                                                                                                     |
| `fibery/date-time-range` | `{"start": "2019-06-18T02:40:00.000Z", "end": "2019-07-25T11:40:00.000Z"}`                                                                                                                        |                                                                                                     |
| `fibery/location`        | `{"longitude": 2.349606, "latitude": 48.890764, "fullAddress": "Métro Marcadet Poissonniers, 67 boulevard Barbès, Paris, 75018, France", "addressParts": {"city": "Paris", "country": "France"}}` | All address parts are optional.                                                                     |
| `fibery/uuid`            | `acb5ef80-9679-11e9-bc42-526af7764f64`                                                                                                                                                            |                                                                                                     |
| `fibery/rank`            | `1000`                                                                                                                                                                                            |                                                                                                     |
| `fibery/json-value`      | `{"paranoid?": true}`                                                                                                                                                                             |                                                                                                     |

Command parameters

| Parameter (required in bold)                | Description                                                                                                                                                                                    | Example          |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
| **`fibery/holder-type`**                    | Holder Database name in `${space}/${name}` format                                                                                                                                              | `Cricket/Player` |
| **`fibery/name`**                           | Field name in `${space}/${name}` format.                                                                                                                                                       | `Cricket/Salary` |
| **`fibery/type`**                           | One of the primitive Field types above or a Database for a one-way relation.                                                                                                                   | `fibery/int`     |
| meta.`fibery/readonly?`                     | If users are able to change value from UI                                                                                                                                                      | true             |
| meta.`fibery/default-value`                 | The value automatically set when a new entity is created                                                                                                                                       | "(empty)"        |
| meta.`fibery/unique?`                       | Makes field values to be unique across the whole Database Only one of unique flags can be used at a time as `fibery/unique?` and `fibery/case-insensitive-text-unique?` are mutually exclusive | true             |
| meta.`fibery/case-insensitive-text-unique?` | makes field values to be unique case insensitive across whole Database                                                                                                                         | true             |

#### Create unique case insensitive Text Field:

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/commands', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      command: 'fibery.schema/batch',
      args: {
        commands: [
          {
            command: 'schema.field/create',
            args: {
              'fibery/holder-type': 'Cricket/Player',
              'fibery/name': 'Cricket/SSN',
              'fibery/type': 'fibery/text',
              'fibery/meta': {
                'fibery/readonly?': false,
                'fibery/case-insensitive-text-unique?': true
              }
            }
          }
        ]
      }
    })
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/commands \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '
    {
      "command": "fibery.schema/batch",
      "args": {
        "commands": [
          {
            "command": "schema.field/create",
            "args": {
              "fibery/holder-type": "Cricket/Player",
              "fibery/name": "Cricket/SSN",
              "fibery/type": "fibery/text",
              "fibery/meta": {
                "fibery/readonly?": false,
                "fibery/case-insensitive-text-unique?": true
              }
            }
          }
        ]
      }
    }
    '
  ```
</CodeGroup>

Response:

```json theme={null}
{
  "success": true,
  "result": "ok"
}
```

#### Create unique Int Field:

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/commands', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      command: 'fibery.schema/batch',
      args: {
        commands: [
          {
            command: 'schema.field/create',
            args: {
              'fibery/holder-type': 'Cricket/Player',
              'fibery/name': 'Cricket/Jersey Number',
              'fibery/type': 'fibery/int',
              'fibery/meta': {
                'fibery/readonly?': false,
                'fibery/unique?': true
              }
            }
          }
        ]
      }
    })
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/commands \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '
    {
      "command": "fibery.schema/batch",
      "args": {
        "commands": [
          {
            "command": "schema.field/create",
            "args": {
              "fibery/holder-type": "Cricket/Player",
              "fibery/name": "Cricket/Jersey Number",
              "fibery/type": "fibery/int",
              "fibery/meta": {
                "fibery/readonly?": false,
                "fibery/unique?": true
              }
            }
          }
        ]
      }
    }
    '
  ```
</CodeGroup>

Response:

```json theme={null}
{
  "success": true,
  "result": "ok"
}
```

### Relation (entity \[collection] Field)

To create a relation between two Databases, we create a pair of entity \[collection] Fields and connect them with a unique identifier.

The relation is to-one by default. Set entity Field's meta.`fibery/collection?` to `true` for to-many relation.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const relationId = 'd9e9ec34-9685-11e9-8550-526af7764f64';

  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/commands', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      command: 'fibery.schema/batch',
      args: {
        commands: [
          {
            command: 'schema.field/create',
            args: {
              'fibery/holder-type': 'Cricket/Player',
              'fibery/name': 'Cricket/Current Team',
              'fibery/type': 'Cricket/Team',
              'fibery/meta': {
                'fibery/relation': relationId
              }
            }
          },
          {
            command: 'schema.field/create',
            args: {
              'fibery/holder-type': 'Cricket/Team',
              'fibery/name': 'Cricket/Current Roster',
              'fibery/type': 'Cricket/Player',
              'fibery/meta': {
                'fibery/collection?': true,
                'fibery/relation': relationId
              }
            }
          }
        ]
      }
    })
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/commands \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '
    {
      "command": "fibery.schema/batch",
      "args": {
        "commands": [
          {
            "command": "schema.field/create",
            "args": {
              "fibery/holder-type": "Cricket/Player",
              "fibery/name": "Cricket/Current Team",
              "fibery/type": "Cricket/Team",
              "fibery/meta": {
                "fibery/relation": "d9e9ec34-9685-11e9-8550-526af7764f64"
              }
            }
          },
          {
            "command": "schema.field/create",
            "args": {
              "fibery/holder-type": "Cricket/Team",
              "fibery/name": "Cricket/Current Roster",
              "fibery/type": "Cricket/Player",
              "fibery/meta": {
                "fibery/collection?": true,
                "fibery/relation": "d9e9ec34-9685-11e9-8550-526af7764f64"
              }
            }
          }
        ]
      }
    }
    '
  ```
</CodeGroup>

Response:

```json theme={null}
{
  "success": true,
  "result": "ok"
}
```

Command parameters

| Parameter (required in bold) | Description                                           | Example                |
| ---------------------------- | ----------------------------------------------------- | ---------------------- |
| **`fibery/holder-type`**     | Holder Database name in `${space}/${name}` format     | `Cricket/Player`       |
| **`fibery/name`**            | Field name in `${space}/${name}` format.              | `Cricket/Current Team` |
| **`fibery/type`**            | Related Database name in `${space}/${name}` format    | `Cricket/Team`         |
| meta.**`fibery/relation`**   | UUID shared between the pair of Fields.               | d9e9ec34-96...         |
| meta.`fibery/collection?`    | `true` for to-many relation (entity collection Field) | true                   |
| meta.`fibery/readonly?`      | If users are able to change value from UI             | true                   |

### Single-select Field

A single-select Field is not what it seems to be. Actually, every single-select option is an Entity of a newly created special Database.

This way unlocks 'name on UI + value in Formula' scenario (think `Self conviction` → `0.01` in GIST) and enables an easy transition to a fully functional Database.

To create a single-select Field we should:

1. Create a new `enum` Database
2. Create a Field of the newly created `enum` Database
3. Create an Entity for each single-select option
4. Make the selection required and set the default value

The new `enum` Database name is built using this format: `${space}/${field}_${app}/${holder-type}`.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const enumType = 'Cricket/Batting Hand_Cricket/Player';
  const rightId = '4a3ffb10-9747-11e9-9def-016e5ea5e162';
  const leftId = '4a402220-9747-11e9-9def-016e5ea5e162';

  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/commands', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      command: 'fibery.command/batch',
      args: {
        commands: [
          {
            command: 'fibery.schema/batch',
            args: {
              commands: [
                {
                  command: 'schema.enum/create',
                  args: { 'fibery/name': enumType }
                },
                {
                  command: 'schema.field/create',
                  args: {
                    'fibery/holder-type': 'Cricket/Player',
                    'fibery/name': 'Cricket/Batting Hand',
                    'fibery/type': enumType
                  }
                }
              ]
            }
          },
          {
            command: 'fibery.entity/create',
            args: {
              type: enumType,
              entity: {
                'enum/name': 'Right',
                'fibery/id': rightId,
                'fibery/rank': 0
              }
            }
          },
          {
            command: 'fibery.entity/create',
            args: {
              type: enumType,
              entity: {
                'enum/name': 'Left',
                'fibery/id': leftId,
                'fibery/rank': 1000000
              }
            }
          },
          {
            command: 'fibery.schema/batch',
            args: {
              commands: [
                {
                  command: 'schema.field/set-meta',
                  args: {
                    name: 'Cricket/Batting Hand',
                    'holder-type': 'Cricket/Player',
                    key: 'fibery/default-value',
                    value: { 'fibery/id': rightId }
                  }
                },
                {
                  command: 'schema.field/set-meta',
                  args: {
                    name: 'Cricket/Batting Hand',
                    'holder-type': 'Cricket/Player',
                    key: 'fibery/required?',
                    value: true
                  }
                }
              ]
            }
          }
        ]
      }
    })
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/commands \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '
    {
      "command": "fibery.command/batch",
      "args": {
        "commands": [
          {
            "command": "fibery.schema/batch",
            "args": {
              "commands": [
                {
                  "command": "schema.enum/create",
                  "args": {
                    "fibery/name": "Cricket/Batting Hand_Cricket/Player"
                  }
                },
                {
                  "command": "schema.field/create",
                  "args": {
                    "fibery/holder-type": "Cricket/Player",
                    "fibery/name": "Cricket/Batting Hand",
                    "fibery/type": "Cricket/Batting Hand_Cricket/Player"
                  }
                }
              ]
            }
          },
          {
            "command": "fibery.entity/create",
            "args": {
              "type": "Cricket/Batting Hand_Cricket/Player",
              "entity": {
                "enum/name": "Right",
                "fibery/id": "4a3ffb10-9747-11e9-9def-016e5ea5e162",
                "fibery/rank": 0
              }
            }
          },
          {
            "command": "fibery.entity/create",
            "args": {
              "type": "Cricket/Batting Hand_Cricket/Player",
              "entity": {
                "enum/name": "Left",
                "fibery/id": "4a402220-9747-11e9-9def-016e5ea5e162",
                "fibery/rank": 1000000
              }
            }
          },
          {
            "command": "fibery.schema/batch",
            "args": {
              "commands": [
                {
                  "command": "schema.field/set-meta",
                  "args": {
                    "name": "Cricket/Batting Hand",
                    "holder-type": "Cricket/Player",
                    "key": "fibery/default-value",
                    "value": {
                      "fibery/id": "4a3ffb10-9747-11e9-9def-016e5ea5e162"
                    }
                  }
                },
                {
                  "command": "schema.field/set-meta",
                  "args": {
                    "name": "Cricket/Batting Hand",
                    "holder-type": "Cricket/Player",
                    "key": "fibery/required?",
                    "value": true
                  }
                }
              ]
            }
          }
        ]
      }
    }
    '
  ```
</CodeGroup>

Response:

```json theme={null}
{
  "success": true,
  "result": [
    {
      "success": true,
      "result": "ok"
    },
    {
      "success": true,
      "result": {
        "fibery/id": "4a3ffb10-9747-11e9-9def-016e5ea5e162",
        "fibery/public-id": "1",
        "enum/name": "Right",
        "fibery/rank": 0
      }
    },
    {
      "success": true,
      "result": {
        "fibery/id": "4a402220-9747-11e9-9def-016e5ea5e162",
        "fibery/public-id": "2",
        "enum/name": "Left",
        "fibery/rank": 1000000
      }
    },
    {
      "success": true,
      "result": "ok"
    }
  ]
}
```

### Rich text Field

In Fibery, every rich text Field instance is, in fact, a collaborative document.

It means that for each Entity with N rich text Fields Fibery automatically creates N documents. Each of these documents is stored in Document Storage and is connected to its Entity through an auxiliary `Collaboration~Documents/Document` Entity:

Entity --- (magic) ---> `Collab Doc/Document` --- (`fibery/secret`) ---> Document in Storage

So to create a rich text Field we just connect our Database with the `Collaboration~Documents/Document` Database. This Database has a special property: the entities inside it inherit access from their Parent Entity. To indicate that Parent-Child relationship we pass `fibery/entity-component?` meta flag, but only for ordinary Fields (e.g. not Lookup and not Formula)

Selecting and updating a rich text Field is a two-step process:

1. Get `fibery/secret` of the related Document.
2. Work with this Document via `api/documents` Storage endpoint.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/commands', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      command: 'fibery.schema/batch',
      args: {
        commands: [
          {
            command: 'schema.field/create',
            args: {
              'fibery/holder-type': 'Cricket/Player',
              'fibery/name': 'Cricket/Bio',
              'fibery/type': 'Collaboration~Documents/Document',
              'fibery/meta': {
                'fibery/entity-component?': true
              }
            }
          }
        ]
      }
    })
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/commands \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '
    {
      "command": "fibery.schema/batch",
      "args": {
        "commands": [
          {
            "command": "schema.field/create",
            "args": {
              "fibery/holder-type": "Cricket/Player",
              "fibery/name": "Cricket/Bio",
              "fibery/type": "Collaboration~Documents/Document",
              "fibery/meta": {
                "fibery/entity-component?": true
              }
            }
          }
        ]
      }
    }
    '
  ```
</CodeGroup>

Response:

```json theme={null}
{
  "success": true,
  "result": "ok"
}
```

## Rename Field

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/commands', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      command: 'fibery.schema/batch',
      args: {
        commands: [
          {
            command: 'schema.field/rename',
            args: {
              'holder-type': 'Cricket/Player',
              'from-name': 'Cricket/Position',
              'to-name': 'Cricket/Role'
            }
          }
        ]
      }
    })
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/commands \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '
    {
      "command": "fibery.schema/batch",
      "args": {
        "commands": [
          {
            "command": "schema.field/rename",
            "args": {
              "holder-type": "Cricket/Player",
              "from-name": "Cricket/Position",
              "to-name": "Cricket/Role"
            }
          }
        ]
      }
    }
    '
  ```
</CodeGroup>

Response:

```json theme={null}
{
  "success": true,
  "result": "ok"
}
```

Command parameters

| Parameter (required in bold) | Description                                       | Example            |
| ---------------------------- | ------------------------------------------------- | ------------------ |
| **`holder-type`**            | Holder Database name in `${space}/${name}` format | `Cricket/Player`   |
| **`from-name`**              | Current Field name in `${space}/${name}` format   | `Cricket/Position` |
| **`to-name`**                | New Field name in `${space}/${name}` format       | `Cricket/Role`     |

## Delete Field

<CodeGroup>
  ```javascript JavaScript theme={null}
  const response = await fetch('https://YOUR_ACCOUNT.fibery.io/api/commands', {
    method: 'POST',
    headers: {
      'Authorization': 'Token YOUR_TOKEN',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      command: 'fibery.schema/batch',
      args: {
        commands: [
          {
            command: 'schema.field/delete',
            args: {
              'holder-type': 'Cricket/Player',
              name: 'Cricket/Role',
              'delete-values?': true
            }
          }
        ]
      }
    })
  });
  const data = await response.json();
  ```

  ```bash cURL theme={null}
  curl -X POST https://YOUR_ACCOUNT.fibery.io/api/commands \
    -H 'Authorization: Token YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '
    {
      "command": "fibery.schema/batch",
      "args": {
        "commands": [
          {
            "command": "schema.field/delete",
            "args": {
              "holder-type": "Cricket/Player",
              "name": "Cricket/Role",
              "delete-values?": true
            }
          }
        ]
      }
    }
    '
  ```
</CodeGroup>

Response:

```json theme={null}
{
  "success": true,
  "result": "ok"
}
```

### **Command parameters**

| Parameter (required in bold) | Default | Description                                       | Example          |
| ---------------------------- | ------- | ------------------------------------------------- | ---------------- |
| **`holder-type`**            |         | Holder Database name in `${space}/${name}` format | `Cricket/Player` |
| **`name`**                   |         | Field name in `${space}/${name}` format           | `Cricket/Role`   |
| **`delete-values?`**         | false   | See the behavior in the table below               | true             |

<Callout icon="circle-exclamation" color="#1fbed3">
  To remove a relation, delete both entity \[collection] Fields within the same `fibery.schema/batch` command.
</Callout>

`delete-values?` parameter behavior

<table class="matrix-table">
  <thead>
    <tr>
      <th />

      <th />

      <th colSpan={2}>**`delete-values?`**</th>
    </tr>

    <tr>
      <th />

      <th />

      <th>**false**</th>
      <th>**true**</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <th rowSpan={4}>**Field type**</th>
      <td>**Empty [primitive](#primitive-field) Field**</td>
      <td>Field is deleted</td>
      <td>Field is deleted</td>
    </tr>

    <tr>
      <td>**Non-empty primitive Field**</td>
      <td>Error is thrown</td>
      <td>Field and values are deleted</td>
    </tr>

    <tr>
      <td>**Empty entity \[collection] Field**</td>
      <td>Field is deleted</td>
      <td>Field is deleted</td>
    </tr>

    <tr>
      <td>**Non-empty entity \[collection] Field**</td>
      <td>Error is thrown</td>
      <td>Field and links (but not related Entities) are deleted</td>
    </tr>
  </tbody>
</table>
