What is an API rate limit?
API rate limits are used to control the amount of traffic that can be sent to and received from an API in a given period of time. Rate limits are designed to protect the API from being overloaded by too many requests at once. API rate limits can also help to prevent abuse or misuse of the API by limiting the number of requests that can be made within a certain time frame.
What are the rate limits of Totango API?
100 requests per minute. (The HTTP API as well as its Javascript wrapper are not limited.)
What happens when you reach the limit?
You will get this response from our API:
HTTP/1.1 429 Too Many Requests
RateLimit-Limit - 100 (the top limit)
RateLimit-Remaining - 0 (requests remaining) //returns on all api calls
RateLimit-Reset - 37 (Seconds until the counter is reseted)
Content-Type: application/json
Content-Length: 85
body: "Too many requests"
In this example, the server is indicating that the client has made too many requests and needs to wait before sending additional requests. The Retry-After header specifies the number of seconds the client should wait before trying again. In this case, the value is set to 60 seconds (1 minute). The body of the response includes a JSON object that provides additional information about the error.
Examples of how to use the API with the rate limit in mind (Javascript)
const sleep = ms => new Promise(r => setTimeout(r, ms));
async function getAllAccountData() {
const allAccounts = await fetchListOfAllAccounts();
for (let i = 0; i < allAccounts.length; i++) {
await fetchAllAccountUsersFromTheTotangoAPI(allAccounts[i].id)
await sleep(500)
}
}
Code explanation
The getAllAccountData
function is fetching and processing data from the Totango API in a controlled and sequential manner. The sleep
function is used to add a delay between API requests, which can help prevent reaching the API rate limit. Alternatively you could look at the response and if a too many requests response is received then utilize the Rate-Limit reset value as the basis for your sleep command.