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.Example
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.
AboutMe |
Account |
ContentType |
ContentTypeID |
Created |
Deleted |
Department |
FirstName |
Hidden |
IsSiteAdmin |
JobTitle |
LastName |
MobileNumber |
Modified |
Name |
Picture |
SIPAddress |
Some sample queries,
Get user Email address using REST
https://c2c.sharepoint.com/sites/SPDemo/_api/web/lists/getbytitle('PaymentRequests')/items?$select=Title,Approver/EMail&$expand=Approver/IDGet user Designation using REST
https://c2c.sharepoint.com/sites/SPDemo/_api/web/lists/getbytitle('PaymentRequests')/items?$select=Title,Approver/JobTitle&$expand=Approver/IDGet user Department using REST
https://c2c.sharepoint.com/sites/SPDemo/_api/web/lists/getbytitle('PaymentRequests')/items?$select=Title,Approver/Department&$expand=Approver/IDComments:
- How to implement this with Angular JS? I cant' figure out.
14 Dec 2020 16:12:42 GMT
- This does not work in case of multiple entries in people field. Any suggestions?
02 Dec 2020 13:19:44 GMT
- I can achieve this by referring to your blog and able to fetch user name and email, but not able to get the profile picture. Can you help plz
24 Nov 2020 17:44:01 GMT
- I passed email in the expand query but not working.
11 Nov 2020 20:20:49 GMT
- Can you share the correct query for getting SharePoint user display name using Graph API? I want to use in an Azure hosted App.
11 Nov 2020 09:11:43 GMT
- I only get an ID, something wrong with the API call but don't understand. Can you share your email? I can share the query with you for checking.
02 Nov 2020 12:12:32 GMT
- Further comments disabled!
- Move Copy Migrate SharePoint OneDrive files folders to different site collection location
- How to generate client id and secret to register SharePoint App with OAuth
- How to share SharePoint site or document with all users in organization
- Get-ADUser PowerShell - Get AD user details using email address
- error CAML Query containing special characters
- Access URL for SharePoint Tenant Admin Center (Online Office 365)
- Fix SharePoint Error - The Managed Metadata Service or Connection is currently not available. The Application Pool or Managed Metadata Web Service may not have been started
- SharePoint - The URL is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web.
- How to delete SharePoint List Item programmatically using C#.Net
- How to Share Microsoft SharePoint Site with Users or Groups
- JSON column formatting to preview SharePoint Online file on mouse hover
- SharePoint List redirect user after submitting form NewForm.aspx
- See actual SharePoint error exception modify web.config
- SharePoint Server 2016 IT Preview Deprecated Removed features
- How to create SharePoint Document Library
- How to Get or Set SharePoint Document ID _dlc_DocId using PowerShell
- How to disable SharePoint subsite creation option for owners
- PowerShell - How to use Try Catch Finally blocks for error exception handling (Windows/SharePoint)
- SharePoint error - Your organization doesn't allow sharing with users from this domain. Please contact your IT department for help. (OSE403)
- [Solved] SharePoint Search Internal server error exception
- How to wrap column text in SharePoint Online Modern List Grid View using JSON formatting
- How to extend retiring SharePoint 2010 Workflows and continue with Office 365
- Changed AD user display name showing old name in SharePoint
- How to hide or remove quick launch left navigation from SharePoint Online Modern site page
- How to enable anonymous public access for SharePoint Online site collection, file, folder without login ?
- Install Microsoft Remote Desktop (RDP) Client on Mac - Microsoft
- PowerShell iterate and get all SharePoint sites and sub sites - SharePoint
- 🌗 List of Solar Eclipses in the year 2020-2021 🌑 - Science
- Java 8 JDBC: Insert Timestamp Code Example - Java
- MySQL ERROR 1064 (42000): You have an error in your SQL syntax [fix] - MySQL
- How to use Content Assist in Eclipse IDE - Eclipse
- Fetch More then 10 Links Per Page in Google Search Result - Google
- Java monitoring and management console [jconsole] - Java