13

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?

3 Answers 3

5

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);
    }
});
4
  • You are right, no cross domain call needed. Just the right permissions. Commented Mar 11, 2013 at 18:15
  • This doesn't seem to work for on-premise solutions. Any suggestions? Commented Mar 18, 2013 at 19:27
  • It should. I have tested it on On-Premise environment too. Commented Mar 19, 2013 at 2:20
  • @BlakeBlackwell make sure your User Profile service is properly configured and running. Commented Oct 29, 2013 at 19:20
10

Does your App request read permissions to User Profiles?

enter image description here

1
  • This sure pointed me to the right direction. Apparently its not enough to have the User Profiles permission, you also need the Tenant permission, otherwise the request fails. Commented Mar 11, 2013 at 18:14
1

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

App Permissions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.