I'm attempting to use the Intercom API to close an array of conversations that match a certain criteria. I am using Axios to first call their API to get an array of conversation ID's, then I am looping over those ID's and calling their API to close them. According to their documentation they are limited by the following:
Although the permitted limit of requests lasts for 1 minute, we evenly distribute this into 10 second windows. This means that every 10 seconds, the amount of permitted requests resets. For example, a default rate limit of 1000 per minute means that you can send a maximum of 166 operations per 10 second period (1000/6)
I attempted to use P-Limit and that did allow for more successful requests before eventually getting a 429. Is there a good solution to throttle the requests to match the criteria they have set in their documentation?
This was was my attempt so far using PLimit - For the sake of brevity I left out the code block for the first promise:
const listOfConversations = [];
axios
.post(searchUrl, searchBodyParameters, config)
.then((response) => {...
.then(() => {
const promises = [];
listOfConversations.forEach((conversation) => {
const p = axios
.post(
`https://api.intercom.io/conversations/${conversation}/parts`,
closeBodyParameters,
config,
)
.catch((error) => {
console.log(
`Error. Failed to close conversations. Server Returned - ${error.response.status}`,
);
});
promises.push(limit(() => p));
});
})
.catch((error) => {
console.log(
`Error. Failed to get number of pages. Server Returned - ${error.response.status}`,
);
});