logo
开发者文档
搜索
更新表数据

更新表数据

可以通过该接口,批量更新 Agent 数据表中的指定目标记录的值,最大支持更新 100 条记录。

注意
更新时整个 JSON 请求体(request body)的大小限制为 5MB。
每个请求最多更新 100 条记录。

请求方式

POST

调用地址

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 Key
Content-Type application/json 数据类型,取值为 application/json。

请求体

字段 类型 必填 描述
table_id string 表id。
update_data list 更新的数据集合。
record_id string record id 与 filter 条件二选一,推荐使用 record_id 。
filter map 用户自定义过滤条件(必须使用自定义唯一主键字段)。
is_creat bool 指定目标记录不存在时,是否创建新记录。
updated_fields list 更新的数据集合。

record_id 与 filter 条件必须二选一,推荐使用 record_id 。当两者都传入时,以 record_id 为准。
is_create 默认值为 false ,当未传入 is_create 时,默认不自动创建新记录。

响应

响应示例

{ "totalCount": 4, "success_count": 2, "fail_count": 2, "fail_detail": [ { "upsert_data": { "record_id": "123456", "value": { "name": "测试用户", "email": "invalid_email" } }, "fail_reason": "邮箱格式不正确" }, { "upsert_data": { "filter": { "id": "789" }, "value": { "name": "测试用户", "email": "invalid_email" } }, "fail_reason": "邮箱格式不正确" } ] }
                      
                      {
    "totalCount": 4,
    "success_count": 2,
    "fail_count": 2,
    "fail_detail": [
        {
            "upsert_data": {
                "record_id": "123456",
                "value": {
                    "name": "测试用户",
                    "email": "invalid_email"
                }
            },
            "fail_reason": "邮箱格式不正确"
        },
        {
            "upsert_data": {
                "filter": {
                    "id": "789"
                },
                "value": {
                    "name": "测试用户",
                    "email": "invalid_email"
                }
            },
            "fail_reason": "邮箱格式不正确"
        }
    ]
}

                    
此代码块在浮窗中显示

成功响应

字段 类型 描述
totalCount int 本次更新任务的数据总行数
success_count string 已成功更新的行数
fail_count string 更新失败的行数
fail_detail array 更新失败的详细原因。
upsert_data array 该行更新的请求数据
fail_reason array 该行更新失败的原因

失败响应

字段 类型 描述
code int 错误码。
message string 错误描述信息

错误码

Code Message
40000 参数错误
50000 系统内部错误
403106 未找到表
403131 无权访问数据表