Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Jun 28, 2021 08:15 AM
I create a basic javascript web app with some ajax javascript call using the api.
I try to get all the records from a table but the response show me only 100 records.
Can someone give me an example for solving this problem?
I use maxRecords and the offset functions but i’m not understand how i have to use that.
Thank you.
Jun 28, 2021 10:59 AM
Welcome to the Airtable community.
You can only retrieve a maximum of 100 records per call with the REST API.
In order to get more records, you must use additional api calls with pagination. If you want to get all the records, you should not set maxRecords, because that limits the total number of records you will get (even with pagination).
Are you using the official js client, or forming your requests manually? What does your code currently look like? How are you submitting the offset in your requests?
From the api documentation:
Jun 29, 2021 06:21 AM
Actually i create this code using the ajax calls into a javascript file. I give you this example:
function test(){
var event = $('#getEventID').val();
$.ajax({
url: "https://api.airtable.com/v0/"+baseid+"/"+tablename+"?filterByFormula=idevento="+event+"&api_key="+apikey,
success: function(response){
var total = response['records'][0]['fields']['totale'];
nextFunction(idevento, total);
}
});
}
Can you help me and show how do you see all the records from the tables with this type of code?!
Thank you
Jun 29, 2021 08:20 AM
Your current call includes two query parameters: filterByFormula
and api_key
.
If you get an offset
from the first call, you need to make another call that also includes the offset from the previous call.
By the way, I find that fetch
is much easier to use than ajax
.
Jul 01, 2021 06:27 AM
Can you make an example with my source code for using the offset parameter? which date i have to pass into the second call. How i can use the fetch method? Thank you.
Jul 01, 2021 07:02 AM
If you would like to hire me to write code for you, feel free to book a meeting.
You do not pass a date. You pass the offset received from the previous call.
Google JavaScript fetch
to see examples.
Jun 03, 2023 01:37 AM
After Searching like hell on the Internet for weeks I could,t find a proper and correct solution for this even Airtable Community did not give proper answers so I did some experiment myself and found out the solution.
const url = `https://api.airtable.com/v0/BaseId/Tablename?api_key=xxxxxxxx`;
const getData = async () => {
const api = await fetch(url);
let allRecords = [];
const data = await api.json();
allRecords.push(data.records);
let offset = data.offset;
if (offset !== undefined) {
do {
const api1 = await fetch(url + "&offset=" + offset);
const response = await api1.json();
allRecords.push(response.records);
offset = response.offset;
} while (offset !== undefined);
}
allRecords = allRecords.flat();
console.log(allRecords);
};