Skip to content

Enhancement: allow spo listitem list to retrieve all items in a list #4697

@martinlingstuyl

Description

@martinlingstuyl

The spo listitem list can be used to return items in a list.

Currently, this command returns a 100 items by default (which is the REST API default), except when using the pageSize and pageNumber options, with these you can maximize the amount returned to max 500 per request. But there's always just one request. If I want to retrieve all items in a list I'd have to build a script to follow each skiptoken.

As an enhancement I'd like to be able to retrieve all items using just the single m365 command.

Implementation

Let's get all items by default and add additional explanation in the docs on how to use this. If people just want the first 100 items, they have to specify the --pageNumber and the --pageSize property.

1. Default (with or without --filter)

In this scenario, the CLI uses the /items endpoint, which accepts $top, and also has nextlink functionality. We can simply use the oData.getAllItems() method in the CLI Codebase to follow every nextlink until we have all items.

2. Using CAML Query

When you specify --camlQuery another endpoint is used. The CAML Query endpoint (/GetItems) does not have nextlink functionality. However, you can add a RowLimit node and set the ListItemCollectionPosition like in CSOM for .NET to skip an amount of items. Additionally, we need an AllowIncrementalResults property as well.

The following query gets 10 items and skips items with ID 1-10. This is similar to how nextlinks work:

{
    "query": {
      "ViewXml": "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>Some title</Value></Eq></Where></Query><RowLimit>10</RowLimit></View>",
      "ListItemCollectionPosition": {
        "PagingInfo": "Paged=TRUE&p_ID=10"
        }
      "AllowIncrementalResults": true
    }
  }

For this scenario the user will be in control of adding the RowLimit node. However, we can always get the last ID from the retrieved items list and use that as PagingInfo for the next request until 0 items are returned.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions