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 been fighting to get user data using the REST API but I can't get it to work mainly because I am getting a server error 500

"Network Error: 500 Internet Server Error - http://mysite/_api/SP.UserProfiles.PeopleManager/GetMyProperties

I'm not sure what I've done wrong but I can't get over this error at all. Does anyone know what could be the cause of this or how I can fix this. Here is my REST code as well

//Connection and Data
function getMyUserProfile(success, error) {
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
$.ajax({
    url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: function (data) {
        success(data.d);
    },
    error: error
});
}

// Usage   
getMyUserProfile(
           function (properties) {
          document.getElementById("sp-name").innerHTML = (properties.DisplayName),
          document.getElementById("sp-avatar").innerHTML = (properties.PictureUrl);
      },
      function (data) {
          console.log(JSON.stringify(data));
      });
share|improve this question
    
Does the returned URL actually contain some data? Have you tried defining siteUrl variable as _spPageContextInfo.webAbsoluteUrl;? –  moe Aug 11 at 9:22
    
Where is this code situated? In a SharePoint page in an app? Make sure an app has the correct permissions. –  W0ut Aug 11 at 9:41
    
Hi there, this code is actually in the masterpage as I need this to cross the entire site so I can display a username in the header of said master page. –  Yanayaya Aug 11 at 9:46
    
When I define it as _spPageContextInfo.webAbsoluteUrl; I get the same error –  Yanayaya Aug 11 at 9:49
    
Your code worked successfully on my site. Can I assume you are on prem? Is this your first attempt at REST in this environment, or have you successfully used REST in this environment before? –  wjervis Aug 11 at 11:52

2 Answers 2

Ok after a little messing I managed to get this to work. Despite having a publishing site I still had to set up my site and also the active directory connection and synchronisation service. With those items in place the Internal Server error 500 vanished and the data was displayed.

Thanks to everyone for their help in getting to the bottom of this, a simple fix but without knowing it's hard to pin point immediately.

share|improve this answer

Try using the below URL :

_spPageContextInfo.webServerRelativeUrl+ "/_api/SP.UserProfiles.PeopleManager/GetMyProperties

If you still do not get the code working try accessing the URL in the browser

http://yoursite.yourdomain.com/_api/SP.UserProfiles.PeopleManager/GetMyProperties

and see if the results are returned. If you get a feed reading error in the IE, you can go to the IE options -> Content tab -> Feeds section "setting" -> Uncheck the "Turn on feed reading view"

share|improve this answer
    
If I try to access the url in a browser I get the following error. <m:error><m:code>-1, Microsoft.SharePoint.Client.UnknownError</m:code><m:message xml:lang="en-US">Unknown Error</m:message></m:error> Not helpful I know but that's what I get –  Yanayaya Aug 11 at 12:57
    
Have you referenced the SP.UserProfiles.js ? –  Vipul Kelkar Aug 11 at 15:27
    
I thought I had. Can you do me a favor and show me where and how I would do that? It would help a lot in working through this problem. –  Yanayaya Aug 11 at 15:54
    
You can use the SharePoint:Scriptlink tag to include the JS in your master page. Refer this: link –  Vipul Kelkar Aug 11 at 16:59
    
Thanks for the link. I have added SP.UserProfiles.js as suggested but the error remains the same. This is so frustrating. I'm not sure what else it could be...any ideas? –  Yanayaya Aug 12 at 8:34

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.