APIs & Integrations

VPatil3
メンバー

Hubspot API rate limit in nodejs

Hello,

 

I am implementing hubspot api rate limit policy in nodejs using cisco node/rate-limiter module. I am using some reference code and there is configuration file like this

{
"name":"RATE_LIMIT_OAUTH2_ENDPOINT",
"description":"Prevents DOS attacks on /oauth-callback",
"match":[
{
"type":"endpoint",
"url":"/oauth-callback"
}
],
"action":[
{
"type":"rate",
"permits":1000,
"interval":"1m"
}
]
}
 
and in app.js the rate limiter module used like below
app.use(rateLimiter.RateLimit.middleware);
 
Here I am not able to understand, how can I specify permits and interval in above cofiguration file for below hubspot policy for both burst and Daily
Burst:100/10 seconds and
Daily: 250,000
 
Please help
 
Thanks
0 いいね!
2件の返信
Teun
名誉エキスパート | Diamond Partner
名誉エキスパート | Diamond Partner

Hubspot API rate limit in nodejs

@VPatil3 ,

 

HubSpot also returns the daily limits in the header of each response, so you could try to dynamically set the token values based on the response you get. Check this doc regarding the response you get when making API calls. 



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.


Teun
名誉エキスパート | Diamond Partner
名誉エキスパート | Diamond Partner

Hubspot API rate limit in nodejs

Hi @VPatil3 ,

 

I do not know about node/rate-limiter, but I use rate-limiter-flexible myself for the burst limit, and it works great. I can show you how I have set it up. I have the below code in my main app file and pass the limiter variable to all functions that make an API call to HubSpot:

 

const { RateLimiterMemory, RateLimiterQueue } = require('rate-limiter-flexible');

// Set this a little lower to be on the safe side.
const burstOptions = {
  points: 100, // Requests
  duration: 10 // Seconds
}

// Set this a little lower to be on the safe side.
const dailyOptions = {
  points: 250000, // Requests
  duration: 5184000 // Seconds
}

// Initiate ratelimiter
const burstLimiter = new RateLimiterMemory(burstOptions)
const dailyLimiter = new RateLimiterMemory(dailyOptions)

const burstLimits = new RateLimiterQueue(burstLimiter)
const dailyLimits = new RateLimiterQueue(dailyLimiter)

await randomAPICall(burstLimits, dailyLimits)

 

So in a function that calls the API, you can do something like this:

 

const randomAPICall = async (burstLimits, dailyLimits) => {
  const remainingBurstTokens = await burstLimits.removeTokens(1)
  const remainingDailyTokens = await dailyLimits.removeTokens(1)

  return axios({
    method: 'get',
    url: ''
  }).then((response) => {
  }).catch((error) => {
  })
}

 

If you use async await in your functions, the node package will pause all next calls until you have new tokens available.



Learn more about HubSpot by following me on LinkedIn or YouTube

Did my answer solve your issue? Help the community by marking it as the solution.