What can be the reason behind Microsoft graph API(/v1.0/me) returning NULL in “preferredLanguage” field in the profile object?

My app on Microsoft Teams is using the consent flow to get the permissions from a user. Then with the access token returned by Microsoft, the app is trying to fetch the profile of the user using the /v1.0/me route. But for many users the preferredLanguage field in the profile object is null, only in some users the filed is returning a language. My app needs the preferred language of the user to show a translated version of the app.

I am requesting the following scopes from Microsoft.

  1. User.Read
  2. TeamsActivity.Send (not related to this issue)
  3. offline_access (for refresh token)

Following is the code for the request for fetching the profile.

const { data, status } = await axios({
      method: 'GET',
      url: `https://graph.microsoft.com/v1.0/me?$select=id,mail,displayName,givenName,businessPhones,preferredLanguage`,
      headers: {
        Authorization: `Bearer ${accessToken}`,
        ConsistencyLevel: 'eventual',
      },
});

Below are the screenshots of Microsoft 365 language settings and what the API is returning.

Screenehot of Microsoft 365 language settings where the preferred language set as German
Screenshot of console log of the returned profile object where the preferred language is null

Leave a Comment