Get User Profile Properties Of All Users Using REST

Hi All,

In this blog, we will see how to fetch user profile properties of all users from SharePoint online.

Many times we need to display specific properties of all users programmatically, so for that, I have Rest API to access User profiles properties. In this case, if properties are mapped to an Active directory then the available data is correct and dynamic.

First we need to add jQuery reference in our file
  1. <script src="/SiteAssets/JS/jquery.min.js"></script>  
SiteUsers is used to get all the users of SharePoint Online site.
  1. <script>  
  2.     $.ajax({  
  3.         asynch: false,  
  4.         url: "your site url /_api/Web/SiteUsers",  
  5.         method: "GET",  
  6.         headers: {  
  7.             "Accept""application/json; odata=verbose"  
  8.         },  
  9.         success: function(data) {  
  10.             if (data.d.results.length > 0) {  
  11.                 for (var i = 0; i < data.d.results.length; i++) {  
  12.                     var accountName = data.d.results[i].LoginName;  
  13.                     GetUserProperties(accountName.replace("#""%23"));  
  14.                 }  
  15.             }  
  16.         },  
  17.         error: function(x, y, z) {  
  18.             alert(JSON.stringify(x) + '\n' + JSON.stringify(y) + '\n' + JSON.stringify(z));  
  19.         }  
  20.     });  
GetUserProperties function is used to get the user profile properties of specific users in SharePoint site.
  1. function GetUserProperties(user) {  
  2.     $.ajax({  
  3.         asynch: false,  
  4.         url: "your site name/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + user + "'",  
  5.         method: "GET",  
  6.         headers: {  
  7.             "Accept""application/json; odata=verbose"  
  8.         },  
  9.         success: function(data) {  
  10.             console.log("Name = " + data.d.DisplayName);  
  11.             //Similarly you can get remaining properties  
  12.             console.log("-------------------");  
  13.         },  
  14.         error: function(data1) {  
  15.             alert("ERROR");  
  16.         }  
  17.     });  
  18. } < /script>  
Thank You.. 
G
M
T
 
Text-to-speech function is limited to 200 characters