Raised from #1203
Proposal
The spo listitem add command should allow users to create multiple SharePoint List Items without having to execute the same command multiple times.
If you need to create a couple of items this most likely is not an issue but we should consider scenarios where hundreds or even thousands of items need to be created. At the moment the automation script required to perform this action would run into hundreds and thousands of lines.
To address this issue, it is proposed that a new command be created under spo listitem called batch with a sub commands for add, i.e. spo listitem batch add, that takes a definition file (initially txt or csv) as an input which describes each item to be created when the command is executed.
Example: spo listitem batch add --filePath listitems.csv
This approach would then allow us to further expand the batch command with more sub commands to cover remove, update and get should the need arise.
Once the approach is validated, we could implement it on other types like file, list, field, file, etc.
Based on research by @waldekmastykarz using the Microsoft Graph batched requests would provide the best performance, therefore we should look to use this in our implementation.
spo listitem batch add [options]
Creates list items in a batch
| Option | Description |
| ----------------------- | ----------------------------------------- |
| -p, --filePath <path> | Absolute or relative path to a flat file containing list items to be created |
| -u, --webUrl [webUrl] | URL of the site where the items should be added |
| -l, --listId [listId] | ID of the list where the items should be added. Specify listId or listTitle but not both |
| -t, --listTitle [listTitle] | Title of the list where the items should be added. Specify listId or listTitle but not both |
Based on research by @waldekmastykarz the fastest way to create multiple items is to use Microsoft Graph batched requests, see: https://blog.mastykarz.nl/fastest-way-create-sharepoint-list-items/
For the initial implementation, consider the below csv format to be passed into the command to create multiple list items by executing a single command.
contentType,listTitle,webUrl,Title
Item,Demo List,https://contoso.sharepoint.com/sites/project-x,Demo Item 1
Item,Demo List,https://contoso.sharepoint.com/sites/project-x,Demo Item 2
Item,Demo List,https://contoso.sharepoint.com/sites/project-x,Demo Item 3
...
Title in the above example, represents a single line of text field, however we should support additional fields and different field types as we currently do with the spo listitem add command.
If --webUrl, --listId or --listTitle are defined then these values should apply to all items stated in the CSV.
For completeness, let's include options for specifying web and list. Other than that 馃殌
Thanks @waldekmastykarz updated spec.