What's a 429 Too Many Requests' error
An HTTP Error 429 "Too Many Requests" mean that you have sent too many request in a short period of time to the same API.
Most APIs have "rate limiting" to prevent users to request too much their API and cause some deny of service.
That's happened to your code if you request many APIs inside a loop or in parallel.
How to fix this error
The first thing is to look for the rate limit inside the vendor's API documentation. If you don't find this information, you can start with a value of 30 request per minute and adapt it to a higher or lower value.
Then, you can use the bottleneck NPM package to limit the number send to a connector.
Here is an example with Airtable, limited to 5 requests per second:
This code use the Airtable list connector to retrieve a list of entries and then, for each entry, I send a new request to get more detailed information.
If you have for example 200 entries inside my Airtable, this code will generate 201 requests in a short amount of time, breaking the Airtable's rate limit.
So the first to do is adding the
bottleneck dependency inside my Spell. You can refer to this guide on adding a dependency:
Then, according to bottleneck's documentation, I need to define and configure a new
This limiter has been configured to wait at least 200ms between each request, limiting them to 5 requests per seconds max.
Next, I need to "surround" each of our connector with bottleneck's
schedule function to "wait" if a request is trigger in less than 200ms.
Now, our two connector will share the same limiter and the
schedule function will ensure to never overpass the 5 requests per second limit.
Bottleneck package have many additional settings you can find on their documentation