Help

Re: Show more than 100 records with API calls using JavaScript (ajax)

3871 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Francesco_Rossi
4 - Data Explorer
4 - Data Explorer

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.

6 Replies 6

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:

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

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.

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.

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.

pratik16
4 - Data Explorer
4 - Data Explorer

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

 

Hope so it Helps....