Search This Blog

Sunday, August 6, 2017

Get User Details from Person or Group field using REST API

This article helps to understand, how to get user details like FirstName, LastName, Email Addrss etc. for a Person/Group field using REST API.

Normally, in a list where we have Person/Group column (say Employee), when we use REST API to get this column value, we get User ID instead of actual value what we see in list column. Reason being Person/Group column is actually a lookup field internally.

Say I have a list Employees with column "Users", and for one item value for Users is "Danish Islam" (set to Name with Presence property). 



Now if I query this list using below REST API -

_api/web/lists/getbytitle('employees')/items
I see result as in below screenshot-




Here if you observe, Users column is returned as "UsersId" and with value "10" not the actual value.

Now if I want the actual value, I have to modify my query something like below-

_api/web/lists/getbytitle('employees')/items?$select=Users/Title&$expand=Users/Id
See the highlighted change, this will return exact value like below-




Similarly If i want to display Email Address or First Name or Last Name, I just have to replace keyword after column name - Title after Users.  See below example-

Query:

_api/web/lists/getbytitle('employees')/items?$select=Users/EMail,Users/FirstName,Users/LastName,Users/EMail&$expand=Users/Id

Result: 



No comments:

Post a Comment