Skip to content

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

Closed

Description

@stvpwrs

Hello,

I'm sure some of the issues I'm seeing are a lack of understanding how this library works. I'm trying to understand the patterns that have to be in place, but when I run the following code I get this odd error that the Error: The 'filter' query option must be provided. and I don't understand why I have to pass a filter.

items = await client.drives.by_drive_id(drive.id).items.get()

If I do pass a filter in I then get Error: Expand cannot be null or empty.. I'm a bit at a loss of what's going on here.

Activity

  1. justmike1 commented on Oct 19, 2023

    @justmike1

    hey, did you solve it? I am having the same issue

  2. glinft commented on Oct 24, 2023

    @glinft

    Did you solve it?
    I am having the same issue today.

  3. stvpwrs commented on Nov 14, 2023

    @stvpwrs
    Author

    No luck Mike J (@justmike1) and Glenn (@glinft). I don't think that code is actually valid, but it did appear in some samples at one point.

  4. andrueastman commented on Apr 3, 2024

    @andrueastman
    Contributor

    Thanks for raising this Steve Powers (@stvpwrs)

    The drive api does not support listing items from the items segment.

    Any chance the documentation below is helpful?
    https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=http

  5. kristianandre commented on Aug 2, 2024

    @kristianandre

    I find it very strange that several users, me included, have copied one of the few code samples in this repo, and it doesn't work. My conclusion so far is that it's a lot more clunky and hard to work with the Python SDK instead of doing requests directly to the Graph API. How can one find files by relative path for example? It seems like one needs to acquire the ids of every drive, site and item one wants to request, but that gets challenging when the code samples to get those ids don't work.

    Andrew Omondi (@andrueastman) In the link you sent under this section, the HTTP tab correctly shows how to list files in the root of a drive. However, the Python tab is identical to the one in section "List children of a DriveItem with a known ID" that requires one to get a DriveItem id first. While there is no Python version for "known path".

    More working code samples would be greatly appreciated.

  6. venukalam commented on Dec 4, 2024

    @venukalam

    This example in the docs is still outdated. It’s confusing and wasting a ton of people’s time.

  7. pierremonico commented on Dec 11, 2024

    @pierremonico

    Even better on my end: I get the same error, but when I pass in the $filter query param, although it now works, the queries actually have no effect, all items are returned.

  8. alesposto commented on Dec 12, 2024

    @alesposto

    Pierre Monico (@pierremonico) did you fix it? Can you explain what did you change? Ty

  9. ThongLai commented on Dec 30, 2024

    @ThongLai

    I believe you followed the sample provided here: https://github.com/microsoftgraph/msgraph-sdk-python/blob/main/docs/drives_samples.md.

    Specifically, the method client.drives.by_drive_id('DRIVE_ID').items.get() in section 3. LIST ALL THE ITEMS IN A DRIVE is not working.
    So instead, you can use the method from section 6. GET ITEMS IN THE ROOT FOLDER OF THE DRIVE: client.drives.by_drive_id('DRIVE_ID').items.by_drive_item_id('root').children.get()

    Differences Between Methods
    As I could not test on .items.get(). However, I believe:

    • .items.get() returns a FLAT LIST of ALL files and folders
    • .items.by_drive_item_id('root').children.get() returns only the children of the root folder.

    For example, with this structure:

    Root/
      ├── File1.txt
      ├── Folder1/
      │   └── File2.txt
      └── File3.txt
    
    • Using .items.get() (will produce an error), I assume it is intended to return: File1.txt, Folder1, File2.txt, File3.txt
    • Using .items.by_drive_item_id('root').children.get(), it would return only: File1.txt, Folder1, File3.txt
      (As File2.txt is in Folder1 not root)

    If you still want to get a flat list of all drive items, you can use .items.by_drive_item_id('root').children.get() and then loop through all the found folders.

    At least for now, this is the only solution I have come up with. Please let me know if there's a fix for this!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions