Rate Limit Slack API Calculation

141 Views Asked by At

I am using the library bottleneck to assist in rate limiting requests with the Slack SCIM API.

Here is a page that defines the Slack SCIM rate limits.

I don't know if I calculated/interpreted the values I am passing to bottleneck correctly to not exceed the rate limit when creating a user (180 request per minute, 20 burst requests). Here is the code:

const createUser = async (token, user) => {
      const url = `https://api.slack.com/scim/v1/Users`;      
      const data = {
        schemas: ['urn:scim:schemas:core:1.0'],
        userName: user.username
        emails: [
          {
            value: user.email
            type: 'work',
            primary: true
          }
        ]
      };
      if(user.fullName && user.fullName.length > 1) data.displayName = user.fullName
      const postConfig = {
        headers: { Authorization: `Bearer ${token}` },
        method: 'POST'
      };
      return await axios.post(url, data, postConfig);
    }

    const wrapper = new Bottleneck({
      minTime: 6000/180,
      maxConcurrent: 20
    })

    const createUserRateLimited = wrapper(createUser);

minTime since the api allows 180 requests in 1 minute, the 6000/180 converts this to milliseconds (ms).

maxConcurrent should map to the amount of concurrent aka burst requests, the api says there can be a 20 burst per minute.

This has been fairly difficult to test (if anybody has suggestions on how to test this that would also be appreciated). Currently, I am making mock users in a loop and hitting the endpoint to test and see if I get any type of rate limit 429 errors.

Am I mapping the Slack API rate limits correctly to the bottleneck library?

0

There are 0 best solutions below