Forum Discussion
Debugging SPFx App Customizer
- Jun 19, 2017
Apparently there are some additional instuctions required for the PnP JS and SPFx to play nicely with one another. Thanks to Patrick Rodgers for pointing me to the missing key described in https://github.com/SharePoint/PnP-JS-Core/wiki/Using-sp-pnp-js-in-SharePoint-Framework#establish-context.
A single call in the onInit() method override does the trick:
@override public onInit(): Promise<void> { return super.onInit().then(_ => { //--- ensure that the current web is used for all pnp calls pnp.setup({ spfxContext: this.context }); }); }The REST call is now forming properly. It sure would be nice to have complete, organized documentation all together in ONE PLACE. :)
Thanks again for your interest and assistance.
It looks indeed that the REST Url isn't correct.
In my code I tried this:
pnp.sp.web.lists.getByTitle('MyList').items.get().then((items: any) => {
return items;
});and the above worked as expected
The below call roughly does the same thing:
return this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/web/lists/GetByTitle('MyList')/items`, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
return response.json();
});Can you double check that you have the latest version of the pnp modules?
I can't see much of a difference between your code and my code.
Apparently there are some additional instuctions required for the PnP JS and SPFx to play nicely with one another. Thanks to Patrick Rodgers for pointing me to the missing key described in https://github.com/SharePoint/PnP-JS-Core/wiki/Using-sp-pnp-js-in-SharePoint-Framework#establish-context.
A single call in the onInit() method override does the trick:
@override
public onInit(): Promise<void> {
return super.onInit().then(_ => {
//--- ensure that the current web is used for all pnp calls
pnp.setup({
spfxContext: this.context
});
});
}The REST call is now forming properly. It sure would be nice to have complete, organized documentation all together in ONE PLACE. :)
Thanks again for your interest and assistance.