-1

I have around 3 Millions users in a csv file, And I am trying to create them in Azure AD B2C using graph API using PowerShell cmdlets (Not SDK) I want to create them in azure ad b2c and at the time also need to record the accepted and rejected users from b2c Steps I followed in PowerShell Script :

  1. Importing CSV using Import-CSV
  2. Creating a Synchronized Arraylist for storing Accepted users
  3. Creating a Synchronized Arraylist for storing Rejecting users
  4. Creating Batch requests (20 at a time) using Batching in Graph API
  5. Calling graph API for each batch using for-each object -parallel -Throttlelimit 100
  6. For each request checking the status code for Accepted and Error and adding the user to respective Arraylist 7.Exporting the Arraylists as CSV

But while following these steps the Microsoft graph API is throwing throttling issues

Can anyone guide me how to handle throttling in this scenario ? or is there any other alternative to achieve this?

1 Answers1

0

Please check the references .

Best practices to handle throttling

When you implement error handling, use the HTTP error code 429 or the code 424 when batch itself fails with (Failed Dependency) to detect throttling. The failed response includes the Retry-After response header.

Backing off requests using the Retry-After delay is the fastest way to recover from throttling because Microsoft Graph continues to log resource usage while a client is being throttled.

  1. Wait the number of seconds specified in the Retry-After header.
  2. Retry the request. If it is throttling due to batch,you may retry all the failed requests in a new batch after the longest retry-after value.
  3. If the request fails again with a 429 /424 error code, you are still being throttled. Continue to use the recommended Retry-After delay and retry the request until it succeeds.

Graph-Powershell

ex:

foreach($Response in $BatchResponse.responses){                        
                        if([Int32]$Response.status -eq 201){
                            //...success logic
                        }else{
                            $rptObject.ErrorCount++
                            $rptObject.Errors += $Response.status
                            if([Int32]$Response.status -eq 429){
                                $rptObject.ThrottleCount++                               
                                if(!$TimeOutServed){
                                    Write-Verbose($Response.Headers.'Retry-After')
                                    Write-Verbose("Serving Throttling Timeout " + $Response.Headers.'Retry-After')
                                    Start-sleep -Seconds $Response.Headers.'Retry-After'
                                    $TimeOutServed = $true
                                }
      }

References :

  1. Microsoft Graph throttling guidance - Microsoft Graph | Microsoft Docs
  2. Does the Microsoft Graph SDK for .NET automatically handle rate limits? - Stack Overflow
  3. (github.com) microsoftgraph powershell issues
kavyaS
  • 8,026
  • 1
  • 7
  • 19