Skip to main content

Get Records

This text provides an example of how to call Get records interface.

Example 1: Get all records in the specified view under the specified datasheet

Suppose you have a datasheet, and you want to get all the records in the "Grid View".

Log action - Example datasheet

Your action steps below:

  1. Get your API Token.(How to get it)

  2. Get the dastasheet ID(How to get it) and 'Grid view' ID(How to get it).

  3. Open the terminal on your computer, execute the following code and send the query request to the server (assuming datasheetId is dstWUHwzTH2YQaXEE, viewId is viw4mnkqkaqdh):

    Note: When sending query requests via cURL, the encodeURIComponent() function is required to escape the values of the query parameters.

    curl -X GET \
    "https://aitable.ai/fusion/v1/datasheets/dstWUHwzTHd2YQaXEE/records?viewId=viw4mnkqkaqdh" \
    -H "Authorization: Bearer {Your API Token}"
  4. The server returns the JSON data below which records are required under records:

    For the meaning of each parameter in the response, please check the API Reference

        {
    "code": 200,
    "success": true,
    "data": {
    "total": 3,
    "pageNum": 1,
    "pageSize": 3,
    "records": [
    {
    "recordId": "reciVgKCRJhCd",
    "createdAt": 1659459289000,
    "uploadedAt": 1659459933000,
    "fields": {
    "features": [
    "gluttonous",
    "sleepy",
    "lively"
    ],
    "create time": 1659459289490,
    "health check date": [
    1659283200000,
    1661961600000
    ],
    "health check": [
    "reczjPnU9tTkJ",
    "rec1fXsdmjOOD"
    ],
    "photo": [
    {
    "id": "atcEuF1pgKFSm",
    "name": "image_1.jpeg",
    "size": 1684539,
    "mimeType": "image/jpeg",
    "token": "space/2022/08/03/831b7a8ebda84d16abc5006f38d29483",
    "width": 2592,
    "height": 3872,
    "url": "https://s1.aitable.ai/space/2022/08/03/831b7a8ebda84d16abc5006f38d29483"
    }
    ],
    "body_length": 1.2,
    "creator": {
    "id": "defa8eadd75648cca0a0125c2f9445c9",
    "unitId": "*********",
    "name": "Yang Weiming",
    "avatar": "https://s1.aitable.ai/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    },
    "age": "5 years old",
    "nickname": "An An",
    "guardian": [
    {
    "id": "1395644188512026652",
    "unitId": "*********",
    "type": "Member",
    "name": "Yang Weiming",
    "avatar": "https://s1.aitable.ai/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    }
    ],
    "weight": 90,
    "chest": 87,
    "gender": "boy",
    "registered or not": true
    }
    },
    {
    "recordId": "rec5oAO1IwVmB",
    "createdAt": 1659459289000,
    "uploadedAt": 1659460724000,
    "fields": {
    "features": [
    "obedient",
    "lively"
    ],
    "create time": 1659459289490,
    "health check date": [
    1659283200000,
    1661961600000
    ],
    "health check": [
    "recaXVhw4AoAx",
    "reccOYxRDPHdA"
    ],
    "photo": [
    {
    "id": "atcuMRSi1Bztg",
    "name": "image_2.jpeg",
    "size": 1684539,
    "mimeType": "image/jpeg",
    "token": "space/2022/08/03/831b7a8ebda84d16abc5006f38d29483",
    "width": 2592,
    "height": 3872,
    "url": "https://s1.aitable.ai/space/2022/08/03/831b7a8ebda84d16abc5006f38d29483"
    }
    ],
    "body_length": 1.52,
    "creator": {
    "id": "defa8eadd75648cca0a0125c2f9445c9",
    "unitId": "*********",
    "name": "Yang Weiming",
    "avatar": "https://s1.aitable.ai/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    },
    "age": "7 years old",
    "nickname": "Xiaoxiao",
    "guardian": [
    {
    "id": "1395644188512026652",
    "unitId": "*********",
    "type": "Member",
    "name": "Yang Weiming",
    "avatar": "https://s1.aitable.ai/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    }
    ],
    "weight": 110,
    "chest": 71,
    "gender": "girl",
    "registered or not": true
    }
    },
    {
    "recordId": "recqNslHPuU13",
    "createdAt": 1659459289000,
    "uploadedAt": 1659459941000,
    "fields": {
    "features": [
    "sleepy",
    "quiet"
    ],
    "create time": 1659459289490,
    "health check date": [
    1659283200000,
    1661961600000
    ],
    "health check": [
    "rec0kjjE3WkwK",
    "reca7dxHhe237"
    ],
    "photo": [
    {
    "id": "atcGT6nF7yPXb",
    "name": "image_3.jpeg",
    "size": 1684539,
    "mimeType": "image/jpeg",
    "token": "space/2022/08/03/831b7a8ebda84d16abc5006f38d29483",
    "width": 2592,
    "height": 3872,
    "url": "https://s1.aitable.ai/space/2022/08/03/831b7a8ebda84d16abc5006f38d29483"
    }
    ],
    "body_length": 1.4,
    "creator": {
    "id": "defa8eadd75648cca0a0125c2f9445c9",
    "unitId": "*********",
    "name": "Yang Weiming",
    "avatar": "https://s1.aitable.ai/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    },
    "age": "6 years old",
    "nickname": "Jiajia",
    "guardian": [
    {
    "id": "1395644188512026652",
    "unitId": "*********",
    "type": "Member",
    "name": "Yang Weiming",
    "avatar": "https://s1.aitable.ai/space/2020/09/11/e4d073b1fa674bc884a8c194e9248ecf"
    }
    ],
    "weight": 88,
    "chest": 66,
    "gender": "girl",
    "registered or not": true
    }
    }
    ]
    },
    "message": "SUCCESS"
    }

Example 2: specifies the fields to be included in the record returned

Assuming you have a datasheet you want to get all of these records and these records contain only two fields of nickname 'age'.

Log action - Example datasheet

Your action steps below:

  1. Get your API Token.(How to get it)

  2. Gets the ID (How to get it) and Nickname for both fields (How to get it).

  3. Open the terminal on your computer, execute the following code and send the query request to the server (assuming dstWUHwzTH2YQaXEEE, dstWUHwzTH2YQaXEE,field id for 'nickname' fields fldY2RQCZ1ycC and fldBmgui8bhNt):

    Note: When sending query requests via cURL, the encodeURIComponent() function is required to escape the values of the query parameters.

    # Query before encoding, for demonstration purposes only, direct execution may report an error "[fields] value is incorrect"
    curl -X GET \
    "https://aitable.ai/fusion/v1/datasheets/dstWUHwzTHd2YQaXEE/records?fields=nickname,age" \
    -H "Authorization: Bearer {Your API Token}"

    # The encoded query can be executed directly
    curl -X GET \
    "https://aitable.ai/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 {Your API Token}"
    ```py from apitable import Apitable

    apitable = Apitable("Your API Token") dst = apitable.datasheet("dstWUHwzTHd2YQaXEE") records = dst.records.all(fields=["nickname", "age"]) for record in records: print(record.json())


    The `all` method supports passing in multiple parameters to customize the returned recordset.

    The supported parameters are consistent with the query parameters in [API Reference "Get Records"](/api/reference#operation/get-records).
  4. The server returns the following JSON packets, records are eligible under records:

    For the meaning of each parameter in the response, please check the API Reference

        {
    "code": 200,
    "success": true,
    "data": {
    "total": 3,
    "pageNum": 1,
    "pageSize": 3,
    "records": [
    {
    "recordId": "reciVgKCRJhCd",
    "createdAt": 1659459289000,
    "updatedAt": 1659459933000,
    "fields": {
    "nickname": "An An",
    "age": "5 years old"
    }
    },
    {
    "recordId": "rec5oAO1IwVmB",
    "createdAt": 1659459289000,
    "updatedAt": 1659460724000,
    "fields": {
    "nickname": "Xiao Xiao",
    "age": "7 years old"
    }
    },
    {
    "recordId": "recqNslHPuU13",
    "createdAt": 1659459289000,
    "updatedAt": 1659459941000,
    "fields": {
    "nickname": "Jia Jia",
    "age": "6 years old"
    }
    }
    ]
    },
    "message": "SUCCESS"
    }

Example 3: Gets a record of the specified filters and quantities, and customize the sort

Suppose you have a datasheet, you want to filter out 3 products whose "main selling points" contains the keywords "Vacuum" or "Thermal isulation", and sort them by promotional price from high to low.

Log action - Example datasheet2

Two query parameters are required here:

  • filterByFormula: value is OR(find("Vacuum", {main selling point}) > 0, find("Thermal insulation", {main selling point}) > 0)
  • maxRecords: value is 3
  • sort: value is {"field": "promotion price", "order": "desc"}

For a detailed description of the query parameters, see API Handbook "Get Records"

Your action steps below:

  1. Get your API Token.(How to get it)

  2. Get datasheet Id (How to get it).

  3. Open the terminal on your computer, execute the following code and send the query request to the server (assuming datasheetId is dstNrmvismEKLSMn2Q):

    Note: When sending query requests via cURL, the encodeURIComponent() function is required to escape the values of the query parameters.

    curl -X GET \
    'https://aitable.ai/fusion/v1/datasheets/dstNrmvismEKLSMn2Q/records?filterByFormula=OR(find("Vacuum", {main selling Points}) > 0, find("Thermal insulation", {main selling points}) > 0)&maxRecords=3&sort={"field": "promotion price", "order": "desc"}' \
    -H "Authorization: Bearer {Your API Token}"
  4. The server returns the following JSON packets, records are eligible under records:

    For the meaning of each parameter in the response, please check the API Reference

        {
    "code": 200,
    "success": true,
    "data": {
    "total": 3,
    "records": [
    {
    "recordId": "recX1UxK12bIo",
    "createdAt": 1671589943000,
    "updatedAt": 1671597856000,
    "fields": {
    "original price": 399,
    "promotion price": 369,
    "inbound time": 1671589943382,
    "title": "Life multifunctional cup",
    "picture": [
    {
    "id": "atcbGfpA2Jc6O",
    "name": "image.png",
    "size": 3539,
    "mimeType": "image/png",
    "token": "space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734",
    "width": 48,
    "height": 49,
    "url": "https://s1.aitable.ai/space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734"
    }
    ],
    "main selling points": [
    "High-borosilicate glass",
    "Cook",
    "Thermal insulation"
    ]
    }
    },
    {
    "recordId": "rectaGRaNuGYU",
    "createdAt": 1671589943000,
    "updatedAt": 1671597856000,
    "fields": {
    "original price": 299,
    "promotion price": 239,
    "inbound time": 1671589943382,
    "title": "Juice Cup",
    "picture": [
    {
    "id": "atcbGfpA2Jc6O",
    "name": "image.png",
    "size": 3539,
    "mimeType": "image/png",
    "token": "space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734",
    "width": 48,
    "height": 49,
    "url": "https://s1.aitable.ai/space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734"
    }
    ],
    "main selling points": [
    "Vacuum",
    "Push Button Type"
    ]
    }
    },
    {
    "recordId": "recZ9ZLTXVFPc",
    "createdAt": 1671589943000,
    "updatedAt": 1671597856000,
    "fields": {
    "original price": 149,
    "promotion price": 129,
    "inbound time": 1671589943382,
    "title": "Electric heating water cup",
    "picture": [
    {
    "id": "atcbGfpA2Jc6O",
    "name": "image.png",
    "size": 3539,
    "mimeType": "image/png",
    "token": "space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734",
    "width": 48,
    "height": 49,
    "url": "https://s1.aitable.ai/space/2022/12/21/085bb750ba3a4eccbaf68c74f8e92734"
    }
    ],
    "main selling points": [
    "Electric hot water bottle",
    "Thermal insulation"
    ]
    }
    }
    "pageSize": 3
    ],
    "pageNum": 1,
    },
    "message": "SUCCESS"
    }