sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

PnP-JS malforming REST call in SPFx Application Customizer

Open acksoft opened this issue 9 years ago • 3 comments

Category

  • [ ] Question
  • [ ] Typo
  • [x] Bug
  • [ ] Additional article idea

Expected or Desired Behavior

I am trying to create a menu in the header, with the text and link information coming from a list in the current web. In the onRender() event I am assigning some html to the _headerPlaceholder.domElement.innerHTML, then calling a method that executes a PnP js call to get the link data out of the list. This in turn calls a method to use the returned data to construct the html for the header.

Observed Behavior

When the code is executed the menu is blank -- no links display.

Steps to Reproduce

Upon investigation, the following PnP call: pnp.sp.web.lists.getByTitle('OrangeLinks').items.select('URL').get().then((links: any) => {...more code here...});

Resolves to this REST call, visible in the inspector panel of the browser: https://tenant.sharepoint.com/sites/sitecollectionname/SitePages/_api/web/lists/getByTitle('OrangeLinks')/items?$select=URL

And thus a response from the server that is (404) Not Found.

The REST call is not executing from the root of the web site, but attempting to access the list from the SitePages folder. When I copy that URL and remove the SitePages/ from the it and put it into the address bar of a blank browser window, the expected items are returned.

acksoft avatar Jun 19 '17 17:06 acksoft

Are you following the instructions for setting up your application with PnP JS Core?

This behavior typically happens when the code is not able to automatically determine the context and set the web url.

In the future, please report issues with the JS Core library to the issues list for the library itself. Thanks!

patrick-rodgers avatar Jun 19 '17 17:06 patrick-rodgers

Your additional "instructions" have solved the problem. Thank you, it is always nice when I find that the problem is something simple that I missed. Future pnp js items will be posted to the preferred issues list.

acksoft avatar Jun 19 '17 18:06 acksoft

Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues

msft-github-bot avatar Jan 29 '20 12:01 msft-github-bot