Get profile properties from person/group field using rest api [duplicate]
-
08-02-2021 - |
Question
I have a list with a person field. I need users to fill in the field with their names but I need to get the following properties below from that field using rest API:
- Email Address
- Name(Full Name)
- Department
- Job Title
- Phone Number
Is this possible?
Thanks in Advance.
Solution
You will not be able to get the user profile properties by using the name of user.
To access the properties using REST API you will need the Login Name (accountName) of user.
If you have a login name of user then you can access its properties using:
siteUrl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='i:0%23.f|membership|username@tenant.onmicrosoft.com'
Where i:0%23.f|membership|username@tenant.onmicrosoft.com
is login name of user.
Note:
The Login Name will be in format something like : i:0%23.f|membership|ganesh.sanap@tenant.onmicrosoft.com
Everything after membership|
is email address of user. So using email address you can build the login name string like this and use it in the REST API above to get the user properties.
You can get the Email Address
of users from Person or Group
field using below endpoint:
siteUrl/_api/web/Lists/getbytitle('TestList')/Items?$select=Title,TestPersonField/EMail&$expand=TestPersonField
OTHER TIPS
You can get current user's profile
_api/SP.UserProfiles.PeopleManager/GetMyProperties