REST API's are great way to query data from SharePoint Lists, Document libraries, Sites.
But if you refer to a Person (Person or Group) column using REST, you may encounter an exception "The query to field 'Approver' is not valid. The $select query string must specify the target fields and the $expand query string must contains Approver (Microsoft.SharePoint.SPException), where Approver is a person type field."
How to get SharePoint user details using REST ?
You can retrieve SharePoint user (Person or Group) details in REST call by using $expand OData query parameter. You cannot select all details together and need to specify which property to retrieve (say FirstName).The same applies even for Lookup columns in SharePoint. This approach will work for all SharePoint versions.
Consider you have a custom SharePoint List "Payment Requests" with a person column "Approver".
We want to fetch the Title and Approver First Name.
Incorrect Query - https://c2c.sharepoint.com/sites/SPDemo/_api/web/lists/getbytitle('PaymentRequests')/items?$select=Title,Approver
Correct Query - https://c2c.sharepoint.com/sites/SPDemo/_api/web/lists/getbytitle('PaymentRequests')/items?$select=Title,Approver/FirstName&$expand=Approver/ID
Note that we are expanding the lookup using Approver/ID (Column/ID) and selecting required value as Approver/FirstName (Column/Property).
Similarly we can query and fetch other properties/attributes from the user profile for a given people/lookup column.
Here is a list of attributes which can be queried, replace and use with your $select query as Column/Property.
⚡️ Important - Use exact name with capitalization.
Some sample queries,
Get user Email address using RESThttps://c2c.sharepoint.com/sites/SPDemo/_api/web/lists/getbytitle('PaymentRequests')/items?$select=Title,Approver/EMail&$expand=Approver/ID
Get user Designation using RESThttps://c2c.sharepoint.com/sites/SPDemo/_api/web/lists/getbytitle('PaymentRequests')/items?$select=Title,Approver/JobTitle&$expand=Approver/ID
Get user Department using RESThttps://c2c.sharepoint.com/sites/SPDemo/_api/web/lists/getbytitle('PaymentRequests')/items?$select=Title,Approver/Department&$expand=Approver/ID
- Managed Metadata error - The data returned from the tagging UI was not formatted correctly
- How to generate client id and secret to register SharePoint App with OAuth
- Create SharePoint Site Collection with new Content database in existing web application
- Fix Error 2711 SQL RBS client - The installer has encountered an unexpected error. The specified Feature name ('Docs') not found in Feature table
- How to exclude results from SharePoint Search
- 'Edit Document' Requires a Windows Sharepoint Services-compatible application and Microsoft Internet Explorer 6.0 or higher
- [Solved] SharePoint Access Denied error editing Document Name
- Recommended size and resolution for SharePoint Online Site logo
- SharePoint Server 2016 IT Preview - new improved Features and Enhancements
- Restore deleted Office 365 SharePoint group site
- SharePoint An unexpected error has occurred - Correlation ID and PowerShell Merge-SPlogfile
- [Solved] SharePoint Search Internal server error exception
- SharePoint CAML query error - The XML source is not correct
- How to hide quick launch in SharePoint classic site
- Not receiving email notification alert in SharePoint Online workflow - Power Automate, FLOW
- Change SharePoint search results FullTextSqlQuery RowLimit 10000
- Fix Power BI error Access to the resource is forbidden when connecting SharePoint Online List as data source
- [Fix] Restricted View permission level missing in SharePoint Online site library
- How to upload file programmatically to SharePoint Document Library using Server Object Model C# .Net
- How to create classic site in SharePoint Online
- That did'nt work, Issue type User not in directory - SharePoint external access error
- Merge-SPlogfile PowerShell - SharePoint Correlation ID error
- Fix Power BI 404 not found error when connecting SharePoint Online List as Data Source
- SharePoint Server 2016 IT Preview Deprecated Removed features
- SharePoint error - An exception occurred when trying to issue security token: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms..
- How to stop/start/restart apache server using command [Ubuntu] - Ubuntu
- Fix java.net.ProtocolException: Invalid HTTP method - Java
- JSON Nest Objects Example: JSON Tutorial - Json-Tutorial
- Install specific JRE on Ubuntu using apt - Ubuntu
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end users experience - Java
- list of jars required for hibernate 4.x.x - Java
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted. - Android
- Your Android SDK is out of date or is missing templates. Please ensure you are using SDK version 22 or later. - Android