Adding alternate mail id from Microsoft Graph API

Viewed 2134

I am trying to add an alternate email with Microsoft Graph API from a.Net Core app.

The user class in Microsoft Graph does not provide a property for adding an additional mail id.

3 Answers

You can using Azure AD Graph to add the mail id to the otherMails. Here is sample to update the this property:

PATCH: https://graph.windows.net/{tenant}/me?api-version=1.6
authorization: bearer {access_token}

{
"otherMails":["test@test.com"]
}

Refer the links below for the user entity and update user REST:

Entity and complex type reference | Graph API reference

Update User

Here is the C# code to retrieve the alternate email

Select(u => new {
    u.DisplayName,
    u.Mail,
    u.UserPrincipalName,
    u.OtherMails
})
.GetAsync();  

You can get the alternate email from the "otherMails" property on a User in the Graph API Docs.

Note that this is only returned on a Select, so you need to include the query parameter "$select=otherMails" to see it.

GET https://graph.microsoft.com/v1.0/users/USER_ID?$select=otherMails
authorization: bearer {access_token}

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(otherMails)",
    "@odata.id": "https://graph.microsoft.com/v2/YOUR_AAD_TENANT/directoryObjects/USER_ID/Microsoft.DirectoryServices.User",
    "otherMails": [
        "altEmail@website.com"
    ]
}
Related