Jan 12, 2022 01:26 AM
Hi, I’m trying to fetch all my table records that has a 500 columns inside but in this json result view it only fetch a random of 100 records in my existing table.
Here is my code. Thank you
//base1
const MY_API_KEY = “API_KEY”;
const AIRTABLE_BASE = “BASE_2”; //base 2
const results = await remoteFetchAsync(AIRTABLE_BASE+?api_key=${MY_API_KEY}
)
const data = await results.json()
// for(let view of data.fields){
// console.log(view);
// }
console.log(data);
Jan 13, 2022 05:21 AM
Yes, the pagination offset.
Jan 16, 2022 09:37 PM
@kuovonne i’ve read some of the articles that pagination offset can’t be access for now.
Jan 16, 2022 10:48 PM
Could you post a link to the article?
Jan 16, 2022 10:54 PM
Jan 16, 2022 10:59 PM
That article is several years old and refers to using a library. Just use the offset as described in the developer documentation.
Jan 16, 2022 11:36 PM
Is there a code that i can use to fetch the url inside the function?
Dec 29, 2023 05:07 PM
To fetch more than 100 records from Airtable using the Airtable API, you need to implement pagination. Airtable API returns a maximum of 100 records in a single request. If your base has more than 100 records, the API response will include an offset parameter. You can use this offset in the next API request to retrieve the next set of records.
Here's how you can fetch 1000 records (or all records if you're not sure of the total count) using Google Apps Script:
function fetchAllRecordsFromAirtable() {
const apiKey = 'YOUR_AIRTABLE_API_KEY';
const baseId = 'YOUR_BASE_ID';
const tableName = 'YOUR_TABLE_NAME';
const encodedTableName = encodeURIComponent(tableName);
const url = `https://api.airtable.com/v0/${baseId}/${encodedTableName}`;
const headers = {
'Authorization': 'Bearer ' + apiKey
};
let allRecords = [];
let offset = null;
do {
let apiUrl = url;
if (offset) {
apiUrl += '?offset=' + offset;
}
const options = {
'headers': headers,
'muteHttpExceptions': true
};
const response = UrlFetchApp.fetch(apiUrl, options);
const json = JSON.parse(response.getContentText());
const records = json.records;
allRecords = allRecords.concat(records);
offset = json.offset; // Airtable provides this in the response when there are more records
} while (offset);
return allRecords;
}