Skip to main content
Question

C# How to determine if Rate Limit was exceeded immediately after xxxx.Sms().Post(msg) call

  • April 2, 2026
  • 5 replies
  • 58 views

Hi, My code is in C#. It is a texting app.  I am assuming that after sending a single SMS message,  I should be able to determine if that single call exceeded the rate limit.  My call to send a SMS message is as follows:

 var resp = await restClient.Restapi().Account().Extension().Sms().Post(requestBody);

Once control returns from the await, how do I obtain the info on whether the rate limit was exceeded?  Is an exception thrown?  Is there a return structure?  Do I have to make another call to read the RateLmit results of above Sms.Post() ?

A C# example to get the Rate Limit info of the above call would be very helpful.

Thank you,

Jim

 

5 replies

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • April 2, 2026

Add this to your code and try it out

var eventsExtension = new EventsExtension();

await restClient.InstallExtension(eventsExtension);

void EventHandler(object sender, HttpMessages httpMessages)
{
httpMessages.Headers.First(i => i.Key == "X-Rate-Limit-Remaining").Value.First();
Console.WriteLine("Remaining: " + rateLimitRemaining);
}

eventsExtension.RequestSuccess += EventHandler;

Or use the rate limit extension directly

https://github.com/ringcentral/RingCentral.Net/tree/master/RingCentral.Net.RateLimit

For more rate limit headers, check out this article.


Thank you.  When I try to use either below, the compiler doesn’t recognize the class or the method.  Am I missing a using statement ?

new EventsExtension();
restClient.InstallExtension

PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • April 6, 2026

Sorry for the quick answer without details and with some mistakes.

You need to install the Events extension package RingCentral.Net.Events. Then add the lib to your code

using RingCentral.Net.Events;

// Then this correct code

var eventsExtension = new EventsExtension();
await restClient.InstallExtension(eventsExtension);

void EventHandler(object sender, HttpMessages httpMessages)
{
String rateLimitRemaining = httpMessages.httpResponseMessage.Headers.First(i => i.Key == "X-Rate-Limit-Remaining").Value.First();
Console.WriteLine("Remaining: " + rateLimitRemaining);
}

eventsExtension.RequestSuccess += EventHandler;

 


Thank you.  I have try/catch blocks around my REST calls.  Before I was aware of this EventHandler Extension,  one of the blocks was catching the 429 error. I was unable to pin point which one, because it is difficult to make a 429 error occur, so I can not test at will.

If this Event Handler is installed, will my other try/catch blocks catch the 429 Error,  or will it only propagate to the newly installed EventHandler Extension?

Also,  what is the c# code to determine which call invoked the EventHandler Extension?  When I look at the structure of the return,  I can sort of get a hint of who called it,  but nothing specific.

Thanks again,

JFA


PhongVu
Community Manager
Forum|alt.badge.img
  • Community Manager
  • April 8, 2026

Thank you.  I have try/catch blocks around my REST calls.  Before I was aware of this EventHandler Extension,  one of the blocks was catching the 429 error. I was unable to pin point which one, because it is difficult to make a 429 error occur, so I can not test at will.

If this Event Handler is installed, will my other try/catch blocks catch the 429 Error,  or will it only propagate to the newly installed EventHandler Extension?

Also,  what is the c# code to determine which call invoked the EventHandler Extension?  When I look at the structure of the return,  I can sort of get a hint of who called it,  but nothing specific.

Thanks again,

JFA

Please open and explore the httpMessages.httpRequestMessage object to find more. I think the event is fired even the API call hits the 429 error.

I recommend you to explore all the extensions and particularly the RateLimit extension.


https://github.com/ringcentral/RingCentral.Net/tree/master?tab=readme-ov-file#extensions