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

# Update Record

### Path

PATCH /api/table/\{tableId}/record/\{recordId}

### Request

#### Path Parameters

* tableId (string): The unique identifier of the table [(how to get)](/en/api-doc/get-id#tableid).
* recordId (string): The unique identifier of the record to update [(how to get)](/en/api-doc/get-id#recordid).

#### Request Body

* **record (required)**
  * Description: The record data to update
  * Type: Object
  * Example:
    ```json theme={null}
    {
      "fields": {
        "Name": "John Doe",
        "Age": 31,
        "Email": "john.doe@example.com"
      }
    }
    ```
  * Note: The `fields` object contains field names and their corresponding new values. Each field type has a different value structure, see [Record Field Value Types](/en/api-doc/record/interface) for details.

To clear a field's value, explicitly pass `null`. If a field name is not included, no update will be performed for that field.

* **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"
      }
      ```

For uploading new files to attachment fields, please refer to the [Upload Attachment](/en/api-doc/record/upload-attachment) section.

* **order (optional)**
  * Description: After updating the record, move it to a specified position in a specified view.
  * Type: Object
  * Properties:
    * viewId: View ID
    * anchorId: Anchor record ID
    * position: Position relative to the anchor record. Possible values: `"before"` or `"after"`
  * Example:
    ```json theme={null}
    {
      "viewId": "viwABCDEFGHIJKLMN",
      "anchorId": "rec123456789ABCDE",
      "position": "after"
    }
    ```

### Response

#### Success Response

* Status code: 200 OK
* Response body: Returns the updated record data.

**Example Response Body**

```json theme={null}
{
    "id": "rec123456789ABCDE",
    "fields": {
        "Name": "John Doe",
        "Age": 31,
        "Email": "john.doe@example.com"
    }
}
```

#### Error Responses

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

#### Example Code

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

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

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

  const response = await updateRecord('__tableId__', '__recordId__', {
    record: {
      fields: {
        Name: 'John Doe',
        Age: 31
      }
    }
  });

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

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

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

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

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

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