Milad Ghafoori
Milad Ghafoori

Reputation: 320

MS Graph API does not return user's email address from Azure AD B2C

When I use Microsoft Graph API to get a user from Azure AD B2C, the email address that the user has signed up with does not appear in the returned JSON. Although there are posts in SO that suggest the email address should exist in other fields than Mail (otherMails or signInNames), the received JSON does not contain any field whatsoever with the expected email address. Here is the request that I ran for a test user (sensitive data masked):

GET https://graph.microsoft.com/v1.0/users/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Authorization: Bearer xxxxxxxxx
Content-Type: application/json

And the JSON in the response is:

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
  "businessPhones": [],
  "displayName": "unknown",
  "givenName": "some",
  "jobTitle": null,
  "mail": null,
  "mobilePhone": null,
  "officeLocation": null,
  "preferredLanguage": null,
  "surname": "user",
  "userPrincipalName": "[email protected]",
  "id": "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

Despite that, when I see the user in the Azure AD B2C, the email address is displayed under the "User name" column in the users list page:

enter image description here

And when I view the user's profile, the email address also displays under the "User Principal Name" field:

enter image description here

Where is the email coming from, and how can I get it using the MS Graph API?

Upvotes: 4

Views: 2560

Answers (1)

Raghavendra beldona
Raghavendra beldona

Reputation: 2102

You can get the username from identities collection using Beta endpoint.

Query

https://graph.microsoft.com/beta/users/userid?select=identities

Please go through the articles

Upvotes: 6

Related Questions