SharePoint REST API - Get User Properties And User Information List

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. function fnGetUserProps() {      
  2.     var UserID = _spPageContextInfo.userId;      
  3.     var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + UserID + ")";      
  4.     $.ajax({      
  5.         url: requestUri,      
  6.         type: "GET",      
  7.         headers: {      
  8.             "Accept""application/json; odata=verbose"      
  9.         },      
  10.         async: false,      
  11.         success: function(data) {      
  12.             var userName = data.d.Title;     
  13.             var userEmail = data.d.Email;    
  14.             alert(userName+' '+userEmail);
  15.         },      
  16.         error: function(error) {      
  17.             console.log("fnGetUserProps:: " + error);      
  18.         }      
  19.     });      
  20. }  
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|[email protected]'
 
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
  1. 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.
  2. 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.
  3. 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.
  4. 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. function fnGetAllFields() {    
  2.     $.ajax({    
  3.         url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getByTitle('User Information List')/fields",    
  4.         method: "GET",    
  5.         headers: {    
  6.             "Accept""application/json;odata=verbose"    
  7.         },    
  8.         success: function(data) {    
  9.             var dataResults = data.d.results;    
  10.             for (var i = 0; i < dataResults.length; i++) {    
  11.                 console.log(dataResults[i]["Title"]);    
  12.             }    
  13.         },    
  14.         error: function(error) {    
  15.             console.log("Failed");    
  16.         }    
  17.     });    
  18. }  
Happy Learning!!!      
HexaCorp
Expertise in the cloud, speed of innovation and customer focus on building strong relationships