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

# Create Records

### Path

POST /api/table/\{tableId}/record

### Request

#### Path Parameters

* tableId (string): The unique identifier of the table.

#### Request Body

* **records (required)**
  * Description: Array of records to create
  * Type: Array
  * Example:
    ```json theme={null}
    [
      {
        "fields": {
          "Name": "John Doe",
          "Age": 30,
          "Email": "john@example.com"
        }
      },
      {
        "fields": {
          "Name": "Jane Smith",
          "Age": 28,
          "Email": "jane@example.com"
        }
      }
    ]
    ```
  * Note: Each record is an item containing a `fields` object. The `fields` object contains field names and their corresponding values. Each field type has a different value structure, see [Record Field Value Types](/en/api-doc/record/interface) for details.
* **fieldKeyType (optional)**
  * Description: Specifies the type of field key
  * Type: String
  * Possible values:
    * "name": Use field name as key
    * "id": Use field ID as key
    * "dbFieldName": Use field dbFieldName as key
  * Example: `"name"` or `"id"` or `"dbFieldName"`
  * Note: If not specified, field name is used as key by default.
  * Usage:
    * When set to "name":
      ```json theme={null}
      {
        "fields": {
          "Name": "John Doe",
          "Age": 30
        }
      }
      ```
    * When set to "id":
      ```json theme={null}
      {
        "fields": {
          "fldABCDEFGHIJKLMN": "John Doe",
          "fldOPQRSTUVWXYZ12": 30
        }
      }
      ```
* **typecast (optional)**
  * Description: Whether to automatically convert field value types. By default, strict validation is enforced, requiring input values to match the current field's data type. If enabled, the system will attempt automatic conversion.
  * Type: Boolean
  * Possible values: true or false
  * Example: `true`
  * Note: If set to true, the system will attempt to convert input values to the correct field value type.
  * Usage examples:
    * Link field: Can directly use primary key text for linking
      ```json theme={null}
      {
        "User table": "John Smith"
      }
      ```
    * Date field: Can use non-standard format date strings
      ```json theme={null}
      {
        "Date": "2023-05-15"
      }
      ```
    * User field: Can directly use username
      ```json theme={null}
      {
        "Assigned To": "John Doe"
      }
      ```
* **order (optional)**
  * Description: Specifies the position of new records in a specific view
  * Type: Object
  * Properties:
    * viewId
      * Description: View ID [(how to get)](/en/api-doc/get-id#viewid)
      * Type: String
      * Example: `"viwABCDEFGHIJKLMN"`
    * anchorId
      * Description: Anchor record ID [(how to get)](/en/api-doc/get-id#recordid)
      * Type: String
      * Example: `"rec123456789ABCDE"`
    * position
      * Description: Position relative to the anchor record
      * Type: String
      * Possible values:
        * "before": Before the anchor record
        * "after": After the anchor record
      * Example: `"after"`
  * Complete example:
    ```json theme={null}
    {
      "viewId": "viwABCDEFGHIJKLMN",
      "anchorId": "rec123456789ABCDE",
      "position": "after"
    }
    ```
  * Note: Using order allows precise control of new record positions in a specific view.

### Response

#### Success Response

* Status code: 201 Created
* Response body: Returns the created record data.

**Example Response Body**

```json theme={null}
{
  "records": [
    {
      "id": "record789",
      "fields": {
        "single line text": "text value 1"
      }
    },
    {
      "id": "record567",
      "fields": {
        "single line text": "text value 2"
      }
    }
  ]
}
```

### Error Responses

* Status code: 400 Bad Request: Request body format error or missing required fields.
* Status code: 404 Not Found: Specified tableId does not exist.

### Example Code

<CodeGroup>
  ```bash CURL theme={null}
  curl -X POST 'https://app.teable.ai/api/table/__tableId__/record' \
    -H 'Authorization: Bearer __token__' \
    -H 'Content-Type: application/json' \
    -d '{
      "records": [
        {
          "fields": {
            "Name": "John Doe",
            "Age": 30
          }
        }
      ]
    }'
  ```

  ```js JS SDK theme={null}
  import { configApi, createRecords } from '@teable/openapi';

  configApi({
    endpoint: 'https://app.teable.ai',
    token,
  });

  const response = await createRecords('__tableId__', {
    records: [
      {
        fields: {
          Name: 'John Doe',
          Age: 30
        }
      }
    ]
  });

  console.log(response.data);
  ```

  ```ts TypeScript theme={null}
  const response = await fetch('https://app.teable.ai/api/table/__tableId__/record', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer __token__',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      records: [
        {
          fields: {
            Name: 'John Doe',
            Age: 30
          }
        }
      ]
    })
  });

  console.log(await response.json());
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://app.teable.ai/api/table/__tableId__/record',
      headers={
          'Authorization': 'Bearer __token__',
          'Content-Type': 'application/json'
      },
      json={
          'records': [
              {
                  'fields': {
                      'Name': 'John Doe',
                      'Age': 30
                  }
              }
          ]
      }
  )

  print(response.json())
  ```
</CodeGroup>
