Tuesday, December 9, 2014

User profile services are common nowadays in SharePoint applications. Most of the applications uses User profile service to fetch user information. And in SharePoint 2013 it is recommended that we must create client side application rather than server side. So it is important to learn working with User Profile service using REST services.

Working with REST services is easy, just remember the REST URL and its parameters. User Profile service returns all properties of user if things goes right.

Following is the REST URL for getting properties of user

URL:  /_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='accountName'

Code snippets:

HTML code:

<script type="text/javascript" src="/Site%20Assets/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="/Site%20Assets/js/knockout.3.2.0.js"></script>
<script type="text/javascript" src="/Site%20Assets/js/GetUserfromService.js"></script>

Current USer Information:
Login name : <span data-bind="text: LoginName"></span>
Title : <span data-bind="text: Title"></span>
Email : <span data-bind="text: Email"></span>

JS Code (GetUserfromService.js):

var RESTURL = "/sites/OnePalSh/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='accountName'";
$(document).ready(function () {
function GetUserInformation()
var self = this;
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
success: function (userdata) {
  self.LoginName = userdata.d.AccountName;
self.Title  = userdata.d.DisplayName;
self.Email = userdata.d.Email;
error: function (error) {

Now we will see other various options available for User Profile services.

To get the properties of current user use following URL:


To get the specific properties of user:




In above code snippet we have just fetched some basic information. To fetch all other properties you need to iterate through properties array which is shown below.

In this way you can use REST services for User profile services interactions.

Happy SharePoint coding.


Post a Comment