Pnpjs: Code specified in the PnP Js documentation does not work.

Created on 29 Aug 2019  路  4Comments  路  Source: pnp/pnpjs

Category

  • [x] Documentation gap/issue

Version

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

Please specify what version(s) of SharePoint you are targeting: [ SharePoint Online ]

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

Observed Behavior

The code specified in the documentation does not work. Throws an error. After making certain changes, it does work. Code sample provided below.
Link to documentation - https://pnp.github.io/pnpjs/graph/docs/sites/#create-item

Steps to Reproduce

// This is specified in the document, which doesn't work
import { graph } from "@pnp/graph";

const newItem = await graph.sites.getById('contoso.sharepoint.com').lists.getById('listId').items.create({
"fields": {
    "Title": "Widget",
    "Color": "Purple",
    "Weight": 32
  }
})
// This works, either the documentation or the code need to be changed
import { graph } from "@pnp/graph";

const newItem = await graph.sites.getById('contoso.sharepoint.com').lists.getById('listId').items.create({
    "Title": "Widget",
    "Color": "Purple",
    "Weight": 32
})

Thank you community for the awesome work.

documentation fixed bug

Most helpful comment

Thanks, got this updated. Appreciate you letting us know.

All 4 comments

@Ramakrishnan24689 - I experienced same issue and below code worked for me.

Here is the issue link https://github.com/pnp/pnpjs/issues/755 which I raised earlier.

const newItem = await graph.sites.getById('contoso.sharepoint.com').lists.getById('listId').items.create(<any>{
    Title: "Widget",
    Color: "Purple",
    Weight: 32,
});

@narulasrinivas : The reason I posted this is to fix the documentation gap or issue. A workaround was posted in my initial conversation as well. Thank you.

@Ramakrishnan24689 - Sorry my bad. I missed out that bit. This change is going to be updated in v2 version docs.

Thanks, got this updated. Appreciate you letting us know.

Was this page helpful?
0 / 5 - 0 ratings