Hi @Perssonify Dev
Thank you for posting your question in the Microsoft Q&A forum.
This is required setup for Outlook API Integration:
1/ Azure AD App Registration:
- Ensure your app is registered in Azure AD with the correct redirect URI and client secret.
- For personal Microsoft accounts, use the /common endpoint and enable multi-tenant access.
2/ Microsoft Graph API Permissions:
- Use delegated permissions like Mail.Read, Mail.ReadWrite, Mail.Send, and offline_access.
- For shared mailboxes, include Mail.Read.Shared and Mail.ReadWrite.Shared.
- Admin consent is required for high-privilege scopes like Mail.ReadWrite.All.
3/ Mailbox Licensing:
- Each user must have a Microsoft 365 license with Exchange Online.
- Without a mailbox, Graph API calls will fail even if permissions are correctly configured.
4/ Endpoint Usage:
- Use /me/messages for delegated tokens.
- Use /users/{id}/messages only with application permissions and client credentials flow.
5/ MSAL Configuration:
- Ensure scopes match those in Azure AD.
- Implement token refresh logic to avoid expired token errors.
For common causes of 401 Errors:
- Missing Exchange Online mailbox.
- Incorrect or missing OAuth scopes.
- Admin consent not granted for required permissions.
- Using the wrong endpoint for the token type.
- Guest or external account without mailbox access.
- Expired or misconfigured access token.
Based on your description, I recommend as below:
- Use Microsoft Graph Explorer or Postman to test API calls.
- Decode access tokens to verify scopes.
- Simplify scope requests to essential permissions.
- Consider application permissions for managing multiple users’ emails via client credentials flow.
By aligning your app configuration, permissions, and licensing with these guidelines, you should be able to resolve the 401 error and ensure smooth email management via the Outlook API.
Note: Please understand that our initial response does not always resolve the issue immediately. However, with your help and more detailed information, we can work together to find a solution. Your detailed response will help us diagnose and investigate the issue more efficiently. If I misunderstood what you’re looking for, feel free to let me know or share a screenshot. I’d be happy to help further!
Thank you for your cooperation. I'm looking forward for your reply.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.