跳到主要内容

创建记录

本文提供调用「创建记录」接口的操作示例。

示例:在指定维格表中创建两条新的记录

假设你有一张维格表,你想在其中创建两条新的记录。

提示

目前成员字段中的 id 属性可能会在后续停用,如创建/更新记录时需要填写成员字段,请使用 unitId 属性来添加成员

你的操作步骤如下:

  1. 获取你的 API Token。(获取方法

  2. 获取该维格表的 ID。(获取方法

  3. 打开你电脑上的终端,执行下列代码,向服务器发送查询请求(假设 datasheetId 为 dstWUHwzTHd2YQaXEE):

    curl -X POST \
    https://vika.cn/fusion/v1/datasheets/dstWUHwzTHd2YQaXEE/records \
    -H 'Authorization: Bearer {你的 API Token}' \
    -H 'Content-Type: application/json' \
    -d '{
    "records": [
    {
    "fields": {
    "体重": "80公斤",
    "肩高": "65厘米",
    "登记日期": "2020/09/15 17:14",
    "胸围": "87厘米",
    "体长": "1.2米",
    "拍照": [
    {
    "name": "image.png",
    "size": 207456,
    "mimeType": "image/png",
    "token": "space/2020/09/21/f577af8bd73f44c79dfc28408eaeff83",
    "width": 374,
    "height": 347
    }
    ],
    "登记员": [
    {
    "id": "1385370606558318594",
    "unitId": "*********",
    "name": "Coco",
    "type": "Member",
    "avatar": "https://s4.vika.cn/default/avatar004.jpg"
    }
    ],
    "性别": "男孩",
    "昵称": "安安",
    "年龄": "5岁"
    }
    },
    {
    "fields": {
    "体重": "88公斤",
    "肩高": "66厘米",
    "登记日期": "2020/09/15 17:14",
    "胸围": "89厘米",
    "体长": "1.4米",
    "拍照": [
    {
    "name": "image.png",
    "size": 395220,
    "mimeType": "image/png",
    "token": "space/2020/09/21/c42f476c01c24e8ca7908188d460f8f1",
    "width": 400,
    "height": 347
    }
    ],
    "登记员": [
    {
    "id": "1379641203598823425",
    "unitId": "*********",
    "type": "Member",
    "name": "Niko",
    "avatar": "https://s4.vika.cn/default/avatar003.jpg"
    }
    ],
    "性别": "女孩",
    "昵称": "佳佳",
    "年龄": "6岁"
    }
    }
    ]
    }'
  4. 服务器会返回下列 JSON 数据包,"records" 下即为新创建的记录数据:

    有关返回结果中各参数的含义,可查看 API 手册

    {
    "code": 200,
    "success": true,
    "data": {
    "records": [
    {
    "recordId": "reclxDBUBjQo6",
    "createdAt": 1600708683000,
    "fields": {
    "体重": "80公斤",
    "肩高": "65厘米",
    "登记日期": "2020/09/15 17:14",
    "胸围": "87厘米",
    "体长": "1.2米",
    "拍照": [
    {
    "id": "atcUJME9gbmFQ",
    "name": "1.png",
    "size": 207456,
    "mimeType": "image/png",
    "token": "space/2020/09/21/f577af8bd73f44c79dfc28408eaeff83",
    "width": 374,
    "height": 347,
    "url": "https://s4.vika.cn/space/2020/09/21/f577af8bd73f44c79dfc28408eaeff83"
    }
    ],
    "登记员": [
    {
    "id": "1286184164530659329",
    "unitId": "*********",
    "type": "Member",
    "name": "Bruce · K",
    "avatar": "https://s4.vika.cn/public/2020/08/03/574bcee4cfc54f6fbb7d686bb237f6f3"
    }
    ],
    "性别": "男孩",
    "年龄": "5岁"
    }
    },
    {
    "recordId": "reckuCT1F1Asn",
    "createdAt": 1600708683000,
    "fields": {
    "体重": "88公斤",
    "肩高": "66厘米",
    "登记日期": "2020/09/15 17:14",
    "胸围": "89厘米",
    "体长": "1.4米",
    "拍照": [
    {
    "id": "atcSvAn7wEBtJ",
    "name": "image.png",
    "size": 395220,
    "mimeType": "image/png",
    "token": "space/2020/09/21/c42f476c01c24e8ca7908188d460f8f1",
    "width": 400,
    "height": 347,
    "url": "https://s4.vika.cn/space/2020/09/21/c42f476c01c24e8ca7908188d460f8f1"
    }
    ],
    "登记员": [
    {
    "id": "1291258301781176321",
    "unitId": "*********",
    "type": "Member",
    "name": "小葵🌻",
    "avatar": "https://s4.vika.cn/public/2020/09/07/dbfe6ceccbdb4d5bbc1fd129566dea89"
    }
    ],
    "性别": "女孩",
    "年龄": "6岁"
    }
    }
    ]
    },
    "message": "SUCCESS"
    }