SharePoint REST query SP.UserProfiles.PeopleManager

stockDevelopers picture stockDevelopers · Apr 28, 2014 · Viewed 11.2k times · Source

Is it possible to get data using REST query like below:

http://moss.moss/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='user_domain\user'&$filter=DirectReports

And call by JavaScript.

I would like to create script which will check if user is a manager (has DirectReports) and next display JavaScript alert.

Thanks in advance!

Answer

Vadim Gremyachev picture Vadim Gremyachev · Apr 28, 2014

How to retrieve Manager property via SharePoint User Profiles REST API

var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
var accountName = 'Domain\\Login';
$.ajax({
        url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (data) {
            if(data.d.DirectReports.results.length > 0)
            {
                 console.log('User has managers');     
            }
        },
        error: function (data) {
            console.log(JSON.stringify(data));
        }
});