Search code examples
shortcutairtable

How to filter records by using Airtable API in Shortcuts app


In Shortcuts app, I can't filter the records with the 'fields' parameter in the Airtable.

Firstly, I can list the records with the 'maxRecords' parameter in following URL in the Shortcuts app successfully.

https://api.airtable.com/v0/<Base>/<Table>?maxRecords=3

However, if I use the 'fields' parameter, and change the URL as below.I get the following error messages. I have read the API documentation for several times, but just can't figure it out.

https://api.airtable.com/v0/<Base>/<Table>?fields=['Name']

{"error":{"type":"INVALID_REQUEST_UNKNOWN","message":"Invalid request: parameter validation failed. Check your request data."}}

Solution

  • Representing lists in URL parameters is a little odd. There are several different ways to manage this but none of them involve using common array notation.

    The Airtable API expects the fields parameter to be represented as fields[]=value where you repeat that argument for each field you want returned. For example, if I want to receive the fields "Name" and "Other Name" from my records, I would do:

    https://api.airtable.com/v0/YOUR_BASE_ID/YOUR_TABLE_NAME?fields[]=Name&fields[]=Other+Name

    You can also use the Airtable API Encoder on Codepen to validate that you are encoding your data correctly.