1

I am using Microsoft Graph API to read emails (/users/{id | userPrincipalName}/messages) in the mailboxes of the users in my Azure active directory. I have noticed that for some users, I get this error:

HTTP error: 404
Error code: MailboxNotEnabledForRESTAPI or MailboxNotSupportedForRESTAPI
Error message: REST API is not yet supported for this mailbox.

Upon investigation, I found out that these users do not have a valid license and also don't have a mailbox attached to them. Ideally, I would like to only fetch the users that have a mailbox enabled. I tried checking the assignedLicenses property of each user and only fetch emails for those users that have a valid license assigned to them but, I'm not sure if this is a reliable method as users might have some other license and still not have a mailbox enabled.

Can someone please suggest a straightforward way to only fetch the users that have mailboxes attached? Any help or hint shall be highly appreciated.

Marry35
  • 387
  • 4
  • 16
  • I don't see much options from Microsoft Graph perspective. Being said that closest one i remember is that you may need to use mailboxsettings API call of the user. This way you can get and update the mailbox settings of the user. If nothing works, you can user Get-mailbox Exchange Powershell commandlet to validate the same. – Dev Feb 02 '21 at 18:22
  • Adding the above info, links in the below answer - as it supports formatting & let me to use the hyperlinks. Test it out and see if it helps. – Dev Feb 02 '21 at 18:23

1 Answers1

0

I don't see much options from Microsoft Graph perspective. Definitely checking the license is one good way, but you may not have much options with that. Being said that i see the following options,

Dev
  • 2,428
  • 2
  • 14
  • 15
  • Dev, thanks for your answer. Have you looked at the assignedLicenses property (https://learn.microsoft.com/en-us/graph/api/resources/user?view=graph-rest-1.0#properties) present in User's data. I'm noticing that it is an empty array for users who don't have license. Can I trust that a user that has a license will always have a mailbox and vice versa? – Marry35 Feb 02 '21 at 18:37
  • Yes i looked at the property, but the problem is whatif the given user has the license assigned and no mailbox exist (say, a service account without any mailbox). Hence i suggested the above two options. Being said that if you found anything related share it here - so it can be useful to others as well. – Dev Feb 02 '21 at 18:41