Core concepts
Rate limits
Each secret key gets its own request budget. Back off on 429 using Retry-After.
Requests made with an API key are limited per key: by default, 600 requests per minute for each key. Integrations that share an outbound IP don't share a limit, and one key used from several servers shares its budget across them.
When you go over, Cartirra answers 429 Too Many Requests with:
{ "error": { "code": "rate_limited", "message": "Too many requests; slow down and retry", "request_id": "…" } }
and a Retry-After header with the number of seconds to wait.
Every response to a key also tells you where you stand:
| Header | Meaning |
|---|---|
X-RateLimit-Limit | Requests allowed in the window |
X-RateLimit-Remaining | Requests left in the current window |
X-RateLimit-Reset | Seconds until the window resets |
Handling 429
async function cartirra(path, init = {}, attempt = 0) {
const response = await fetch(`https://api.cartirra.com${path}`, {
...init,
headers: { Authorization: `Bearer ${process.env.CARTIRRA_SECRET_KEY}`, ...init.headers },
});
if (response.status === 429 && attempt < 5) {
const wait = Number(response.headers.get('Retry-After') ?? 1) * 1000;
await new Promise((resolve) => setTimeout(resolve, wait + Math.random() * 250));
return cartirra(path, init, attempt + 1);
}
return response;
}
Staying under the limit
- Use webhooks instead of polling for changes.
- Ask for up to 100 items a page when you sync lists.
- Cache things that rarely change, such as your stores.
- Spread bulk jobs out instead of firing everything at once.
If you need a higher limit, contact Cartirra support with your use case.