Skip to main content

获取记录

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

示例 1:获取指定维格表下指定视图中的所有记录#

假设你有一张维格表,你想获取「维格视图」中的所有记录。

记录相关操作 - 示例维格表

你的操作步骤如下:

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

  2. 获取该维格表的 ID(获取方法)和「维格视图」的 ID(获取方法)。

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

    注意:通过 cURL 发送查询请求时,需要使用 encodeURIComponent() 函数对查询参数的值进行转义编码。

    curl -X GET \"https://api.vika.cn/fusion/v1/datasheets/dstWUHwzTHd2YQaXEE/records?viewId=viw4mnkqkaqdh" \-H "Authorization: Bearer {你的 API Token}"
  4. 服务器会返回下列 JSON 数据包,records 下即为符合条件的记录:

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

    {    "code": 200,     "success": true,     "data": {        "total": 3,         "pageNum": 1,         "pageSize": 3,         "records": [            {                "recordId": "recZbXSB2tPs2",                 "createdAt": 1626251202000,                 "updatedAt": 1626251202000,                 "fields": {                    "登记日期": 1600161240000,                     "性别": "男孩",                     "年龄": "5岁",                     "昵称": "安安",                     "拍照": [                        {                            "id": "atc10wTOBmAFt",                             "name": "vika_占位图_panda.jpg",                             "size": 15566,                             "mimeType": "image/jpeg",                             "token": "space/2021/02/04/5f6f489049ac44838457047cfb742898",                             "width": 400,                             "height": 400,                             "url": "https://s1.vika.cn/space/2021/02/04/5f6f489049ac44838457047cfb742898"                        }                    ],                     "肩高": "65厘米",                     "胸围": "87厘米",                     "体长": "1.2米",                     "体重(公斤)": 80                }            },             {                "recordId": "recQGtqpxAYDz",                 "createdAt": 1626251202000,                 "updatedAt": 1626251202000,                 "fields": {                    "登记日期": 1600161240000,                     "性别": "女孩",                     "年龄": "7岁",                     "昵称": "晓晓",                     "拍照": [                        {                            "id": "atc10wTOBmAFt",                             "name": "vika_占位图_panda.jpg",                             "size": 15566,                             "mimeType": "image/jpeg",                             "token": "space/2021/02/04/5f6f489049ac44838457047cfb742898",                             "width": 400,                             "height": 400,                             "url": "https://s1.vika.cn/space/2021/02/04/5f6f489049ac44838457047cfb742898"                        }                    ],                     "肩高": "71厘米",                     "胸围": "87厘米",                     "体长": "1.52米",                     "体重(公斤)": 110                }            },             {                "recordId": "recn8jWaDUwf5",                 "createdAt": 1626251202000,                 "updatedAt": 1626251202000,                 "fields": {                    "登记日期": 1600161240000,                     "性别": "女孩",                     "年龄": "6岁",                     "昵称": "佳佳",                     "拍照": [                        {                            "id": "atc10wTOBmAFt",                             "name": "vika_占位图_panda.jpg",                             "size": 15566,                             "mimeType": "image/jpeg",                             "token": "space/2021/02/04/5f6f489049ac44838457047cfb742898",                             "width": 400,                             "height": 400,                             "url": "https://s1.vika.cn/space/2021/02/04/5f6f489049ac44838457047cfb742898"                        }                    ],                     "肩高": "66厘米",                     "胸围": "89厘米",                     "体长": "1.4米",                     "体重(公斤)": 88                }            }        ]    },     "message": "SUCCESS"}

示例 2:指定返回记录里要包含的字段#

假设你有一张维格表,你想获取其中的所有记录,且这些记录仅包含「昵称」「年龄」两个字段。

记录相关操作 - 示例维格表

你的操作步骤如下:

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

  2. 获取该维格表的 ID(获取方法)和「昵称」「年龄」两个字段的 ID(获取方法)。

  3. 打开你电脑上的终端,执行下列代码,向服务器发送查询请求(假设 datasheetId 为 dstWUHwzTHd2YQaXEE,「昵称」「年龄」两个字段的 fieldId 分别为 fldY2RQCZ1ycCfldBmgui8bhNt):

    注意:通过 cURL 发送查询请求时,需要使用 encodeURIComponent() 函数对查询参数的值进行转义编码。

    # 编码前的查询,仅为演示用,直接执行可能会报错“[fields]的值不正确”curl -X GET \"https://api.vika.cn/fusion/v1/datasheets/dstWUHwzTHd2YQaXEE/records?fields[]=昵称&fields[]=年龄" \-H "Authorization: Bearer {你的 API Token}"
    # 编码后的查询,可以直接执行curl -X GET \"https://api.vika.cn/fusion/v1/datasheets/dstWUHwzTHd2YQaXEE/records?fields%5B%5D%3D%E6%98%B5%E7%A7%B0%26fields%5B%5D%3D%E5%B9%B4%E9%BE%84" \-H "Authorization: Bearer {你的 API Token}"
  4. 服务器会返回下列 JSON 数据包,records 下即为符合条件的记录:

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

    {    "code": 200,     "success": true,     "data": {        "total": 3,         "pageNum": 1,         "pageSize": 3,         "records": [            {                "recordId": "recZbXSB2tPs2",                 "createdAt": 1626251202000,                 "updatedAt": 1626251202000,                 "fields": {                    "fldWooy3c3Puz": "安安",                     "fldEAr5y7Go5S": "5岁"                }            },             {                "recordId": "recQGtqpxAYDz",                 "createdAt": 1626251202000,                 "updatedAt": 1626251202000,                 "fields": {                    "fldWooy3c3Puz": "晓晓",                     "fldEAr5y7Go5S": "7岁"                }            },             {                "recordId": "recn8jWaDUwf5",                 "createdAt": 1626251202000,                 "updatedAt": 1626251202000,                 "fields": {                    "fldWooy3c3Puz": "佳佳",                     "fldEAr5y7Go5S": "6岁"                }            }        ]    },     "message": "SUCCESS"}

示例 3:获取指定筛选条件和指定数量的记录,并自定义排序#

假设你有一张维格表,你想要筛选出「主要卖点」包含「真空」或「保温」这两个关键词的 3 件商品,并且按照促销价由高到低排序。

记录相关操作 - 示例维格表 2

这里需要用到两个查询参数:

  • filterByFormula:值为 OR(find("真空", {主要卖点}) > 0, find("保温", {主要卖点}) > 0)
  • maxRecords:值为 3
  • sort:值为 {"field": "促销价", "order": "desc"}

查询参数的详细说明见 API 手册「获取记录」

你的操作步骤如下:

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

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

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

    注意:通过 cURL 发送查询请求时,需要使用 encodeURIComponent() 函数对查询参数的值进行转义编码。

    # 编码前的查询,仅为演示用,直接执行可能会报错“[fields]的值不正确”curl -X GET \'https://api.vika.cn/fusion/v1/datasheets/dstNrmvismEKLSMn2Q/records?filterByFormula=OR(find("真空", {主要卖点}) > 0, find("保温", {主要卖点}) > 0)&maxRecords=3&sort={"field": "促销价", "order": "desc"}' \-H "Authorization: Bearer {你的 API Token}"
    # 编码后的查询,可以直接执行curl -X GET \"https://api.vika.cn/fusion/v1/datasheets/dstNrmvismEKLSMn2Q/records?filterByFormula=OR(find(%22%E7%9C%9F%E7%A9%BA%22%2C%20%7B%E4%B8%BB%E8%A6%81%E5%8D%96%E7%82%B9%7D)%20%3E%200%2C%20find(%22%E4%BF%9D%E6%B8%A9%22%2C%20%7B%E4%B8%BB%E8%A6%81%E5%8D%96%E7%82%B9%7D)%20%3E%200)&maxRecords=3&sort=%7B%22field%22%3A%20%22%E4%BF%83%E9%94%80%E4%BB%B7%22%2C%20%22order%22%3A%20%22desc%22%7D" \-H "Authorization: Bearer {你的 API Token}"
  4. 服务器会返回下列 JSON 数据包,records 下即为符合条件的记录:

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

    {    "code": 200,     "success": true,     "data": {        "total": 3,         "pageNum": 1,         "pageSize": 3,         "records": [            {                "recordId": "recdj7n9GOa3v",                 "createdAt": 1626251202000,                 "updatedAt": 1626251202000,                 "fields": {                    "摘要": "一机多用,轻量杯体设计,一键自动清洗",                     "分类": "料理机",                     "原价": 399,                     "促销价": 399,                     "入库时间": 1626251202420,                     "标题": "破壁料理机(小Q)",                     "配图": [                        {                            "id": "atc5a9cOIOYCy",                             "name": "vika_占位图_商品配图.png",                             "size": 11026,                             "mimeType": "image/png",                             "token": "space/2021/02/04/f1cbb62e1be34937880fb56da13ea5ee",                             "width": 400,                             "height": 400,                             "url": "https://s1.vika.cn/space/2021/02/04/f1cbb62e1be34937880fb56da13ea5ee"                        }                    ],                     "主要卖点": [                        "保温",                         "触摸式"                    ]                }            },             {                "recordId": "recX1UxK12bIo",                 "createdAt": 1626251202000,                 "updatedAt": 1626251202000,                 "fields": {                    "摘要": "八大功能,冷热双享,一键触控,多挡调温",                     "分类": "养生壶",                     "原价": 399,                     "促销价": 369,                     "入库时间": 1626251202420,                     "标题": "生活多功能冷热杯",                     "配图": [                        {                            "id": "atc5a9cOIOYCy",                             "name": "vika_占位图_商品配图.png",                             "size": 11026,                             "mimeType": "image/png",                             "token": "space/2021/02/04/f1cbb62e1be34937880fb56da13ea5ee",                             "width": 400,                             "height": 400,                             "url": "https://s1.vika.cn/space/2021/02/04/f1cbb62e1be34937880fb56da13ea5ee"                        }                    ],                     "主要卖点": [                        "高硼硅玻璃",                         "煮",                         "保温"                    ]                }            },             {                "recordId": "rectaGRaNuGYU",                 "createdAt": 1626251202000,                 "updatedAt": 1626251202000,                 "fields": {                    "摘要": "一键真空保鲜 单手开盖 特有分享杯",                     "分类": "新品上市",                     "原价": 299,                     "促销价": 239,                     "入库时间": 1626251202420,                     "标题": "无线真空便携榨汁杯",                     "配图": [                        {                            "id": "atc5a9cOIOYCy",                             "name": "vika_占位图_商品配图.png",                             "size": 11026,                             "mimeType": "image/png",                             "token": "space/2021/02/04/f1cbb62e1be34937880fb56da13ea5ee",                             "width": 400,                             "height": 400,                             "url": "https://s1.vika.cn/space/2021/02/04/f1cbb62e1be34937880fb56da13ea5ee"                        }                    ],                     "主要卖点": [                        "真空",                         "按键式"                    ]                }            }        ]    },     "message": "SUCCESS"}