From 31b4fef7db03eba74f4ca3aedfc4972edf11042a Mon Sep 17 00:00:00 2001 From: Eduard Arbona <175124143+earbona23@users.noreply.github.com> Date: Tue, 1 Sep 2026 22:25:23 -0400 Subject: [PATCH] docs: fix the "list all items in a drive" sample (#1070, #365) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (#365, closed without a fix, and #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. --- docs/drives_samples.md | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/docs/drives_samples.md b/docs/drives_samples.md index 85b51bb9715..bc4474b1224 100644 --- a/docs/drives_samples.md +++ b/docs/drives_samples.md @@ -39,17 +39,29 @@ async def get_drive(): asyncio.run(get_drive()) ``` -## 3. LIST ALL THE ITEMS IN A DRIVE (GET /drives/{id}/items) +## 3. LIST ALL THE ITEMS IN A DRIVE, RECURSIVELY (GET /drives/{id}/items/root/delta) + +`GET /drives/{id}/items` is not an enumerable collection in Microsoft Graph — it addresses +items by id and only answers `$filter` queries, so calling it without a filter returns +`The 'filter' query option must be provided.` To enumerate every item in a drive, walk the +tree from the root with `delta`, which pages through the whole drive: ```py -async def get_drive_items(): - items = await client.drives.by_drive_id('DRIVE_ID').items.get() - if items and items.value: - for item in items.value: - print(item.id, item.name, item.size, item.folder, item.file) -asyncio.run(get_drive_items()) +async def get_all_drive_items(): + 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() +asyncio.run(get_all_drive_items()) ``` +To list only the top level of the drive rather than recursing, use the `root/children` +sample below (section 6). + ## 4. GET AN ITEM IN THE DRIVE (GET /drives/{id}/items/{id}) ```py