更新表格資料
更新表格資料
此 API 允許您批次更新 Agent 資料庫表格中的指定記錄,每次請求最多可更新 100 筆記錄。
請您注意:
- 整個 JSON 請求內容(request body)大小限制為 5MB。
- 每次請求最多可更新 100 筆記錄。
請求方法
POST
請求 URL
https://api.${endpoint}gptbots.ai/v2/database/update/record
認證
有關認證詳情,請參考 API 概覽。
請求
請求範例
curl -X POST 'https://api-${endpoint}gptbots.ai/v2/database/update/record' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"table_id": "673af861ed69656ac0895b07",
"is_create": true,
"update_data":[
{
"record_id":"123456",
"updated_fields": {
"name": "andy",
"age": "30"
}
},
{
"filter": {
"id": "789"
},
"updated_fields": {
"name": "mop",
"age": "32"
}
}
]
}'
curl -X POST 'https://api-${endpoint}gptbots.ai/v2/database/update/record' \
-H 'Authorization: Bearer ${API Key}' \
-H 'Content-Type: application/json' \
-d '{
"table_id": "673af861ed69656ac0895b07",
"is_create": true,
"update_data":[
{
"record_id":"123456",
"updated_fields": {
"name": "andy",
"age": "30"
}
},
{
"filter": {
"id": "789"
},
"updated_fields": {
"name": "mop",
"age": "32"
}
}
]
}'
此代碼塊在浮窗中顯示
請求標頭
| 欄位 | 類型 | 描述 |
|---|---|---|
| Authorization | Bearer ${API Key} | 使用 Authorization: Bearer ${API Key} 進行認證。API 密鑰可於 API 密鑰頁面取得。 |
| Content-Type | application/json | 資料格式,必須為 application/json。 |
請求內容
| 欄位 | 類型 | 必填 | 描述 |
|---|---|---|---|
| table_id | string | 是 | 表格 ID。 |
| is_create | bool | 否 | 當指定目標記錄不存在時,是否自動新增記錄。預設為 false。 |
| update_data | list | 是 | 要更新的資料集合。 |
| record_id | string | 否 | record_id 或 filter 必須擇一提供,建議優先使用 record_id。 |
| filter | map | 否 | 使用者自訂的篩選條件,必須包含唯一欄位("unique": true),僅支援一個欄位。 |
| updated_fields | list | 是 | 要更新的欄位集合。 |
注意
- 必須提供 record_id 或 filter 其中之一,建議優先使用 record_id。若同時提供,將以 record_id 為主。
- 當未提供 is_create 時,不會自動新增記錄。
- 當 is_create 設為 true 時,若要更新的記錄(record_id 或 filter)在資料表中不存在,則會自動新增該記錄。
回應
回應範例
{
"totalCount": 4,
"success_count": 2,
"fail_count": 2,
"fail_detail": [
{
"upsert_data": {
"record_id": "123456",
"value": {
"name": "test user",
"email": "invalid_email"
}
},
"fail_reason": "電子郵件格式無效"
},
{
"upsert_data": {
"filter": {
"id": "789"
},
"value": {
"name": "test user",
"email": "invalid_email"
}
},
"fail_reason": "電子郵件格式無效"
}
]
}
{
"totalCount": 4,
"success_count": 2,
"fail_count": 2,
"fail_detail": [
{
"upsert_data": {
"record_id": "123456",
"value": {
"name": "test user",
"email": "invalid_email"
}
},
"fail_reason": "電子郵件格式無效"
},
{
"upsert_data": {
"filter": {
"id": "789"
},
"value": {
"name": "test user",
"email": "invalid_email"
}
},
"fail_reason": "電子郵件格式無效"
}
]
}
此代碼塊在浮窗中顯示
成功回應
| 欄位 | 類型 | 描述 |
|---|---|---|
| totalCount | int | 此次更新操作的記錄總數 |
| success_count | int | 成功更新的記錄數量 |
| fail_count | int | 更新失敗的記錄數量 |
| fail_detail | array | 更新失敗的詳細資訊 |
| upsert_data | array | 此次失敗更新操作的請求資料 |
| fail_reason | array | 更新失敗的原因 |
錯誤回應
| 欄位 | 類型 | 描述 |
|---|---|---|
| code | int | 錯誤代碼 |
| message | string | 錯誤訊息描述 |
錯誤代碼
| 錯誤代碼 | 訊息 |
|---|---|
| 40000 | 無效參數 |
| 50000 | 系統內部錯誤 |
| 403106 | 找不到表格 |
| 403131 | 無權存取該表格 |
