Skip to main content

Get all records from table

  • January 12, 2022
  • 16 replies
  • 508 views

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);

16 replies

Forum|alt.badge.img+19
  • Inspiring
  • January 12, 2022

As is the case with every modern API, you need to make multiple calls to get all 500+ records. Look at the result set - you’ll see an attribute that can be used to make the next request for another 100 items.


  • Author
  • Known Participant
  • January 12, 2022

May i ask what is the attribute/code i need to add in order to get the remaining records? I’m stuck on this one. The const data has a multidimensional array which consist of
result > records > objects > the actual data i have to fetch


kuovonne
Forum|alt.badge.img+29
  • Brainy
  • January 12, 2022

It looks like you are using Scripting to access the REST API.
Are you trying to get records from a different base than the one where the script resides?


  • Author
  • Known Participant
  • January 13, 2022

It looks like you are using Scripting to access the REST API.
Are you trying to get records from a different base than the one where the script resides?


Yes, i’m trying to get records from different base to compare data from 1 base to another.


  • Author
  • Known Participant
  • January 13, 2022

@kuovonne @Bill.French

How can i fetch all the records from another base? I’m using the base 2 to update the columns from base 1. Is there any way for fetching all the records with or without the rest api?
Thank you :slightly_smiling_face:


Forum|alt.badge.img+19
  • Inspiring
  • January 13, 2022

May i ask what is the attribute/code i need to add in order to get the remaining records? I’m stuck on this one. The const data has a multidimensional array which consist of
result > records > objects > the actual data i have to fetch


I would take a look at this -


kuovonne
Forum|alt.badge.img+29
  • Brainy
  • January 13, 2022

Read the REST API documentation about pagination and rate limits. You can get a maximum of 100 records at a time. If there are over 100 records available you will get pagination info in the results. Keep querying until you no longer get the pagination token. But also make sure you do not exceed the rate limit of 5 requests per second or you will be temporarily locked out.


  • Author
  • Known Participant
  • January 13, 2022

I would take a look at this -


@Bill.French I will take a look and read this one.


  • Author
  • Known Participant
  • January 13, 2022

Read the REST API documentation about pagination and rate limits. You can get a maximum of 100 records at a time. If there are over 100 records available you will get pagination info in the results. Keep querying until you no longer get the pagination token. But also make sure you do not exceed the rate limit of 5 requests per second or you will be temporarily locked out.


@kuovonne is the pagination you are talking about is the offset inside the array?


kuovonne
Forum|alt.badge.img+29
  • Brainy
  • January 13, 2022

Yes, the pagination offset.


  • Author
  • Known Participant
  • January 17, 2022

Yes, the pagination offset.


@kuovonne i’ve read some of the articles that pagination offset can’t be access for now.


kuovonne
Forum|alt.badge.img+29
  • Brainy
  • January 17, 2022

@kuovonne i’ve read some of the articles that pagination offset can’t be access for now.


Could you post a link to the article?


  • Author
  • Known Participant
  • January 17, 2022

Could you post a link to the article?



kuovonne
Forum|alt.badge.img+29
  • Brainy
  • January 17, 2022

That article is several years old and refers to using a library. Just use the offset as described in the developer documentation.


  • Author
  • Known Participant
  • January 17, 2022

That article is several years old and refers to using a library. Just use the offset as described in the developer documentation.


Is there a code that i can use to fetch the url inside the function?


Forum|alt.badge.img+2
  • New Participant
  • December 30, 2023

Is there a code that i can use to fetch the url inside the function?


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;
}