maverickosama92
maverickosama92

Reputation: 2725

How to set contentful.js api call rateLimit

I have following code:

contentfulMgmt.createClient({
                accessToken: sourceSpace.accessCode,
                rateLimit: 1,
                secure: true,
                retryOnTooManyRequests: true,
                maxRetries: 5
            });

How to set api call rate?

I have seen it in their github project but i am unable to make it work.

For ref:

rate-limit: https://github.com/contentful/contentful-management.js/blob/master/lib/rate-limit.js

contentful-management: https://github.com/contentful/contentful-management.js

They have added index.js file in the project but how to use it. Kindly help.

Please help. Thanks

Upvotes: 1

Views: 1990

Answers (1)

trodrigues
trodrigues

Reputation: 1457

All you should need to do is to specify the rateLimit property. That property defines maximum amount of requests per second the library will try to send. The default value is 6, and you probably won't want to go much higher than 10.

Be aware however, that the server also limits the amount of requests per second and per hour, so if you set that number too high you might start getting a 429 error from the server.

The library will try to recover from that by default (retryOnTooManyRequests). If all the max retries are exhausted then you've probably reached your rate limit per hour.

Upvotes: 2

Related Questions