I am making a graphi api search call on driveItem and the result is having both files and folders. How do i differentiate between the files and folders? I only want to folder not documents

Manohar onmi 0 Reputation points
2025-01-30T08:53:44.5+00:00
{
    "requests": [
        {
            "entityTypes": [
                "driveItem"
            ],
            "query": {
                "queryString": "test folder"
            }
        }
    ]
}
{
    "value": [
        {
            "searchTerms": [
                "test"
            ],
            "hitsContainers": [
                {
                    "hits": [
                        {
                            "hitId": "01B5TYRY2IKYVGDJW4XNEISAF5IGOXNJTN",
                            "rank": 1,
                            "summary": "",
                            "resource": {
                                "@odata.type": "#microsoft.graph.driveItem",
                                "size": 0,
                                "fileSystemInfo": {
                                    "createdDateTime": "2025-01-10T09:11:44Z",
                                    "lastModifiedDateTime": "2025-01-10T09:11:44Z"
                                },
                                "listItem": {
                                    "@odata.type": "#microsoft.graph.listItem",
                                    "id": "612a5648-dca6-48bb-8900-bd419d76a66d",
                                    "fields": {}
                                },
                                "id": "01B5TYRY2IKYVGDJW4XNEISAF5IGOXNJTN",
                                "createdBy": {
                                    "user": {
                                        "displayName": "Manohar Sompalli",
                                        "email": "******@w41w3.onmicrosoft.com"
                                    }
                                },
                                "createdDateTime": "2025-01-10T09:11:44Z",
                                "lastModifiedBy": {
                                    "user": {
                                        "displayName": "Manohar Sompalli",
                                        "email": "******@w41w3.onmicrosoft.com"
                                    }
                                },
                                "lastModifiedDateTime": "2025-01-10T09:11:44Z",
                                "name": "test folder",
                                "parentReference": {
                                    "driveId": "b!DiL9LymYQkK8rpw3DSEl90mffvczxepJl2OByfhDqgcP5BdpyQQjRrD1xPlMPCjo",
                                    "id": "01B5TYRYZNXUYFHIWOVJG3EMLBQUMYI2U2",
                                    "sharepointIds": {
                                        "listId": "6917e40f-04c9-4623-b0f5-c4f94c3c28e8",
                                        "listItemId": "3",
                                        "listItemUniqueId": "612a5648-dca6-48bb-8900-bd419d76a66d"
                                    },
                                    "siteId": "w41w3.sharepoint.com,2ffd220e-9829-4242-bcae-9c370d2125f7,f77e9f49-c533-49ea-9763-81c9f843aa07"
                                },
                                "webUrl": "https://w41w3.sharepoint.com/Shared Documents/test folder"
                            }
                        },
                        {
                            "hitId": "01LODBMYOE5TAQBVOLVFHZ7DZGFUYPAGWB",
                            "rank": 2,
                            "summary": "",
                            "resource": {
                                "@odata.type": "#microsoft.graph.driveItem",
                                "size": 0,
                                "fileSystemInfo": {
                                    "createdDateTime": "2024-07-17T09:24:36Z",
                                    "lastModifiedDateTime": "2024-07-17T09:24:36Z"
                                },
                                "listItem": {
                                    "@odata.type": "#microsoft.graph.listItem",
                                    "id": "00c1ecc4-cbd5-4fa9-9f8f-262d30f01ac1",
                                    "fields": {}
                                },
                                "id": "01LODBMYOE5TAQBVOLVFHZ7DZGFUYPAGWB",
                                "createdBy": {
                                    "user": {
                                        "displayName": "SharePoint App"
                                    }
                                },
                                "createdDateTime": "2024-07-17T09:24:36Z",
                                "lastModifiedBy": {
                                    "user": {
                                        "displayName": "SharePoint App"
                                    }
                                },
                                "lastModifiedDateTime": "2024-07-17T09:24:36Z",
                                "name": "XT1050 Usability test 2.3.docx",
                                "parentReference": {
                                    "driveId": "b!fHLEU38RvEqQciyesaSoKfyPVNGw-yBOhlwY37gZWMVwBeqZNT1FSouw8fO2Aimd",
                                    "id": "01LODBMYPRBJX2AP7Y65BIAQFQDGFKIZYE",
                                    "sharepointIds": {
                                        "listId": "99ea0570-3d35-4a45-8bb0-f1f3b602299d",
                                        "listItemId": "4",
                                        "listItemUniqueId": "00c1ecc4-cbd5-4fa9-9f8f-262d30f01ac1"
                                    },
                                    "siteId": "w41w3.sharepoint.com,53c4727c-117f-4abc-9072-2c9eb1a4a829,d1548ffc-fbb0-4e20-865c-18dfb81958c5"
                                },
                                "webUrl": "https://w41w3.sharepoint.com/sites/Mark8ProjectTeam535/Shared Documents/General/XT1050 Usability test 2.3.docx"
                            }
                        },
                        {
                            "hitId": "01KJNYKYNOXSRXWUSEKVAIZ24HRGTEEJVA",
                            "rank": 3,
                            "summary": "05/02/2020 CS265: Data Systems daslab.seas.harvard.edu/classes/cs265/project.html 1/8 CS265 Spring 2020 Systems Project: An LSM-tree based key-value store 1. Introduction The<ddd/>",
                            "resource": {
                                "@odata.type": "#microsoft.graph.driveItem",
                                "size": 286428,
                                "fileSystemInfo": {
                                    "createdDateTime": "2025-01-02T05:39:33Z",
                                    "lastModifiedDateTime": "2020-02-06T01:02:59Z"
                                },
                                "listItem": {
                                    "@odata.type": "#microsoft.graph.listItem",
                                    "id": "7ba3bcae-4452-4055-8ceb-8789a64226a0",
                                    "fields": {}
                                },
                                "id": "01KJNYKYNOXSRXWUSEKVAIZ24HRGTEEJVA",
                                "createdBy": {
                                    "user": {
                                        "displayName": "Manohar Sompalli",
                                        "email": "******@w41w3.onmicrosoft.com"
                                    }
                                },
                                "createdDateTime": "2025-01-02T05:39:33Z",
                                "lastModifiedBy": {
                                    "user": {
                                        "displayName": "Manohar Sompalli",
                                        "email": "******@w41w3.onmicrosoft.com"
                                    }
                                },
                                "lastModifiedDateTime": "2020-02-06T01:02:59Z",
                                "name": "hvard-lsm-project.pdf",
                                "parentReference": {
                                    "driveId": "b!axJ6LuGrp06mU67mQeVBrzFvQsPsujpIhPqaxoAwsQnhjt-tPoSEQJy9OuAlojEA",
                                    "id": "01KJNYKYI6EGRMDVUXXNCK45CXWGOIRQAA",
                                    "sharepointIds": {
                                        "listId": "addf8ee1-843e-4084-9cbd-3ae025a23100",
                                        "listItemId": "71",
                                        "listItemUniqueId": "7ba3bcae-4452-4055-8ceb-8789a64226a0"
                                    },
                                    "siteId": "w41w3.sharepoint.com,2e7a126b-abe1-4ea7-a653-aee641e541af,c3426f31-baec-483a-84fa-9ac68030b109"
                                },
                                "webUrl": "https://w41w3.sharepoint.com/sites/communication-assembly/Shared Documents/Documents/hvard-lsm-project.pdf"
                            }
                        },
                        {
                            "hitId": "01KJNYKYOSY4DKQNZBKZHZ2W5IJGZEQDLL",
                            "rank": 4,
                            "summary": "<ddd/><c0>test</c0>. Override the digital divide with additional clickthroughs from DevOps. <ddd/>",
                            "resource": {
                                "@odata.type": "#microsoft.graph.driveItem",
                                "size": 38729,
                                "fileSystemInfo": {
                                    "createdDateTime": "2024-08-01T04:54:03Z",
                                    "lastModifiedDateTime": "2024-08-01T04:54:03Z"
                                },
                                "listItem": {
                                    "@odata.type": "#microsoft.graph.listItem",
                                    "id": "a806c7d2-2137-4f56-9d5b-a849b2480d6b",
                                    "fields": {}
                                },
                                "id": "01KJNYKYOSY4DKQNZBKZHZ2W5IJGZEQDLL",
                                "createdBy": {
                                    "user": {
                                        "displayName": "Manohar Sompalli",
                                        "email": "******@w41w3.onmicrosoft.com"
                                    }
                                },
                                "createdDateTime": "2024-08-01T04:54:03Z",
                                "lastModifiedBy": {
                                    "user": {
                                        "displayName": "Manohar Sompalli",
                                        "email": "******@w41w3.onmicrosoft.com"
                                    }
                                },
                                "lastModifiedDateTime": "2024-08-01T04:54:03Z",
                                "name": "World_Wide_Corp_lorem.pdf",
                                "parentReference": {
                                    "driveId": "b!axJ6LuGrp06mU67mQeVBrzFvQsPsujpIhPqaxoAwsQnhjt-tPoSEQJy9OuAlojEA",
                                    "id": "01KJNYKYOYUTPKDFQXAFCKZ3MJXRU46NUD",
                                    "sharepointIds": {
                                        "listId": "addf8ee1-843e-4084-9cbd-3ae025a23100",
                                        "listItemId": "62",
                                        "listItemUniqueId": "a806c7d2-2137-4f56-9d5b-a849b2480d6b"
                                    },
                                    "siteId": "w41w3.sharepoint.com,2e7a126b-abe1-4ea7-a653-aee641e541af,c3426f31-baec-483a-84fa-9ac68030b109"
                                },
                                "webUrl": "https://w41w3.sharepoint.com/sites/communication-assembly/Shared Documents/app/static/demo_documents/World_Wide_Corp_lorem.pdf"
                            }
                        }
                    ],
                    "total": 4,
                    "moreResultsAvailable": false
                }
            ]
        }
    ],
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(microsoft.graph.searchResponse)"
}
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,376 Reputation points
    2025-01-30T10:07:48.01+00:00

    Hi @Manohar onmi

    As far as I know, there is no way to filter out folders directly via the search API, you can only check if the object in the response contains a folder property. In the response, folders will have a folder property, but files will not. You can filter out folders by checking this property. Here is an example response:

    {
        "value": [
            {
                "name": "Folder1",
                "folder": {}  // This indicates it's a folder
            },
            {
                "name": "File1",
                "file": {}  // This indicates it's a file
            }
        ]
    }
    

    If you only want to get folders, then I recommend using the Drive API.

    GET /me/drive/root/children?$filter=folder ne null
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.