How do I access retry-after for paging? RRS feed

  • Question

  • I have this code and it is working but have trouble with throttling since some apps have a lot of sign-ins. My goal is to get total sign in for a particular app.

    var authenticationProvider = new MsalAuthenticationProvider(cca, scopes.ToArray());           

    GraphServiceClient graphClient = new GraphServiceClient(authenticationProvider);           

    graphClient = new GraphServiceClient(authenticationProvider);

    var task = Task.Run(async () => await _graphClient.AuditLogs.SignIns.Request().Filter("appDisplayName eq 'MyApp'").GetAsync());
    if (!task.IsCompleted)

    var retrievedUser = task.Result;

    //then do looping

    while (retrievedUser.count > 0) {

    if (retrievedUser.NextPageRequest != null) {

    //do something


                        while (!task.IsCompleted)
                        retrievedUser = task.Result;

    // do more stuff

    Now, if x anount of time I run, it breaks because I get the throttling. So, the value is ok if I don't hit the limit.

    Now, if I do hit throttling, is there a way I can ask my app to stop and wait? I know in articles that you can get retry-after, but i have check the content and header and couldn't find it. I read that you need to use RetryHandler. I have no clue how to use it.

    Any sugguestions? Thanks in advance.

    Wednesday, February 19, 2020 7:56 AM

All replies

  • @M Nor Azmil,

    When you implement your app's error handling, use the HTTP error code 429 to detect the need for client-side throttling. If the request fails again with an HTTP 429 error code, you are still encountering an Azure service limit. Continue to use the recommended client-side throttling method, retrying the request until it succeeds.

    Below is the code that implements exponential backoff:

    Retry =
                Delay= TimeSpan.FromSeconds(2),
                MaxDelay = TimeSpan.FromSeconds(16),
                MaxRetries = 5,
                Mode = RetryMode.Exponential

    On HTTP error code 429, your client will use an exponential backoff approach:

    Wait 1 second, retry request
    If still throttled wait 2 seconds, retry request
    If still throttled wait 4 seconds, retry request
    If still throttled wait 8 seconds, retry request
    If still throttled wait 16 seconds, retry request

    At this point, you should not be getting HTTP 429 response codes.


    Please "accept as answer" or "vote as helpful" wherever the information provided helps you to help others in the community.


    We're migrating from MSDN to Microsoft Q&A as our new forums and Azure Active Directory has already made the move!  In future, you can ask and look for the discussion for Azure Active Directory related questions here:    https://docs.microsoft.com/answers/topics/azure-active-directory.html.

    Monday, February 24, 2020 5:12 AM