Jos Bredek
Jos Bredek

Reputation: 21

MS Graph API: looking for ALIAS of user

I've been playing with the MS graph api. Nice stuff.

One thing keeps me puzzled, i can't seem to find the ALIAS of a user, in the users properties. The people search https://graph.microsoft.com/beta/me/people?$search="123456" gives me the exact right result. But none of the properties matches the alias field (employeeID, userprincipalname, etc). I know it's in there cause the full outlook client can dig it out...

Any tips (probably I'm overlooking something very trivial)

outlook screenshot: outlook screenshot

Upvotes: 2

Views: 4744

Answers (2)

Jos Bredek
Jos Bredek

Reputation: 21

thanks for your reply. Much appreciated.

Great to know that the mailNickname is the same as alias. I already did some testing with the mailNickName in the select. I get this response:

{
    "error": {
        "code": "BadRequest",
        "message": "Could not find a property named 'mailNickname' on type 'microsoft.graph.person'.",
        "innerError": {
            "request-id": "5c84fa9e-4989-40aa-b099-0e7bc4dc14cf",
            "date": "2018-06-09T11:56:27"
        }
    }
}

I think this is permisson related... cause when i do the same on "me" i DO get my own alias.

I'll contact my site admins to give me some additional privileges...probably this one....

admin rights needed

Upvotes: 0

Marc LaFleur
Marc LaFleur

Reputation: 33124

A user's "alias" is held in the mailNickname. By default, this property isn't returned as part of the /user/{upn} or /me result so you need to specifically request it using the $select query parameter. From the documentation:

Note: Getting a user returns a default set of properties only (businessPhones, displayName, givenName, id, jobTitle, mail, mobilePhone, officeLocation, preferredLanguage, surname, userPrincipalName). Use $select to get the other properties and relationships for the user object.

For example, calling /me returns:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
    "id": "48d31887-5fad-4d73-a9f5-3c356e68a038",
    "businessPhones": [
        "+1 412 555 0109"
    ],
    "displayName": "Megan Bowen",
    "givenName": "Megan",
    "jobTitle": "Auditor",
    "mail": "[email protected]",
    "mobilePhone": null,
    "officeLocation": "12/1110",
    "preferredLanguage": "en-US",
    "surname": "Bowen",
    "userPrincipalName": "[email protected]"
}

In order to return mailNickname you need to specify that you want this property using $select.

Calling /me?$select=mailNickname for example will return:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(mailNickname)/$entity",
    "mailNickname": "MeganB"
}

You'll notice that $select doesn't add to the properties that are returned, it specifies the entire set you're requesting. So to include the default set as well as mailNickname you would need to add the default properties as well.

For example, calling /me/?$select=businessPhones,displayName,givenName,jobTitle,mail,mobilePhone,officeLocation,preferredLanguage,surname,userPrincipalName,id,mailNickname returns:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(businessPhones,displayName,givenName,jobTitle,mail,mobilePhone,officeLocation,preferredLanguage,surname,userPrincipalName,id,mailNickname)/$entity",
    "id": "48d31887-5fad-4d73-a9f5-3c356e68a038",
    "businessPhones": [
        "+1 412 555 0109"
    ],
    "displayName": "Megan Bowen",
    "givenName": "Megan",
    "jobTitle": "Auditor",
    "mail": "[email protected]",
    "mailNickname": "MeganB",
    "mobilePhone": null,
    "officeLocation": "12/1110",
    "preferredLanguage": "en-US",
    "surname": "Bowen",
    "userPrincipalName": "[email protected]"
}

Upvotes: 3

Related Questions