Sp-dev-docs: PnP-JS malforming REST call in SPFx Application Customizer

Created on 19 Jun 2017  路  3Comments  路  Source: SharePoint/sp-dev-docs

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.

answered question

All 3 comments

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!

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.

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

Was this page helpful?
0 / 5 - 0 ratings