# Change a table schema

> Source: https://elaichi.ai/docs/api-reference/collections/collection/changecollectiontableschema/

`POST /collection/{id}/table/{tableKey}/schema`

Resource: **Collection** · API: **Collections**

## Path parameters

- **`id`** _(string, required)_
  Resource id
- **`tableKey`** _(string, required)_
  Table key; `main` is the default table.

## Request body

- **`expected_version`** _(integer)_
- **`ops`** _(array<unknown>)_
- **`accept_data_loss`** _(boolean)_
- **`dry_run`** _(boolean)_

## Response body

- **`table`** _(object)_
  - **`key`** _(string)_
  - **`name`** _(string)_
  - **`description`** _(string)_
  - **`is_default`** _(boolean)_
  - **`schema_version`** _(integer)_
  - **`field_count`** _(integer)_
  - **`row_scope_field`** _(string,null)_
  - **`stats`** _(object,null)_
  - **`row_visibility`** _(string)_
    Allowed: `all`, `own`
  - **`updated_by_name`** _(string,null)_
  - **`created_at`** _(string)_
  - **`updated_at`** _(string)_
  - **`collection_id`** _(string)_
  - **`schema`** _(object)_
    - **`version`** _(integer)_
    - **`fields`** _(array<object>)_
      - **`id`** _(string)_
      - **`key`** _(string)_
      - **`name`** _(string)_
      - **`type`** _(string)_
      - **`required`** _(boolean)_
      - **`indexed`** _(boolean)_
      - **`description`** _(string)_
      - **`options`** _(unknown)_
    - **`primary_field`** _(string)_
    - **`unique_key`** _(array,null)_
    - **`row_scope`** _(object,null)_
  - **`hidden_field_keys`** _(array<string>)_
  - **`can_manage`** _(boolean)_
  - **`can_use`** _(boolean)_
- **`report`** _(object)_
  - **`dry_run`** _(boolean)_
  - **`from_version`** _(integer)_
  - **`to_version`** _(integer)_
  - **`schema`** _(object)_
    - **`version`** _(integer)_
    - **`fields`** _(array<object>)_
      - **`id`** _(string)_
      - **`key`** _(string)_
      - **`name`** _(string)_
      - **`type`** _(string)_
      - **`required`** _(boolean)_
      - **`indexed`** _(boolean)_
      - **`description`** _(string)_
      - **`options`** _(unknown)_
    - **`primary_field`** _(string)_
    - **`unique_key`** _(array,null)_
    - **`row_scope`** _(object,null)_
  - **`changes`** _(array<unknown>)_
  - **`requires_accept_data_loss`** _(boolean)_

## Code examples

### curl

```bash
curl -X POST 'https://api.elaichi.ai/collection/<id>/table/<tableKey>/schema' \
  -H 'Authorization: Bearer $ELAICHI_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"expected_version":0,"ops":[],"accept_data_loss":true,"dry_run":true}'
```

### JavaScript

```javascript
const body = {
  "expected_version": 0,
  "ops": [],
  "accept_data_loss": true,
  "dry_run": true
};

const response = await fetch('https://api.elaichi.ai/collection/<id>/table/<tableKey>/schema', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer ' + process.env.ELAICHI_API_TOKEN,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify(body),
});

const data = await response.json();
console.log(data);
```

### Python

```python
import os
import requests

url = "https://api.elaichi.ai/collection/<id>/table/<tableKey>/schema"
headers = {
    "Authorization": f"Bearer {os.environ['ELAICHI_API_TOKEN']}",
    "Content-Type": "application/json",
}
payload = {
    "expected_version": 0,
    "ops": [],
    "accept_data_loss": True,
    "dry_run": True
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```
