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

# レコードを更新

### パス

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

### リクエスト

#### パスパラメーター

* tableId (string): テーブルの一意の識別子です（[取得方法](/ja/api-doc/get-id#tableid)）。
* recordId (string): 更新するレコードの一意の識別子です（[取得方法](/ja/api-doc/get-id#recordid)）。

#### リクエスト本文

* **record（必須）**
  * 説明: 更新するレコードデータ
  * 型: オブジェクト
  * 例:
    ```json theme={null}
    {
      "fields": {
        "Name": "John Doe",
        "Age": 31,
        "Email": "john.doe@example.com"
      }
    }
    ```
  * 注: `fields`オブジェクトには、フィールド名と対応する新しい値が含まれます。フィールド型ごとに値の構造が異なります。詳しくは[レコードフィールドの値の型](/ja/api-doc/record/interface)をご覧ください。

フィールドの値を消去するには、明示的に`null`を渡します。フィールド名を含めなかった場合、そのフィールドは更新されません。

* **fieldKeyType（任意）**
  * 説明: フィールドキーの種類を指定します
  * 型: 文字列
  * 指定可能な値:
    * "name": フィールド名をキーとして使用します
    * "id": フィールドIDをキーとして使用します
    * "dbFieldName": フィールドのdbFieldNameをキーとして使用します
  * 例: `"name"`、`"id"`、または`"dbFieldName"`
  * 注: 指定しない場合、デフォルトではフィールド名がキーとして使用されます。
  * 使用方法:
    * "name"に設定した場合:
      ```json theme={null}
      {
        "fields": {
          "Name": "John Doe",
          "Age": 30
        }
      }
      ```
    * "id"に設定した場合:
      ```json theme={null}
      {
        "fields": {
          "fldABCDEFGHIJKLMN": "John Doe",
          "fldOPQRSTUVWXYZ12": 30
        }
      }
      ```
* **typecast（任意）**
  * 説明: フィールド値の型を自動変換するかどうかを指定します。デフォルトでは厳密な検証が適用され、入力値が現在のフィールドのデータ型と一致している必要があります。有効にすると、システムが自動変換を試みます。
  * 型: ブール値
  * 指定可能な値: trueまたはfalse
  * 例: `true`
  * 注: trueに設定すると、入力値を正しいフィールド値の型へ変換しようとします。
  * 使用例:
    * リンクフィールド: 主キーテキストをリンクに直接使用できます
      ```json theme={null}
      {
        "User table": "John Smith"
      }
      ```
    * 日付フィールド: 標準形式以外の日付文字列を使用できます
      ```json theme={null}
      {
        "Date": "2023-05-15"
      }
      ```
    * ユーザーフィールド: ユーザー名を直接使用できます
      ```json theme={null}
      {
        "Assigned To": "John Doe"
      }
      ```

添付ファイルフィールドに新しいファイルをアップロードする方法については、[添付ファイルをアップロード](/ja/api-doc/record/upload-attachment)セクションをご覧ください。

* **order（任意）**
  * 説明: レコードの更新後、指定したビュー内の指定位置へ移動します。
  * 型: オブジェクト
  * プロパティ:
    * viewId: ビューID
    * anchorId: 基準となるレコードID
    * position: 基準レコードに対する位置。指定可能な値: `"before"`または`"after"`
  * 例:
    ```json theme={null}
    {
      "viewId": "viwABCDEFGHIJKLMN",
      "anchorId": "rec123456789ABCDE",
      "position": "after"
    }
    ```

### レスポンス

#### 成功レスポンス

* ステータスコード: 200 OK
* レスポンス本文: 更新されたレコードデータを返します。

**レスポンス本文の例**

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

#### エラーレスポンス

* ステータスコード: 400 Bad Request: リクエスト本文の形式が正しくないか、必須フィールドがありません。
* ステータスコード: 404 Not Found: 指定したtableIdまたはrecordIdが存在しません。

#### コード例

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