1

I've been trying to search within a specific DriveItem folder but I've been having some troubles. First of all, despite the API stating that "You can search within a folder hierarchy, a whole drive, or files shared with the current user.", I haven't found any documentation supporting this. I have found this stackoverflow reply that describes how to do it. Unfortunately, it doesn't to be working very well.

Since I don't know how sensitive IDs are, I'll be redacting them in my examples.

https://graph.microsoft.com/v1.0/me/drive/items/<id_parent_folder>/children?select=name

This request returns all files inside the folder I want to search and it does list everything inside the folder. The response is something like:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('<id_user>')/drive/items('<id_parent_folder>')/children(name)",
    "value": [
        {
            "@odata.etag": "\"{redacted1},1\"",
            "name": "automation_csv.csv"
        },
        {
            "@odata.etag": "\"{redacted2},1\"",
            "name": "HOSPITAIS_PT.cpg"
        },
        {
            "@odata.etag": "\"{redacted3},1\"",
            "name": "HOSPITAIS_PT.dbf"
        },
        {
            "@odata.etag": "\"{redacted4},1\"",
            "name": "HOSPITAIS_PT.prj"
        },
        {
            "@odata.etag": "\"{redacted5},1\"",
            "name": "HOSPITAIS_PT.qpj"
        },
        {
            "@odata.etag": "\"{redacted6},1\"",
            "name": "HOSPITAIS_PT.shp"
        },
        {
            "@odata.etag": "\"{redacted7},1\"",
            "name": "HOSPITAIS_PT.shx"
        }
    ]
}

However, when searching inside the folder I only get the CSV file....

https://graph.microsoft.com/v1.0/me/drive/items/<id_parent_folder>/search(q='')?select=name

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
    "value": [
        {
            "@odata.type": "#microsoft.graph.driveItem",
            "name": "<name_parent_folder>"
        },
        {
            "@odata.type": "#microsoft.graph.driveItem",
            "name": "automation_csv.csv"
        }
    ]
}

Searching for any other file name produces no results.

Is this a bug or a feature? Is there another endpoint that allows me to search all files inside a folder?

EDIT: changed the "beta" endpoint to "v1.0", though they produce the same results. Just don't want to create the assumption that it only happens in the beta endpoint.

Cosme Benito
  • 125
  • 2
  • 13

1 Answers1

0

Use the Microsoft Query API to search instead of using q search parameter. See https://learn.microsoft.com/en-us/graph/api/resources/search-api-overview?view=graph-rest-beta

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 08 '22 at 08:23
  • I've been trying to make this API work but unfortunately it has a major flaw: it lists deleted items. There's no property or search refinement I can use to exclude the deleted items. The results are cohered with using the search functionality in the One Drive website but unfortunately I need to list results that actually exist. – Cosme Benito Feb 02 '22 at 12:04