'PowerShell GraphAPI - Invoke-MgForwardUserMessage - Error: tooManyRetries
I am working on a PowerShell script that needs to forward emails that I get with the Graph API. I already have the Azure App Registration and necessary consents figured out and can get the emails via Get-MGuserMessage. The issue is when I call Invoke-MgForwardUserMessage that the script hangs for about 30 seconds then fails with: tooManyRetries ErrorCode. I am calling the function with the below code. Most of what is written below is some form of what the Microsoft docs say to write... Any ideas?
$userId is my ObjectID in Azure. $mail.Id is the GraphAPI gotten message "Id" field.
$params = @{
Message = @{
IsDeliveryReceiptRequested = $true
ToRecipients = @(
@{
EmailAddress = @{
Name = "Not Real Person"
Address = "[email protected]"
}
}
)
}
Comment = "Just want to make sure you get this."
}
Invoke-MgForwardUserMessage -UserId $userId -MessageId $mail.Id -BodyParameter $params
Solution 1:[1]
When the user sends too many requests within a short span of time, the 429 error occurs and if the user exceeds default service limits this error occurs.
Limit requests for resource (email) is 1 request per 15 minutes and 3 requests per 24 hours.
For email, the resource is a unique network message ID/recipient pair.
Initially try the Invoke-MgForwardUserMessage command in graph explorer and see if works and check all permissions to be granted for graph api to operate on email and then try in PowerShell.
To handle the throttling,
- Try reducing the number of operations per request.
- Try reducing the frequency of calls.
- Try avoiding immediate retries, because all requests against your usage limits.
Reference: Best practices to handle the throttling.
To resolve the issue, please try the below,
- If you know the error code and message, you can try to handle it after some time by using sleep.
- To detect throttling, use the HTTP error code
429or5010r503. - Check the number of seconds specified in the Retry-After response header and retry the request.Continue till it succeeds.
If still the issue exists, please check by including this sample code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RukminiMr-MT |
