office365outlook-restapioffice365-restapi

Choosing between the UpnName and SmtpAddress for the X-AnchorMailbox header when using Office 365 REST API


We use the Outlook REST API with Azure AD authentication to access mailboxes of our users. The documentation recommends the use of the x-AnchorMailbox header to optimize performance :

For optimal performance when using the new Outlook REST endpoint, add an x-AnchorMailbox header for every request and set it to the user's email address. For example: x-AnchorMailbox:john@contoso.com

For a given user, should we use the primary SMTP Address (which may change) or the UPN Name for this purpose ?

There are various code samples using these techniques (like this), however it uses an EmailAddress, which can be ambiguous.


Solution

  • You should be setting this to the EmailAddress property of the user (obtained from the /Me endpoint of the API.