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.
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',
},
});
I agree with @user2250152, while querying the user details if the
preferredLanguage
is displaying asnull
then the user might not have set thepreferredLanguage
in the Azure AD user details.
Go to Azure Portal -> Users -> Select the user -> Overview -> Properties
Initially I got the preferredLanguage
as null while querying the user:
GET https://graph.microsoft.com/v1.0/me?$select=id,mail,displayName,givenName,businessPhones,preferredLanguage
Note that: Some user properties/details cannot be updated directly from the Azure Portal, make use of Microsoft Graph API to update the preferredLanguage
property.
PATCH https://graph.microsoft.com/v1.0/me
{
"preferredLanguage": "en-US"
}
After refreshing the user page, the preferredLanguage
property is updated:
Now when I used the same query to fetch the user details, the preferredLanguage
is displayed with the value:
GET https://graph.microsoft.com/v1.0/me?$select=id,mail,displayName,givenName,businessPhones,preferredLanguage
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,mail,displayName,givenName,businessPhones,preferredLanguage)/$entity",
"id": "XXX",
"mail": "user@***.onmicrosoft.com",
"displayName": "user",
"givenName": null,
"businessPhones": [],
"preferredLanguage": "en-US"
}