Question

I've successfully deployed a SharePoint Hosted App to Office 365 and my local on premise installation. All the app aims to do is call the REST API for the user profile manager to get the profile properties of a user. No matter how I try to call the API it fails.

1) If I try to call it using $.getJson and the url as http://host web url/_api/SP.UserProfiles.PeopleManager/GetMyProperties it fails for cross domain call.

2) If I try to use the request executer and the url as http://app web url/_api/SP.UserProfiles.PeopleManager/GetMyProperties it fails (not found).

3) If I try to use the request executer and the url as http://app web url/_api/SP.AppContextSite(@t)/SP.UserProfiles.PeopleManager/GetMyProperties?@t='" + encodeURIComponent(hostweburl) + "'"; it fails on access denied and/or not found.

If I use the exact same SP.AppContextSite and tries to simply get the title of the web it works just fine.

Is the SP.AppContextSite limited to just the web object? Is there any way to call the user profiles REST API from a SharePoint Hosted App?

Was it helpful?

Solution

Set the Permissions on User Profiles = Read as mentioned in Rob's Answer and then the following code should work. We don't need to use request executor as we are not making a cross domain call here.

$.ajax({

    url:"http://<app web url>/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
    headers:{ Accept:"application/json;odata=verbose" },
    success:function(data){
      alert(data.d.DisplayName);
    },
    error:function(jQxhr,errorCode,errorThrown){
      alert(errorThrown);
    }
});

OTHER TIPS

Does your App request read permissions to User Profiles?

enter image description here

You have to add the permissions in order too. Tenant first, then User Profiles (Social)

App Permissions

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top