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