Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions docs/drives_samples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down