Sending mutliple SMS and avoiding Request rate exceeded

  • 1
  • Question
  • Updated 2 years ago
I'm working with my coder on a script for sending SMS.  It is server-based and no user interaction.  The PHP script is performing the Authorization Code Flow and getting a token for the instance each time the script is called (/restapi/oauth/token).  This appears to not be the preferred method as there is a limit of "5 requests / 60 secs".  So if we attempt to send more than 5 SMS requests in a 60 second period, we are getting rejected with "Request rate exceeded", I believe because the multiple token requests. 

What is a better way to code this to avoid the Rate request exceeded error response?  We do not have a way to multithread or internally cache the token information.  

We also are not using the PHP SDK.  When I looked at it, the documentation in the middle/bottom of the page is pretty sparce ( on how it works and if this would resolve the issue.  If calling $sdk->platform()->loggedIn(); each instance the script is called, what is returned?  Does it returns that we are still logged in (authenticated) and we can continue forward with the SMS, thereby avoiding the token calls that trigger the "Request rate exceeded" error?
Photo of Ryan Ryan

Ryan Ryan

  • 174 Points 100 badge 2x thumb

Posted 2 years ago

  • 1
Photo of AK

AK, Official Rep

  • 4,412 Points 4k badge 2x thumb

The better approach would be to locally cache the tokens once you authorize and use it to send sms.

Session Variables

Once you Login using the below SDK method
you could store the token information into a session variable ( $_SESSION['sessionAccessToken'] ) and re-use this token to set the auth data on the auth object as

Cache Locally

With this approach, you would instead store the tokens locally in a file or a cache implementation and re-use the same to set the auth data and make the API call to send SMS

One of the publicly available libraries which you could use is :
is used to check if the platform instance is loggedIn ( would return `true` if the accessToken is valid ) which would serve as the initial entry check to make sure the platform object is active ( as the tokens are valid ) and you could then use it to make any API calls, SMS in your case.