# Add a table to a collection

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

`POST /collection/{id}/table`

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

## Path parameters

- **`id`** _(string, required)_
  Resource id

## Request body

- **`key`** _(string)_
- **`name`** _(string)_
- **`description`** _(string)_
- **`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<string>)_
- **`row_scope`** _(object)_
- **`history`** _(object)_

## Response body

- **`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)_

## Code examples

### curl

```bash
curl -X POST 'https://api.elaichi.ai/collection/<id>/table' \
  -H 'Authorization: Bearer $ELAICHI_API_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"key":"your_key","name":"your_name","description":"your_description","fields":[],"primary_field":"your_primary_field","unique_key":[],"row_scope":{},"history":{}}'
```

### JavaScript

```javascript
const body = {
  "key": "your_key",
  "name": "your_name",
  "description": "your_description",
  "fields": [],
  "primary_field": "your_primary_field",
  "unique_key": [],
  "row_scope": {},
  "history": {}
};

const response = await fetch('https://api.elaichi.ai/collection/<id>/table', {
  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"
headers = {
    "Authorization": f"Bearer {os.environ['ELAICHI_API_TOKEN']}",
    "Content-Type": "application/json",
}
payload = {
    "key": "your_key",
    "name": "your_name",
    "description": "your_description",
    "fields": [],
    "primary_field": "your_primary_field",
    "unique_key": [],
    "row_scope": {},
    "history": {}
}

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