Skip to content

New command: Add SharePoint List Items in a Batch #2029

@garrytrinder

Description

@garrytrinder

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.

Usage

spo listitem batch add [options]

Description

Creates list items in a batch

Options

Option Description
-p, --filePath <path> The absolute or relative path to a flat file containing list items to be created
-u, --webUrl [webUrl] The URL of the site where the items should be added
-l, --listId [listId] The 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

Additional Information

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.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions