User Profile properties with REST API–SharePoint Office 365

Sriram
 
Technology Specialist
July 19, 2018
 
Rate this article
 
Views
27367

 

In this post lets have a look at how to get SharePoint user profile properties using the REST API.

Here is a quick reference for the REST API endpoints.

1) Get all properties of current user:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties

2) Get single property of current user:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties/PictureUrl
OR
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl

3) Get Multiple Properties for the current user:

http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl,AccountName

4) Get all properties of Specific User:

For Office 365/SharePoint Online:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=’i:0%23.f|membership|vardhaman@siteurl.onmicrosoft.com’
For SharePoint 2013 On-Premise:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v=’domain\username’

5) Get Specific UserProfile Property of Specific User:

For Office 365/SharePoint Online:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName=’LastName’)?@v=’i:0%23.f|membership|vardhaman@siteurl.onmicrosoft.com’
For SharePoint 2013 On-Premise:
http://siteurl/_api/SP.UserProfiles.PeopleManager/GetUserProfilePropertyFor(accountName=@v,propertyName=’LastName’)?@v=’domain\username’

 

 

 

 

 

 

Below is the function to get user profile details for the particular user.

 function gettingUserProfileByAccountName(accountName) {
 
 $.ajax({
 
 url: _spPageContextInfo.webAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='"+accountName+"'",
 
 headers: {
 
 "Accept": "application/json; odata=verbose"
 
 },
 
 async: false,
 
 contentType: "application/json; odata=verbose",
 
 success: function (data) {
 
 var results;
 
 if (data.d) {
 
 results = data.d.UserProfileProperties.results;
 
 for (i = 0; i < results.length; i++) {
 
 if (results[i].Key == "WorkEmail") {
 
 $('input[title="Requestor Email"]').val(results[i].Value);
 
 }
 
 if (results[i].Key == "WorkPhone") {
 
 $('input[title="Requestor Phone"]').val(results[i].Value);
 
 }
 
 }
 
 }
 
 }
 
 });
 
 }
 

Author Info

Sriram
 
Technology Specialist
 
Rate this article
 
Sriram T has been working in IT industry for over 6 years He holds Bachelor's degree in Computer Science Engineering. Sriram write articles and blogs related to SharePoint 2013, SharePoint ...read more
 

Leave a comment