Today, while working on a project, came across an interesting fact about REST API. I had a list having columns as Employee Name, Job Title, Department and Description. Their types were Person or Group, Single line of text, Single line of text and multiple lines of text respectively.
The general URL in REST API to query data from list is:-
WRONG WAY – /_api/web/lists/getbytitle(listname)/items?$select=Employee Name,JobTitle,Department,Description.
This is wrong, because Employee Name is a Person or Group type column and you cannot use it in select parameter. For that you must use – “expand” like below in your URL:-
RIGHT WAY – /_api/web/lists/getbytitle(listname)/items?$select=JobTitle,Department,Description,EmployeeName/FirstName,EmployeeName/LastName
Noticed Above ?? In above REST URL, I have used “EmployeeName/ID” in expand parameter and then you can access all user properties with select parameter like FirstName, LastName, EMail, UserName,Department,Name,JobTitle etc.
Please remember, if you want to use other User Properties, appropriate names should be given. (For E.g. – for getting email of the user, do not use WorkEmail or Email. instead use EMail – capital M 🙂 )