Add new list item to the specified list
spo listitem add -w|--webUrl <webUrl> -l|--listId [listId] --listTitle [listTitle] -c|--contentType [contentType] -f|--folder [folder] ...For more information see the Add-PnPListItem cmdlet
Hey there @waldekmastykarz - mind if I have a go at developing this command?
first time contributor here, btw :)
Awesome! Appreciate you reaching out. All yours and please don't hesitate to reach out if you have questions or need any help. 馃殌
@waldekmastykarz, the Add-PnPListItem powershell cmdlet has an "EnsureFolder" call when folder is specified in the parameters. "EnsureFolder" would also be useful for file provisioning scenarios; should I split this out into a separate command? If so, is this how it should be described:
spo folder ensure -w|--webUrl <webUrl> -l|--listId [listId] --listTitle [listTitle] -f|--folder [folder]Also, I have found the SPO modern UI uses the following endpoints to create folders, and create list items:
/_api/web/GetFolderByServerRelativePath(DecodedUrl=@a1)/AddSubFolderUsingPath(DecodedUrl=@a2) to add folders - documented here/_api/web/lists/GetByTitle('List Title')/AddValidateUpdateItemUsingPath() to create list items - can't find it documentedConsidering the lack of documentation for AddValidateUpdateItemUsingPath(), should I use it? If not, is there another REST endpoint that allows creating of list items with paths? I tried a post to /_api/web/lists/GetByTitle('List Title')/items but it doesn't seem to have a ParentPath parameter for creating items in folders. I think pnp cmdlets use CSOM which is a ProcessQuery request.
FYI - I've pushed my progress, including a working implementation using the AddValidateUpdateItemUsingPath() method, here. Writing of unit tests remains.
the Add-PnPListItem powershell cmdlet has an "EnsureFolder" call when folder is specified in the parameters. "EnsureFolder" would also be useful for file provisioning scenarios; should I split this out into a separate command?
Calling one command from another is not trivial because the underlying surface keeps track of active commands, history, etc. We could centralize the code to avoid duplication, but we can get to that when implementing the folder command. For now, we can put it in a separate method inside the command class and we'll look into refactoring later.
Considering the lack of documentation for AddValidateUpdateItemUsingPath(), should I use it?
Let me get back to you on that one. It could be that this API is meant for internal use. Worst case we can use either that or mimic the CSOM call used by PnP PowerShell.
So I have an update on AddValidateUpdateItemUsingPath(). At this moment it's not documented, meaning not officially supported for 3rd party use. We're looking into the possibility to open it up for third parties but that could take a while. Let's keep using it for now. If we hear that it's not officially supported for 3rd parties after all, we can always consider switching to mimicking CSOM.
@mpowney, got another update on the AddValidateUpdateItemUsingPath() method. It's now officially documented and fully supported for use by third parties (docs available at https://github.com/SharePoint/sp-dev-docs/blob/master/docs/sp-add-ins/working-with-lists-and-list-items-with-rest.md#create-list-item-in-a-folder and will be published soon). We're good to go. Once again thanks for pointing it out 馃憤
How to update User field (single or multi) using AddValidateUpdateItemUsingPath() method? I cannot find any information about this.
@TomekPi You should use ValidateUpdateListItem() instead when you want to Update a User field, or any other field. I am implementing this at the moment in the spo file add command where you are able to upload a new file and set list item properties. In first place I was also looking at this AddValidateUpdateItemUsingPath() method and pulling my hear out, but eventually found this one for updates.
You could then use a command parameter like:
--SinglePeopleField "[{'Key':'i:0#.f|membership|[email protected]'}]"
Got this from @mpowney spo list add command.
Thanks @rfjschouten , it's working!
That's exactly what I was looking for: the syntax "[{'Key':'loginName'}]" .
I was trying to update User field from sample react-listForm and this did the trick.
Great @TomekPi ! Good to hear it is working! Earnings to @mpowney for sorting this out...
@rfjschouten Thanks, it's working for single user filed but what about multi user field. Please help.
@Sumitrpareek let鈥檚 create a new issue for your question to make it more visible to the community.
Most helpful comment
You could then use a command parameter like:
--SinglePeopleField "[{'Key':'i:0#.f|membership|[email protected]'}]"
Got this from @mpowney spo list add command.