Getting Person or Group Type field in REST API SharePoint 2013

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
&$expand=EmployeeName/ID

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 🙂 )

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s