Hi all!
I’m working on a script that grabs two fields from a table as query parameters in a API GET request, gets the resulting JSON data, and updates the records in the same table for those corresponding queries. I have my for loop running fine when I limit it to 50 records (notice the IF statement) and aware of the 50 record limitation by Airtable. How do I go about refining my script so that it grabs the remaining records? I’ve been banging my head against a wall on how to do this since Friday.
Here’s the script I have so far:
//Set table for Stage Data
let testTable = base.getTable("Test Table");
let stages = await testTable.selectRecordsAsync();
let recordsData = [];
//Testing for loop
for (let record of stages.records) {
let url = `https://apiwebsite?filter[account][customId]=${record.getCellValue("Query Param")}&filter[stage][id]=${record.getCellValue("Query Param")}`
if (recordsData.length < 50) {
let data = await fetch(url, {
method: 'GET',
headers: {"Authorization": `Bearer ${temp}`}
})
const results = await data.json();
let newRecord = { id: record.id, fields: {"Total Prospects": results.meta.count}};
console.log('newRecord', newRecord, record.id);
recordsData.push(newRecord);
}}
while (recordsData.length > 0) {
await testTable.updateRecordsAsync(recordsData.slice(0, 50));
recordsData = recordsData.slice(50);
}