Skip to main content
The First Step
Dec 10, 2019 10:39 AM UTC
Question

C# SDK - Get X-Rate-Limit headers from response

Using the RingCentral.Net SDK - how do retrieve the X-Rate-Limit-* headers from the responses ?

    10 replies

    The First Step
    Dec 10, 2019 12:32 PM UTC
    PhongVu
    Community Manager
    Community Manager
    Dec 10, 2019 3:58 PM UTC

    Using the RingCentral .Net SDK, you can check API limit header as shown below:

    static RestClient rcsdk;
    
    static void Main(string[] args)
    {
      rcsdk = new RestClient(RINGCENTRAL_CLIENTID, RINGCENTRAL_CLIENTSECRET, RINGCENTRAL_PRODUCTION);
      rcsdk.Authorize(RINGCENTRAL_USERNAME, RINGCENTRAL_EXTENSION, RINGCENTRAL_PASSWORD).Wait();
      rcsdk.AfterHttpCall += EventHandler;
    }
    static void EventHandler(object sender, HttpCallEventArgs eventArgs)
    {
      var rateLimitRemaining = eventArgs.httpResponseMessage.Headers.First(i => i.Key == "X-Rate-Limit-Remaining").Value.First();
      Console.WriteLine("Remaining: " + rateLimitRemaining);
    }
    The First Step
    Apr 29, 2021 10:09 PM UTC

    Hi Phong Vu,

    I don't see AfterHttpCall in my ringcentral DLL. (Assembly RingCentral.Net, Version=1.0.0.0)

    I am using Nuget Packaage.


    Am I missing something...

    PhongVu
    Community Manager
    Community Manager
    Apr 30, 2021 6:42 PM UTC

    What version of the RingCentral .NET SDK do you use?

    The First Step
    May 12, 2021 8:16 PM UTC

    This does not work in RingCentral.net SDK version 5.2. The AfterHTTPCall event does not exist.

    PhongVu
    Community Manager
    Community Manager
    May 12, 2021 9:26 PM UTC

    RingCentral .NET SDK 5.x has major changes and there are many source breaks. It supports SDK extensions mechanism. And to catch the events, create and install the EventsExtension as shown below:

    RestClient rcsdk = new RestClient(RC_CLIENTID, RC_CLIENTSECRET, RC_PRODUCTION);
    rcsdk.Authorize(RC_USERNAME, RC_EXTENSION, RC_PASSWORD).Wait();
    var eventsExtension = new EventsExtension();
    rcsdk.InstallExtension(eventsExtension).Wait();
    eventsExtension.RequestSuccess += EventHandler;
    ...
    static void EventHandler(object sender, HttpMessages httpMessages)
    {
        var rateLimitRemaining = httpMessages.httpResponseMessage.Headers.First(i => i.Key == "X-Rate-Limit-Remaining").Value.First();
        Console.WriteLine("Remaining: " + rateLimitRemaining);
    }
    The First Step
    May 12, 2021 10:01 PM UTC

    I will try this and report back.

    The First Step
    Sep 30, 2021 6:27 PM UTC
    1. var eventsExtension = new EventsExtension();

    What do I have to do to make it work for EventsExtension as I am getting an error to create a namespace for it. Do I have to install some package from Nuget?

    What do you mean by "create and install the EventsExtension as shown below: ". Can you clarify this?

    The First Step
    Sep 30, 2021 6:38 PM UTC
    The First Step
    Sep 30, 2021 7:27 PM UTC

    I will try this and report back. Thank you for quick reply.