Skip to content

docs: fix the 'list all items in a drive' sample (#1070) - #1572

Open
eduardarbona (earbona23) wants to merge 1 commit into
microsoftgraph:mainfrom
earbona23:docs/fix-list-all-drive-items-sample
Open

docs: fix the 'list all items in a drive' sample (#1070)#1572
eduardarbona (earbona23) wants to merge 1 commit into
microsoftgraph:mainfrom
earbona23:docs/fix-list-all-drive-items-sample

Conversation

@earbona23

Copy link
Copy Markdown

Fixes #1070 (and the earlier #365, which was closed without a fix).

The bug

Sample 3 in docs/drives_samples.md was:

items = await client.drives.by_drive_id('DRIVE_ID').items.get()   # GET /drives/{id}/items

GET /drives/{id}/items is not an enumerable collection in Microsoft Graph — it
addresses driveItems by id and only answers $filter queries — so following the sample
returns exactly the error nine people reacted to:

The 'filter' query option must be provided.

The SDK and Graph are both behaving correctly; the sample documented a call that cannot
work. #365 reported this and was closed with no fix while the broken sample stayed in place.

The fix

Sample 3 now does what its title says — list all the items — by walking root with
delta and paging through odata_next_link:

page = await client.drives.by_drive_id('DRIVE_ID').items.by_drive_item_id('root').delta.get()
while page:
    if page.value:
        for item in page.value:
            print(item.id, item.name, item.size, item.folder, item.file)
    if not page.odata_next_link:
        break
    page = await client.drives.by_drive_id('DRIVE_ID').items.by_drive_item_id('root').delta.with_url(page.odata_next_link).get()

This also removes an overlap: as written, sample 3 duplicated sample 6 (which lists only the
top level via root/children). Now 3 is the recursive listing and 6 is the top-level one,
with a cross-reference between them so the distinction is explicit.

Verified against the generated SDK in this repo

  • items.by_drive_item_id('root').deltamsgraph/generated/drives/item/items/item/delta/delta_request_builder.py
  • .with_url() for paging — same file, line 65
  • odata_next_link and value on the response — inherited from BaseDeltaFunctionResponse (msgraph/generated/models/base_delta_function_response.py:18)
  • the snippet parses as valid Python

Docs-only, one file. I did not run it against a live drive (no tenant), so if a maintainer
runs it and sees anything off with the paging, tell me and I will adjust — but every symbol
it uses is confirmed present in the generated client.

…microsoftgraph#365)

Sample 3 called `client.drives.by_drive_id(id).items.get()`, i.e. `GET /drives/{id}/items`.
That path is not an enumerable collection in Microsoft Graph — it addresses driveItems by id
and only answers `$filter` queries — so the sample fails at runtime with
`The 'filter' query option must be provided.` This has been reported repeatedly (microsoftgraph#365, closed
without a fix, and microsoftgraph#1070 with nine reactions), while the broken sample stayed in the docs.

Replace it with a correct, and now distinct, sample: enumerate every item in the drive by
walking `root` with `delta`, paging through `odata_next_link`. That matches the section's
title ("list ALL the items") and no longer overlaps with sample 6, which lists only the top
level via `root/children`. A cross-reference between the two makes the distinction explicit.

Verified against the generated SDK in this repo: `items.by_drive_item_id('root').delta`, its
`with_url()` for paging, and `odata_next_link` / `value` on the delta response all exist. The
snippet parses as valid Python.
@earbona23
eduardarbona (earbona23) requested a review from a team as a code owner September 2, 2026 02:26
@earbona23

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: The 'filter' query option must be provided.

1 participant