Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

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

Does your App request read permissions to User Profiles?

enter image description here

share|improve this answer
    
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. –  JohnnyT Mar 11 '13 at 18:14

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

App Permissions

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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