> ## 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.

# Create and update entities

> Learn how to create, update, and delete Entities using the Fibery API.

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

## Create Entity

Create Entities with primitive, single-select and entity Fields.

Setting `fibery/id` is optional and might be useful for working with Entity right after creation.

To set a single-select or an entity Field we'll need the target Entity's `fibery/id`. We can get `fibery/id` either via API (check [Query entities](/guides/http-api/query-entities)) or by opening the relevant Entity on UI and exploring the command response in browser's Network tab.

<Callout icon="circle-exclamation" color="#9c2baf">
  Note that the target related Entity should already exist.
</Callout>

Setting entity collection Fields on Entity creation is not supported. Instead we suggest updating entity collection Fields after the Entity is created — see [Collections](/guides/http-api/collections).

Setting a rich text Field on creation is not possible either. Update rich text Field once the Entity is created — see [Rich text and comments](/guides/http-api/rich-text-and-comments).

`Cricket/Player` Database used as an example

| Field name             | Field type              |
| ---------------------- | ----------------------- |
| `fibery/id`            | `fibery/uuid`           |
| `fibery/public-id`     | `fibery/text`           |
| `Cricket/Name`         | `fibery/text`           |
| `Cricket/Full Name`    | `fibery/text`           |
| `Cricket/Born`         | `fibery/date`           |
| `Cricket/Youth Career` | `fibery/date-range`     |
| `Cricket/Shirt Number` | `fibery/int`            |
| `Cricket/Height`       | `fibery/decimal`        |
| `Cricket/Retired`      | `fibery/bool`           |
| `Cricket/Batting Hand` | single-select           |
| `Cricket/Current Team` | entity Field            |
| `Cricket/Former Teams` | entity collection 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.entity/create',
      args: {
        type: 'Cricket/Player',
        entity: {
          'fibery/id': 'd17390c4-98c8-11e9-a2a3-2a2ae2dbcce4',
          'Cricket/Name': 'Curtly Ambrose',
          'Cricket/Full Name': 'Curtly Elconn Lynwall Ambrose',
          'Cricket/Born': '1963-09-21',
          'Cricket/Youth Career': {
            start: '1985-01-01',
            end: '1986-01-01'
          },
          'Cricket/Shirt Number': 1,
          'Cricket/Height': '2.01',
          'Cricket/Retired': true,

          'Cricket/Batting Hand': { 'fibery/id': 'b0ed3a80-9747-11e9-9f03-fd937c4ecf3b' }
        }
      }
    })
  });
  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.entity/create",
       "args": {
         "type": "Cricket/Player",
         "entity": {
           "fibery/id": "d17390c4-98c8-11e9-a2a3-2a2ae2dbcce4",
           "Cricket/Name": "Curtly Ambrose",
           "Cricket/Full Name": "Curtly Elconn Lynwall Ambrose",
           "Cricket/Born": "1963-09-21",
           "Cricket/Youth Career": {
             "start": "1985-01-01",
             "end": "1986-01-01"
           },
           "Cricket/Shirt Number": 1,
           "Cricket/Height": "2.01",
           "Cricket/Retired": true,

           "Cricket/Batting Hand": {"fibery/id": "b0ed3a80-9747-11e9-9f03-fd937c4ecf3b"}
         }
       }
     }
    '
  ```
</CodeGroup>

Result with all primitive Fields, single-selects and entity Fields:

```json theme={null}
{
  "success": true,
  "result": {
    "Cricket/Height": "2.01",
    "fibery/modification-date": "2019-06-27T10:44:53.860Z",
    "Cricket/Born": "1963-09-21",
    "fibery/id": "d17390c4-98c8-11e9-a2a3-2a2ae2dbcce4",
    "fibery/creation-date": "2019-06-27T10:44:53.860Z",
    "fibery/created-by": {
      "fibery/id": "fe1db100-3779-11e9-9162-04d77e8d50cb"
    },
    "fibery/rank": 5674304923033269,
    "Cricket/Shirt Number": 1,
    "Cricket/Full Name": "Curtly Elconn Lynwall Ambrose",
    "fibery/public-id": "6",
    "Cricket/Retired": true,
    "Cricket/Current Team": null,
    "Cricket/Batting Hand": {
      "fibery/id": "b0ed3a80-9747-11e9-9f03-fd937c4ecf3b"
    },
    "Cricket/Bio": {
      "fibery/id": "019dd3cd-3810-702d-857b-20fb92d60268"
    },
    "Cricket/Youth Career": {
      "start": "1985-01-01",
      "end": "1986-01-01"
    },
    "Cricket/Name": "Curtly Ambrose"
  }
}
```

## Update Entity

Update primitive, single-select and entity Fields this way. For updating entity collection Fields, see [Collections](/guides/http-api/collections).

To update a single-select or an entity Field, we'll need the target Entity's `fibery/id`. We can get `fibery/id` either via API or by opening the relevant Entity on UI and exploring the command response in browser's Network tab. Note that the target Entity should already exist.

`Cricket/Player` Database used as an example

| Field name             | Field type              |
| ---------------------- | ----------------------- |
| `fibery/id`            | `fibery/uuid`           |
| `fibery/public-id`     | `fibery/text`           |
| `Cricket/Name`         | `fibery/text`           |
| `Cricket/Full Name`    | `fibery/text`           |
| `Cricket/Born`         | `fibery/date`           |
| `Cricket/Youth Career` | `fibery/date-range`     |
| `Cricket/Shirt Number` | `fibery/int`            |
| `Cricket/Height`       | `fibery/decimal`        |
| `Cricket/Retired`      | `fibery/bool`           |
| `Cricket/Batting Hand` | single-select           |
| `Cricket/Current Team` | entity Field            |
| `Cricket/Former Teams` | entity collection 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.entity/update',
      args: {
        type: 'Cricket/Player',
        entity: {
          'fibery/id': '20f9b920-9752-11e9-81b9-4363f716f666',
          'Cricket/Full Name': 'Virat "Chikoo" Kohli',
          'Cricket/Current Team': { 'fibery/id': 'd328b7b0-97fa-11e9-81b9-4363f716f666' }
        }
      }
    })
  });
  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.entity/update",
       "args": {
         "type": "Cricket/Player",
         "entity": {
           "fibery/id": "20f9b920-9752-11e9-81b9-4363f716f666",
           "Cricket/Full Name": "Virat \"Chikoo\" Kohli",
           "Cricket/Current Team": {"fibery/id": "d328b7b0-97fa-11e9-81b9-4363f716f666"}
         }
       }
     }
    '
  ```
</CodeGroup>

Response:

```json theme={null}
{
  "success": true,
  "result": {
    "fibery/id": "20f9b920-9752-11e9-81b9-4363f716f666"
  }
}
```

## Delete Entity

Delete an Entity by providing its Database and `fibery/id`.

<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.entity/delete',
      args: {
        type: 'Cricket/Player',
        entity: { 'fibery/id': '93648510-9907-11e9-acf1-fd0d502cdd20' }
      }
    })
  });
  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.entity/delete",
       "args": {
         "type": "Cricket/Player",
         "entity": {"fibery/id": "93648510-9907-11e9-acf1-fd0d502cdd20"}
       }
     }
    '
  ```
</CodeGroup>

Response:

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