Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE : Get User Properties And User Information List in SharePoint REST API
Hey there! In this blog, we are going to see how can we fetch User Names and User Emails using a REST API call that displays particular user information.
In SharePoint, you can access the User Information List to get basic data about a user.
This list is hidden and there’s no direct link provided by Microsoft to access the list, which I will discuss later in this blog.
To get the user Name and Email, we are going to use the endpoint,
_spPageContextInfo.webAbsoluteUrl + “/_api/web/getuserbyid(” + UserID + “)”;
JavaScript Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
function fnGetUserProps() { var UserID = _spPageContextInfo.userId; var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + UserID + ")"; $.ajax({ url: requestUri, type: "GET", headers: { "Accept": "application/json; odata=verbose" }, async: false, success: function(data) { var userName = data.d.Title; var userEmail = data.d.Email; alert(userName+' '+userEmail); }, error: function(error) { console.log("fnGetUserProps:: " + error); } }); } |
REST API to Get all properties of the current user,
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties
REST API to Get all properties of Specific User,
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=’i:0%23.f|membership|user@domain.com’
For more information refer the URL below,
- https://docs.microsoft.com/en-us/previous-versions/office/developer/sharepoint-rest-reference/dn790354(v=office.15)?redirectedfrom=MSDN#bk_PeopleManagerGetPropertiesFor
User Information List
- The User Information List is hidden which resides only in Root Site Collection and contains data about the user added as part of their Active Directory (AD) profile configuration, users don’t have a direct link to access it.
- Whenever you grant access to the user on the SharePoint site/list or the other resource, the user automatically gets added to the present list.
-
If any AD Group is given permission on-site, the group also will be added to the User Information List, and also the Group-users are going to be added to the list.
- You can access the User Information list as long as you’re an Admin of the location.
To access User Information List
Get detailed information for users – https://SiteURL/_catalogs/users/detail.aspx
Get basic information for users – https://SiteURL/_catalogs/users/simple.aspx
Access SharePoint User Information List Using REST API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
function fnGetAllFields() { $.ajax({ url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getByTitle('User Information List')/fields", method: "GET", headers: { "Accept": "application/json;odata=verbose" }, success: function(data) { var dataResults = data.d.results; for (var i = 0; i < dataResults.length; i++) { console.log(dataResults[i]["Title"]); } }, error: function(error) { console.log("Failed"); } }); } |
Print article | This entry was posted by Peter on May 27, 2021 at 2:00 am, and is filed under European SharePoint 2013 Hosting. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |