1

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));
      });
8
  • Does the returned URL actually contain some data? Have you tried defining siteUrl variable as _spPageContextInfo.webAbsoluteUrl;?
    – moe
    Commented Aug 11, 2014 at 9:22
  • Where is this code situated? In a SharePoint page in an app? Make sure an app has the correct permissions.
    – Wout
    Commented Aug 11, 2014 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
    Commented Aug 11, 2014 at 9:46
  • When I define it as _spPageContextInfo.webAbsoluteUrl; I get the same error
    – Yanayaya
    Commented Aug 11, 2014 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
    Commented Aug 11, 2014 at 11:52

3 Answers 3

1

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.

1

Somehow there is an issue reading all of the properties of an account so try to select only what you want like in the url

siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=AccountNamr,Email
0

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"

7
  • 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
    Commented Aug 11, 2014 at 12:57
  • Have you referenced the SP.UserProfiles.js ? Commented Aug 11, 2014 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
    Commented Aug 11, 2014 at 15:54
  • You can use the SharePoint:Scriptlink tag to include the JS in your master page. Refer this: link Commented Aug 11, 2014 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
    Commented Aug 12, 2014 at 8:34

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.