Have you looked at the throttling guidance? Also, if you use our SDKs, there is built in middleware that will handle this for you; check out the documentation and the best practices shared in it.
Getting exception while fetching busy time from calendar. Microsoft.Graph.ServiceException: Code: tooManyRetries. exeptionType : System.AggregateException. Status Code: 0
When I am trying to fetch meetings from Calendar using Graph API I am getting exceptions randomly for multiple users
Code for fetching calendar events:
GraphServiceClient service = new GraphServiceClient(
new DelegateAuthenticationProvider(
async (request) =>
{
request.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", accessToken);
await Task.FromResult<string>(null);
}));
eventResult = await service.Users[connectedAccountEmailID].Calendars[calendarId].CalendarView.Request(options)
.Select("id,subject,organizer,start,end,attendees,showas,isallday,seriesmasterid")
.Header("Prefer", "IdType=\"ImmutableId\"")
.GetAsync();
The exception I am getting a few time for multiple users (daily up to 50-60 times approx)
exeptionType : System.AggregateException
Status Code: 0
Microsoft.Graph.ServiceException: Code: tooManyRetries
Message: More than 3 retries encountered while sending the request.
at Microsoft.Graph.HttpProvider.<SendRequestAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.HttpProvider.<SendAsync>d__18.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendRequestAsync>d__38.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.BaseRequest.<SendAsync>d__34`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Graph.CalendarCalendarViewCollectionRequest.<GetAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Service.Office365CalendarProviderService.<>c__DisplayClass44_0.<<GetCalendarMeetings>b__0>d.MoveNext()
I have checked the code and verified that we are not making any parallel calls at the same time but still getting throttled limit type exceptions.
I have checked the same through Graph Explorer and not getting this exception. Urgent help will be appreciated.
4 answers
Sort by: Most helpful
-
Deva-MSFT 2,256 Reputation points Microsoft Employee
2021-05-07T16:17:54.143+00:00 -
Mike Crowley 121 Reputation points
2022-09-25T17:07:15.043+00:00 @Harsh Vats , did you find a solution here?
@Deva-MSFT , I am having a similar error while using the SDK. It doesn't seem to handle the retries. In my case, I am only tying to do a single operation. I've tried both
Remove-MgUserMailFolder
andInvoke-MgGraphRequest
from the v1.12.0 of the PowerShell SDK.Remove-MgUserMailFolder -MailFolderId $MailFolderId -UserId $userid -debug
Response:
DEBUG: [CmdletBeginProcessing]: - Remove-MgUserMailFolder begin processing with parameterSet 'Delete1'. DEBUG: [Authentication]: - AuthType: 'AppOnly', AuthProviderType: 'ClientCredentialProvider', ContextScope: 'Process', AppName: 'MYAPP'. DEBUG: [Authentication]: - Scopes: [Mail.ReadWrite]. DEBUG: ============================ HTTP REQUEST ============================ HTTP Method: DELETE Absolute Uri: https://graph.microsoft.com/v1.0/users/UserJ%40example.com/mailFolders/AAMkADQ4YmFhZWYxLWE2OWMtNDg0JmMmU3OfakefakeGJhNAAuAAAAAACT_g6Qs8dkTa4jxSl4iG6yAQAAq1rPMXmaSITxu7W_t3CAAARyuQ0QAAA%3D Headers: Body: DEBUG: [CmdletException]: Received exception with message 'ServiceException - Code: tooManyRetries Message: More than 3 retries encountered while sending the request. : at Microsoft.Graph.RetryHandler.<SendRetryAsync>d__10.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.RetryHandler.<SendAsync>d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.CompressionHandler.<SendAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.AuthenticationHandler.<SendAsync>d__16.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.PowerShell.Mail.<UsersDeleteMailFolders1_Call>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Graph.PowerShell.Mail.<UsersDeleteMailFolders1_Call>d__19.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.PowerShell.Mail.<UsersDeleteMailFolders1>d__17.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.Graph.PowerShell.Cmdlets.RemoveMgUserMailFolder_Delete1.<ProcessRecordAsync>d__61.MoveNext()'
Error:
Remove-MgUserMailFolder : Code: tooManyRetries Message: More than 3 retries encountered while sending the request. At line:3 char:1 + Remove-MgUserMailFolder -MailFolderId $MailFolderId -UserI ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Remove-MgUserMailFolder_Delete1], ServiceException + FullyQualifiedErrorId : Microsoft.Graph.PowerShell.Cmdlets.RemoveMgUserMailFolder_Delete1 DEBUG: [CmdletEndProcessing]: - Remove-MgUserMailFolder end processing.
-
Mike Crowley 121 Reputation points
2022-09-27T14:57:40.817+00:00 Thinking the SDK cmdlets are hiding detail, I also tried using
Invoke-RestMethod
andInvoke-WebRequest
and got 503 errors.$MsalConnectParams = @{ ClientId = '660<redacted>4aed02' TenantId = '<redacted>' ClientCertificate = (Get-ChildItem Cert:\LocalMachine\my\8F<redacted>11) } $Token = Get-MsalToken @MsalConnectParams $Token $Header = @{ Authorization = "Bearer $($Token.accesstoken)" ConsistencyLevel = "Eventual" } #Define User $userid = '<redacted>' $FolderDisplayName = "MyFolder" #Find Folder Id $uri_base = "https://graph.microsoft.com/v1.0/" $uri_endpoint = "users/$UserId/mailFolders/" $uri_parameters = "?`$filter=displayName eq '$FolderDisplayName'&includeHiddenFolders=true&`$top=1000" $uri = ($uri_base + $uri_endpoint + $uri_parameters) $Response = Invoke-RestMethod -Headers $Header -Uri $uri $MailFolderId = $Response.value.id #Delete Folder $uri_parameters = "$MailFolderId" $uri = ($uri_base + $uri_endpoint + $uri_parameters) $Response = Invoke-RestMethod -Headers $Header -Uri $uri -Method Delete $Response
Invoke-RestMethod : The remote server returned an error: (503) Server Unavailable.
At line:2 char:13- $Response = Invoke-RestMethod -Headers $Header -Uri $uri -Method Dele ...
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
- FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
$Response = Invoke-WebRequest -Headers $Header -Uri $uri -Method Delete -Debug $Response
Invoke-WebRequest : The remote server returned an error: (503) Server Unavailable.
IAt line:2 char:13- $Response = Invoke-WebRequest -Headers $Header -Uri $uri -Method Dele ...
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
- FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
- $Response = Invoke-RestMethod -Headers $Header -Uri $uri -Method Dele ...
-
Mike Crowley 121 Reputation points
2022-09-27T15:05:11.38+00:00 I posted here as well, in case its something with the API.
tooManyRetries / (503) Server Unavailable #18652
https://github.com/microsoftgraph/microsoft-graph-docs/issues/18652