I have an application that makes use of Microsoft Graph API and I am trying to check API's usage and further informations such as quota limits, billing, etc. How can I get these kind of information?
Calculation of the Microsoft Graph's quota limit is very complicated. For example, a single query to return a list of users could take X resources. Another query for the apps in your tenants (assume you have the same number of apps as users) could take 2X resources because in the background, AAD is collecting information from multiple places to represent the application.
This is just a made up example, but the take away is that there is no easy way for you to get a clearly defined "quota" limit from services like the Microsoft Graph. Not to mention that quota and throttle limits can change somewhat dynamically depending on the tenant being accessed (1K user tenant vs 100K user tenant), the APIs you are accessing (Outlook may have a different throttling behavior than SharePoint), etc...
Instead, you should build into your application the ability to handle the clear errors returned to you once you have hit such a limit, and re-ping the endpoint using the suggested time-frames and methods.
All of this is documented here: Microsoft Graph throttling guidance
What happens when throttling occurs?
When throttling occurs, Microsoft Graph returns HTTP status code 429 (Too many requests), and the requests fail. A suggested wait time is returned in the response header of the failed request.
Best practices to handle throttling
When you implement error handling, use the HTTP error code 429 to detect throttling. The failed response includes the Retry-After field in the 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.
Wait the number of seconds specified in the Retry-After field.
Retry the request.
If the request fails again with a 429 error code, you are still being throttled. Continue to use the recommended Retry-After delay and retry the request until it succeeds.
You should also take a look here: Microsoft Throttling Pattern
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With