Sushrut Paranjape
Sushrut Paranjape

Reputation: 547

User principal name vs mail in Graph Users

I am listing users from SharePoint into custom database table for use in custom application. While adding these users to custom database we need the user Id from Azure Active Directory (not user ID from SharePoint).

So based on email of user from SharePoint I search the user in Azure AD and get the ID.

For some users I see that Mail field from Graph User object is null but has User Principal Name field filled with email. And for other users has both Mail and User Principal Name filled.

What is the reason Mail field for users is null? Which field should I rely on as email value?

Thank you!

Upvotes: 5

Views: 2657

Answers (2)

yves175
yves175

Reputation: 11

userPrincipalName may not equal email, for example, "xxx_xxx.com#EXT#@xxx.xxx.com"

Upvotes: 1

Md Farid Uddin Kiron
Md Farid Uddin Kiron

Reputation: 22515

What is the reason Mail field for users is null?

That value is for Guest User only. When you would add a guest user on your tenant there is a field with Email address which has shown below would treated as mail when you get user list using Microsoft Graph API then you would see that email value.

enter image description here

PostMan Test:

enter image description here

Which field should I rely on as email value?

You can rely on userPrincipalName which is User name on azure portal that is mandatory property. Once you set it that would be treated as userPrincipalName which you can be used for any scenario where you need tenant user email for example user login on portal

See the screenshot:

enter image description here

Hope that would help.

Upvotes: 7

Related Questions