2

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!

stockDevelopers
  • 53
  • 1
  • 3
  • 8

1 Answers1

8

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));
        }
});
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
  • Hi, thanks! How can I replace 'Domain\\Login' to current user? – stockDevelopers Apr 29 '14 at 05:29
  • 1
    The following REST request /_api/Web/CurrentUser/LoginName returns the LoginName for the current user – Vadim Gremyachev Apr 29 '14 at 07:39
  • I am trying to get "QuickLinks" from user profile, this request returns almost everything but "QuickLinks" is empty, I have tried CSOM to fetch user info but that also gives me empty string, getting quick links is not supported or I need to have a look somewhere else? – Ali Jul 14 '14 at 03:33
  • 1
    @stockDevs: If you want the properties for the current user you can replace /_api/SP.UserProfiles.PeopleManager/GetPropertiesFor[...] with /_api/SP.UserProfiles.PeopleManager/GetMyProperties – Nick Cox Sep 08 '14 at 04:32