How to Manage User Accounts with the Microsoft Exchange Online Admin API
Managing user accounts is crucial for any organization. It ensures that employees have the right access to resources while keeping sensitive information secure. The Exchange Admin API makes this process easier and more efficient. With its powerful features, you can quickly create, update, or delete user accounts. Plus, it allows you to manage mailboxes effectively. This API streamlines your workflow and saves you time, so you can focus on what truly matters—your team.
Key Takeaways
The Exchange Admin API simplifies user account management, allowing you to create, update, and delete accounts efficiently.
Use OAuth 2.0 for secure API authentication. It protects user credentials by using access tokens instead of passwords.
Always secure your access tokens to prevent unauthorized access and potential data breaches.
Implement error handling strategies to address common issues like unauthorized access or bad requests effectively.
Be mindful of rate limits when using the API. Monitor your usage and consider batching requests to stay within limits.
7 Surprising Facts About Exchange Admin API
If you manage Exchange Online, the Exchange Admin API can change how you automate, secure, and monitor your environment. Here are seven surprising facts about the Exchange Admin API.
- It exposes mailbox management beyond Graph API. While Microsoft Graph covers many user and mailbox scenarios, the Exchange Admin API provides specialized endpoints for Exchange-specific configuration and management not available in Graph, making it the go-to for deep Exchange Online automation.
- Granular RBAC and admin consent are required. The API enforces Exchange-focused role-based access controls and often requires explicit admin consent for sensitive operations, so least-privilege scoping and dedicated service principals are essential for safe automation.
- Supports batch and bulk operations for scale. The Exchange Admin API allows batch-style and bulk management patterns (for example, updating policies across many mailboxes) which significantly reduces the number of calls and simplifies large-scale tenant management.
- Has tenant-level throttling and limits that differ from Graph. Throttling rules and request limits are distinct from Microsoft Graph; you must design retry and backoff logic specifically for Exchange Admin API behavior to avoid unexpected failures under load.
- Enables advanced compliance and auditing controls. The API surfaces Exchange-specific compliance features—such as mail flow rules, retention policy assignments, and auditing configurations—allowing programmatic enforcement of organizational policies at scale.
- Integrates with hybrid Exchange setups. For organizations in hybrid mode, the Exchange Admin API can be used alongside on-prem management tools to coordinate settings and policies, easing migration and coexistence scenarios.
- Can be extended with PowerShell and modern auth flows. You can combine Exchange Online PowerShell modules and the Exchange Admin API using OAuth 2.0 app-only authentication or delegated flows, enabling modern, secure automation while preserving legacy PowerShell capabilities when needed.
Use the Exchange Admin API to complement Microsoft Graph and PowerShell for robust, scalable, and secure Exchange Online management.
Authentication Methods

OAuth 2.0 Overview
When you work with the Exchange Admin API, understanding OAuth 2.0 is essential. This framework enhances security by allowing applications to access resources without exposing user credentials. Instead of sharing passwords, you use access tokens, which significantly reduces the risk of unauthorized access. Here are some key features of OAuth 2.0 that make it a robust choice for API authentication:
Feature | Description |
|---|---|
Token-based authorization reduces the risk of exposing user credentials and provides a more secure method for API access. | |
Granular Access Control | OAuth 2.0 enables fine-grained permission management through scopes, allowing organizations to control exactly what resources a client can access. |
Flexibility | The framework supports multiple authorization flows, accommodating various application types and deployment scenarios. |
Scalability | API gateways can efficiently handle token validation and management, supporting high-volume API traffic without compromising performance. |
Obtaining Access Tokens
To interact with the Exchange Admin API, you need to obtain access tokens. Here’s a simple step-by-step guide to help you through the process:
Register an app in Microsoft Entra ID.
Assign required API permissions.
Assign RBAC permissions.
Securing your access tokens is crucial. If tokens are not protected, they can lead to serious security risks. Here are some potential dangers of unsecured access tokens:
APIs can expose sensitive data if not secured properly.
Unsecured access tokens can lead to unauthorized access and manipulation of data.
The rise in API attacks highlights the need for robust security measures.
Moreover, if someone impersonates a Global Admin, they could gain full control over your tenant, including access to services like SharePoint Online and Exchange Online. This could lead to significant data breaches.
To assign Exchange Online RBAC roles to applications for API access, follow these steps:
For delegated scenarios, ensure the user has necessary RBAC roles assigned in Exchange Online, such as Recipient Management or Organization Management.
For app-only scenarios, assign Microsoft Entra roles or custom Exchange RBAC role groups to the service principal representing your app.
Use the appropriate OAuth 2.0 access token flow for your application type, either delegated or app-only.
Install Exchange Online PowerShell and connect to it.
Create a new service principal and assign the required roles.
Verify the role assignment and test RBAC for applications.
By following these guidelines, you can effectively manage user accounts while ensuring that your API interactions remain secure.
Managing User Accounts with the Exchange Admin API
Creating User Accounts
Creating user accounts with the Exchange Admin API is straightforward. You need to provide specific fields to set up a new user. Here’s a quick list of the required parameters:
Alias: This is the username for the account.
Name: The full name of the user.
FirstName: The user's first name.
LastName: The user's last name.
DisplayName: How the user’s name appears in the directory.
MicrosoftOnlineServicesID: The email address associated with the account.
Password: You’ll need to prompt for this input.
ResetPasswordOnNextLogon: This is optional but can be set to true if you want the user to change their password upon first login.
Here’s a simple example of how you might create a user account using PowerShell:
New-MgUser -AccountEnabled $true -DisplayName "Holly Holt" -MailNickname "hollyh" -UserPrincipalName "hollyh@corp.contoso.com" -PasswordProfile @{ForceChangePasswordNextSignIn=$true; Password="YourSecurePassword"}
Updating User Information
Updating user information is just as easy. You can modify various attributes of a user account through the Exchange Admin API. Here are some common attributes you might want to update:
Parameter | Description |
|---|---|
ModifiedObjectResolvedName | The user-friendly name of the modified object. |
ModifiedProperties | This includes the name of the modified property, its new value, and the previous value. |
ExternalAccess | Indicates if the command was run by an internal user or external personnel. |
To update a user, you can use a command like this:
Update-MgUser -UserId "<userId>" -DisplayName "Holly Holt Updated"
This command updates the display name of the user with the specified user ID.
Deleting User Accounts
When it comes to deleting user accounts, you need to follow a few steps to ensure everything goes smoothly. Here’s a quick guide:
Connect to your Microsoft 365 tenant using PowerShell with the required permissions.
Use the command
Connect-MgGraph -Scopes User.Read.All, User.ReadWrite.Allto establish the connection.Retrieve the user ID by filtering with the display name using
Get-MgUser -Filter "displayName eq '<display name>'".Remove the user account with the command
Remove-MgUser -UserId <userId> -Confirm:$false.
This process ensures that you can efficiently manage user accounts, keeping your organization secure and organized.
Fetching Mailboxes for Effective Management
Fetching mailboxes is crucial for effective user account management. Here are some best practices to keep in mind:
Always use POST for all operations, including Get-* cmdlets.
Include only parameters supported for the cmdlet in the endpoint.
Use X-AnchorMailbox for all operations to ensure requests are routed correctly.
Utilize
$selectto reduce response payload size, especially when dealing with large datasets.Combine
$selectwith pagination to manage extensive data efficiently.
By following these guidelines, you can streamline your mailbox management and ensure that your user accounts are always up to date.
Best Practices for the Exchange Admin API
Error Handling
When working with the Exchange Admin API, you might encounter errors. Knowing how to handle these errors effectively can save you time and frustration. Here’s a handy table that outlines common error codes, their causes, and suggested fixes:
Error Code | Cause | Fix |
|---|---|---|
401 Unauthorized | Missing, invalid, or expired OAuth token. Incorrect scope. | Ensure your app has the right scopes assigned. Acquire a new token if expired. Verify TenantID. |
403 Forbidden | Missing RBAC role or managing objects outside your scope. | Assign required RBAC roles. Confirm the object is within your management scope. |
400 Bad Request | Unsupported or incorrectly formatted parameter. | Check cmdlet details. Only include supported parameters. |
Wrong base URL | The wrong base URL for your environment. | Use the correct base URL for your organization. |
Pagination issues | Changing parameters between paged calls or ignoring @odata.nextLink. | Keep parameters consistent. Always POST to @odata.nextLink. |
Routing errors | Missing or incorrect X-AnchorMailbox header for mailbox-scoped ops. | Include X-AnchorMailbox with mailbox UPN or SMTP address. Validate the value. |
Resilience | Implement retry logic for throttling and log request IDs. | Validate parameters before sending requests to avoid 400 Bad Request. |
By following these strategies, you can minimize disruptions and keep your operations running smoothly.
Rate Limiting Considerations
Rate limiting is another important aspect to consider when using the Exchange Admin API. It helps maintain the performance of the API and ensures fair usage among all users. Here are some tips to keep in mind:
Understand the Limits: Familiarize yourself with the rate limits imposed by the API. This knowledge helps you plan your requests accordingly.
Implement Backoff Strategies: If you hit a rate limit, implement a backoff strategy. This means waiting a bit before retrying your request. It can prevent you from getting blocked.
Monitor Your Usage: Keep an eye on your API usage. Monitoring tools can help you track how many requests you make and when you approach the limits.
Batch Requests: If possible, batch your requests. This approach can reduce the number of calls you make and help you stay within the limits.
By being mindful of rate limiting, you can ensure that your interactions with the Exchange Admin API remain efficient and effective.
In summary, the Exchange Admin API is a powerful tool for managing user accounts effectively. You can create, update, and delete accounts with ease, ensuring your organization runs smoothly. Remember, securing your access tokens and understanding error handling are crucial for a seamless experience.
To dive deeper into the Exchange Admin API, consider these resources:
This article guides you on making your first successful call to the Exchange Online Admin API and explains key behaviors and patterns applicable across all endpoints.
So, don’t hesitate! Explore the API and see how it can enhance your user management processes. Happy coding! 🚀
FAQ
What is the Exchange Admin API?
The Exchange Admin API allows you to manage user accounts and mailboxes in Microsoft Exchange Online. It simplifies tasks like creating, updating, and deleting user accounts, making administration more efficient.
How do I authenticate with the Exchange Admin API?
You authenticate using OAuth 2.0. Register your app in Microsoft Entra ID, assign permissions, and obtain an access token to interact with the API securely.
Can I automate user account management?
Yes! You can automate user account management using scripts with PowerShell or other programming languages. This saves time and reduces manual errors in user administration.
What should I do if I encounter an error?
Check the error code and refer to the documentation for troubleshooting steps. Common issues include invalid tokens or missing permissions. Adjust your requests accordingly.
How can I monitor my API usage?
You can monitor your API usage by implementing logging in your application. Track the number of requests made and watch for any rate limit warnings to avoid disruptions.
What is the Exchange Admin API and how does it relate to Exchange Online?
The Exchange Admin API is a new rest-based administrative API Microsoft launched to enable exchange administrative tasks for Exchange Online and Office 365 Exchange Online. The admin api is a rest-based approach designed to help organizations modernize automation, offering admin api endpoints that perform a focused set of exchange cmdlets and parameters for common management scenarios previously handled with EWS or Exchange Online PowerShell.
Is the Exchange Admin API a replacement for Exchange Web Services (EWS)?
The new api is not a direct one-to-one replacement for all EWS scenarios, but it is intended to help organizations move away from EWS over time. Microsoft announced deprecation timelines and guidance such as deprecation in october 2026 for certain EWS scenarios; the admin api public preview and admin api in public preview provide rest api alternatives for many exchange admin scenarios and modernize automation.
Which admin tasks are supported by the admin api endpoints?
The api supports a limited set of Exchange Online administrative tasks focused on exchange management tasks like managing accepted domains, mailboxfolderpermission settings, delegate and permission assignments, and other exchange administrative tasks. The admin api is a rest-based administrative surface designed to enable common exchange admin scenarios and to enable scripting and REST-based automation alongside PowerShell cmdlets and powershell scripts.
How does this impact Office 365 and Office 365 Exchange Online administrators?
For Office 365 and Office 365 Exchange Online administrators, the preview of exchange provides a path to modernize with a rest api and reduce reliance on EWS code and exchange cmdlets. Administrators can use admin api endpoints or continue using Exchange Online PowerShell while Microsoft expands the available admin api public preview capabilities. This helps organizations migrate away from EWS and adopt modern automation that integrates with Microsoft 365 management workflows.
What about Exchange Online PowerShell and existing Powershell cmdlets—will they be removed?
Exchange Online PowerShell and powershell cmdlets remain a supported option for many tasks. The admin api aims to complement exchange cmdlets and parameters by offering a REST-based alternative for specific exchange admin scenarios. Microsoft has provided a preview of exchange admin api and guidance for using both powershell scripts and the admin api; some scenarios will continue to require Exchange Online PowerShell until admin api endpoints cover a broader subset of exchange functionality.
When will EWS be retired and what should organizations do before October 2026?
Microsoft signaled deprecation in october 2026 for certain EWS usages and encouraged organizations to plan to move away from EWS for specific exchange admin scenarios. Admins should inventory EWS code, EWS for specific exchange admin uses, and any EWS scenarios in their environment, then evaluate the admin api public preview, rest api alternatives, and Exchange Online PowerShell to modernize automation before the deprecation in october 2026.
Can the admin api manage mailbox permissions like mailboxfolderpermission and delegates?
Yes, the admin api supports managing mailboxfolderpermission and delegate assignments for many scenarios, providing endpoints that allow admins to set or modify delegate and permission settings. While the admin api may initially provide a limited set, it is designed to help organizations automate these specific exchange administrative tasks without relying solely on EWS code or exchange cmdlets.
How do I access the admin api in public preview and what authentication is required?
The admin api is available in public preview and requires modern authentication through Microsoft identity platform (Azure AD/Entra). Administrators register an app, grant appropriate scopes for Exchange Online API access, and call the rest-based admin api endpoints to perform exchange management. This approach enables integration with existing automation, scripts, and Microsoft 365 management frameworks.
Are there any limitations to the admin api during public preview?
During the admin api public preview the api may provide a limited set of capabilities compared to the full set of Exchange cmdlets or EWS. The preview focuses on appropriate exchange administrative tasks and a subset of exchange functions; organizations should validate admin scenarios and modernize automation by combining admin api endpoints with Exchange Online PowerShell where needed until the api supports more extensive exchange management tasks.
How should organizations plan their migration strategy from EWS to the new rest-based admin api?
Organizations should perform an overview of the exchange workloads that rely on EWS, identify specific exchange admin scenarios and EWS scenarios for specific exchange admin needs, and prioritize migrating high-impact automation to the admin api or Exchange Online PowerShell. Use the admin api public preview to test admin scenarios and modernize automation, update powershell scripts and EWS code where appropriate, and track Microsoft guidance on deprecation and future availability through october 2026 and beyond.








