SharePoint/PnP-JS-Core

UserProfile MyProperties with error 500

Closed this issue · 2 comments

Category

[ ] Enhancement

[ ] Bug

[X] Question

Version

Please specify what version of the library you are using: [ 3.0.9 ]

If you are not using the latest release, please update and see if the issue is resolved before submitting an issue.

Expected / Desired Behavior / Question

Hi Guys,

I am using pnp.sp.profiles.myProperties to get all information of the logged In user from the Userprofile.

Observed Behavior

I get the error "[Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (getmyproperties, line 0) https://____/sites//_api/sp.userprofiles.peoplemanager/getmyproperties"

Steps to Reproduce

 getMyProperties() {
    const _sp = pnp.sp.configure(
      {
        headers: {
          "Content-Type": "application/json",
          Accept: "application/json;odata=verbose"
        }
      },
      this.urlSite
    );
    _sp.profiles.myProperties.get().then(d => {
      const properties = d.UserProfileProperties.results;
      console.log(properties);
    });
  }

index.html

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Device Request</title>
    <base href="/">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <script src="/_layouts/15/sp.init.js" type="text/javascript"></script>
    <script src="/_layouts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="/_layouts/sp.core.js" type="text/javascript"></script>
    <script src="/_layouts/sp.runtime.js" type="text/javascript"></script>
    <script src="/_layouts/sp.js" type="text/javascript"></script>
    <script src="/_layouts/SP.UI.Dialog.js" type="text/javascript"></script>
    <script src="/_layouts/15/ScriptResx.ashx?name=sp.res&culture=en-us" type="text/javascript" ></script>
</head>

<body>
    <app-root></app-root>
</body>

</html>
<script>
    // self executing function here
    (function() {
        LoadSodByKey("sp.js", function () { });
    })();
    </script>

Thanks!

Hi @hmendezm,

Didn't actually get what and how to reproduce. Any combinations I tried whatever the crazy they were just worked for me.

I guess, that it's about the configuration of the context of your application in SP. Isn't it some sort SPA deployed to a SP page not as a webpart but a full page source? I would recommend use another approach and host an "app" within CEWP, yet style it as a full page if needed.

For example, CEWP source html file body:

<div id="wrapper">
  <div id="app">My app</div>
</div>

<style>
.ms-rtestate-field #wrapper {
  position: fixed;
  width: 100%;
  left: 0;
  top: 50px;
  z-index: 100;
  background: #fff;
  overflow: auto;
  bottom: 0px;
}
#app {
  padding: 1em;
}
.ms-rtestate-write #wrapper {
  position: relative;
}
</style>

To look like:

image

While it's actually a CEWP and all the standard context and scripts are on the page by default:

image

Let's pretend it's 2013 and no SPFx world is there for you yet. =)

But it absolutely a separate question.

Regard PnPjs, sp.configure worked for me as well, however, could you try this:

import { sp } from '@pnp/sp';

sp.setup({ sp: { baseUrl: webAbsoluteUrl }});
// OData headers for 2013 if it's a case

sp.profiles.myProperties.get().then(console.log);

Thank you for your interest in the sp-pnp-js library. We wanted to mention that this library is being deprecated in July 2018 in favor of the new scoped pnpjs libraries. You should begin transitioning your existing projects when possible or start new projects with the new libraries. Please see the transition guide for more details on migrating and be sure to let us know if you have any questions. Thanks!

Thanks KoltyaKov. My problem was the User profile service itself. it was not synchronizing correctly.

Best,
hmendezm