How to Work Around API Limits

I can only request 15 new record creations with a single API call.

// create a People-Holiday::Christmas record for each person in the People table
people.map(person => {
    peopleHolidaysTable.createRecordAsync({
        'Person' : [{id: `${person.id}`}],
        'Holiday' : [{id: 'reclZYRpInJiev0ce'}]
    });
});

I have 33 people in my array. I’m not terribly proficient with async programming in JS yet. What is the proper way to chunk this into 3 API calls of 15/15/3? I suspect I need to split it up into arrays of 15 and then have each call await the one previous with a timeout of 1000ms.

Anyone able to provide some guidance on how to do that?

Hi Jeremy,

We rate-limit blocks to 15 writes per second and batch methods allow modification of 50 records in one call. Your current code looks like it does a separate API call for each person, so you’re running into the 15 writes per second limit.

You could switch your code to use the batch createRecordsAsync instead of createRecordAsync to get around this. You could also do what you suggested (split the calls and await each previous one). The time it takes for the write to complete (while you await) should be long enough that you wouldn’t need to include an additional timeout.

For the first option, it’d look like this:

peopleHolidaysTable.createRecordsAsync(people.map(person => ...))

For the second option, we have an example on how to that in the “Size limits & rate limits” section of this guide: https://airtable.com/developers/blocks/guides/write-back-to-airtable as well as in the Wikipedia Enhancement example block: https://github.com/Airtable/blocks/blob/master/examples/wikipedia-enrichment-block/frontend/index.js#L117

Sorry for the late response, hope this is still helpful!

2 Likes

Very helpful — thank you, @Emma_Yeap!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.