I can successfully retrieve records by using views with Google Apps Script, but I’m struggling to incorporate a filter using filterByFormula when querying Airtable. I’m looking to build a precise query that filters records based on specific criteria within my script. I need clear guidance on constructing the proper URL and parameter setup to ensure the filter is applied correctly in my code. Below is an example code snippet using different function names and variable identifiers:
function applyAirtableFilter() {
var myApiKey = 'YOUR_API_KEY';
var baseId = 'YOUR_BASE_ID';
var tableName = 'ExampleTable';
var endpoint = "https://api.airtable.com/v0/" + baseId + "/" + tableName;
var queryParams = "?filterByFormula=({Status}='active')&maxRecords=5";
var requestUrl = endpoint + queryParams;
var requestOptions = {
method: 'get',
headers: {
'Authorization': 'Bearer ' + myApiKey
}
};
var response = UrlFetchApp.fetch(requestUrl, requestOptions);
var data = JSON.parse(response.getContentText());
Logger.log(data.records);
}