Question

I am trying out pnpjs USING SharePoint framework and adding new item to my list.

But when I try to gulp serve and run it inside my SharePoint Online

const iar: IItemAddResult = await sp.web.lists.getByTitle(ListName).items.add({
    Title: "Title",
})

When I try to run its trying to get the information in my list but it has "_layouts/15" on it.

[O365Url]/sites/LimitTester/_layouts/15/_api/web/lists/getByTitle('CrudTestOnly')?$select=ListItemEntityTypeFullName
Was it helpful?

Solution

Need to set up correct spfxContent like this in WebPartName.ts:

public onInit(): Promise<void> {

  return super.onInit().then(_ => {

    // other init code may be present

    sp.setup({
      spfxContext: this.context
    });
  });
}

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top