跳到主要内容

获取记录

本文提供调用「获取记录」接口的操作示例,该接口支持搭载全新数据引擎的 Fusion API v3,能够提供提供更出色的性能以及更高效的 API 体验,详情请查看 Fusion API v3

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

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

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

你的操作步骤如下:

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

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

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

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

    curl -X GET \
    "https://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": "reciVgKCRJhCd",
    "createdAt": 1659459289000,
    "updatedAt": 1659459933000,
    "fields": {
    "特点": [
    "贪吃",
    "贪睡",
    "活泼"
    ],
    "创建时间": 1659459289490,
    "健康检查日期": [
    1659283200000,
    1661961600000
    ],
    "健康检查": [
    "reczjPnU9tTkJ",
    "rec1fXsdmjOOD"
    ],
    "照片": [
    {
    "id": "atcEuF1pgKFSm",
    "name": "image_1.jpeg",
    "size": 1684539,
    "mimeType": "image/jpeg",
    "token": "space/2022/08/03/831b7a8ebda84d16abc5006f38d29483",
    "width": 2592,
    "height": 3872,
    "url": "https://s4.vika.cn/space/2022/08/03/831b7a8ebda84d16abc5006f38d29483"
    }
    ],
    "体长": 1.2,
    "创建人": {
    "id": "defa8eadd75648cca0a0125c2f9445c9",
    "unitId": "*********",
    "name": "杨伟铭",
    "avatar": "https://s4.vika.cn/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    },
    "年龄": "5岁",
    "昵称": "安安",
    "监护人": [
    {
    "id": "1395644188512026652",
    "unitId": "*********",
    "type": "Member",
    "name": "杨伟铭",
    "avatar": "https://s4.vika.cn/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    }
    ],
    "体重": 90,
    "胸围": 87,
    "性别": "男孩",
    "是否登记": true
    }
    },
    {
    "recordId": "rec5oAO1IwVmB",
    "createdAt": 1659459289000,
    "updatedAt": 1659460724000,
    "fields": {
    "特点": [
    "听话",
    "活泼"
    ],
    "创建时间": 1659459289490,
    "健康检查日期": [
    1659283200000,
    1661961600000
    ],
    "健康检查": [
    "recaXVhw4AoAx",
    "reccOYxRDPHdA"
    ],
    "照片": [
    {
    "id": "atcuMRSi1Bztg",
    "name": "image_2.jpeg",
    "size": 1684539,
    "mimeType": "image/jpeg",
    "token": "space/2022/08/03/831b7a8ebda84d16abc5006f38d29483",
    "width": 2592,
    "height": 3872,
    "url": "https://s4.vika.cn/space/2022/08/03/831b7a8ebda84d16abc5006f38d29483"
    }
    ],
    "体长": 1.52,
    "创建人": {
    "id": "defa8eadd75648cca0a0125c2f9445c9",
    "unitId": "*********",
    "name": "杨伟铭",
    "avatar": "https://s4.vika.cn/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    },
    "年龄": "7岁",
    "昵称": "晓晓",
    "监护人": [
    {
    "id": "1395644188512026652",
    "unitId": "*********",
    "type": "Member",
    "name": "杨伟铭",
    "avatar": "https://s4.vika.cn/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    }
    ],
    "体重": 110,
    "胸围": 71,
    "性别": "女孩",
    "是否登记": true
    }
    },
    {
    "recordId": "recqNslHPuU13",
    "createdAt": 1659459289000,
    "updatedAt": 1659459941000,
    "fields": {
    "特点": [
    "贪睡",
    "安静"
    ],
    "创建时间": 1659459289490,
    "健康检查日期": [
    1659283200000,
    1661961600000
    ],
    "健康检查": [
    "rec0kjjE3WkwK",
    "reca7dxHhe237"
    ],
    "照片": [
    {
    "id": "atcGT6nF7yPXb",
    "name": "image_3.jpeg",
    "size": 1684539,
    "mimeType": "image/jpeg",
    "token": "space/2022/08/03/831b7a8ebda84d16abc5006f38d29483",
    "width": 2592,
    "height": 3872,
    "url": "https://s4.vika.cn/space/2022/08/03/831b7a8ebda84d16abc5006f38d29483"
    }
    ],
    "体长": 1.4,
    "创建人": {
    "id": "defa8eadd75648cca0a0125c2f9445c9",
    "unitId": "*********",
    "name": "杨伟铭",
    "avatar": "https://s4.vika.cn/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    },
    "年龄": "6岁",
    "昵称": "佳佳",
    "监护人": [
    {
    "id": "1395644188512026652",
    "unitId": "*********",
    "type": "Member",
    "name": "杨伟铭",
    "avatar": "https://s4.vika.cn/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    }
    ],
    "体重": 88,
    "胸围": 66,
    "性别": "女孩",
    "是否登记": true
    }
    }
    ]
    },
    "message": "SUCCESS"
    }

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

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

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

你的操作步骤如下:

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

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

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

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

    # 编码前的查询,仅为演示用,直接执行可能会报错“[fields]的值不正确”
    curl -X GET \
    "https://vika.cn/fusion/v1/datasheets/dstWUHwzTHd2YQaXEE/records?fields=昵称,年龄" \
    -H "Authorization: Bearer {你的 API Token}"

    # 编码后的查询,可以直接执行
    curl -X GET \
    "https://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": "reciVgKCRJhCd",
    "createdAt": 1659459289000,
    "updatedAt": 1659459933000,
    "fields": {
    "昵称": "安安",
    "年龄": "5岁"
    }
    },
    {
    "recordId": "rec5oAO1IwVmB",
    "createdAt": 1659459289000,
    "updatedAt": 1659460724000,
    "fields": {
    "昵称": "晓晓",
    "年龄": "7岁"
    }
    },
    {
    "recordId": "recqNslHPuU13",
    "createdAt": 1659459289000,
    "updatedAt": 1659459941000,
    "fields": {
    "昵称": "佳佳",
    "年龄": "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://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://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://s4.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://s4.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://s4.vika.cn/space/2021/02/04/f1cbb62e1be34937880fb56da13ea5ee"
    }
    ],
    "主要卖点": [
    "真空",
    "按键式"
    ]
    }
    }
    ]
    },
    "message": "SUCCESS"
    }