应用$ filter选项以在Graph API中检索具有特定名称的文件夹

时间:2018-08-07 12:28:26

标签: microsoft-graph

以下过滤器子句在Graph Explorer中不起作用

https://graph.microsoft.com/v1.0/drives?$ filter = name eq'文档'

由于指定的过滤器符合OData协议,因此过滤器的应用是否存在限制

2 个答案:

答案 0 :(得分:0)

OneDrive API(和驱动器上的Graph API)不支持过滤或排序结果。 当Microsoft Graph看到它不期望的查询参数时,它只是忽略未知的过滤器参数,并向我们返回未过滤的结果。 drives api支持使用$ expand,$ select,$ skipToken,$ top和$ orderby(orderby在我这边不起作用)OData查询参数来自定义响应。

我的测试数据: https://graph.microsoft.com/v1.0/drives?$ filter = name eq'Documents'/ $ filter = driveType eq'documentLibrary'“:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
    "value": [
        {
            "createdDateTime": "2018-06-04T07:32:28Z",
            "description": "List of all app packages uploaded in the Dev Site",
            "id": "b!NEuoD0E0IkyGzigmyNtKyXtJFUgDWoBJhM2BFIAvNsp69o2q1-czTaV6INjgi_dk",
            "lastModifiedDateTime": "2018-06-05T04:19:59Z",
            "name": "App Packages",
            "webUrl": "https://xxxx.sharepoint.com/Lists/AppPackages",
            "driveType": "documentLibrary",
            "createdBy": {
                "user": {
                    "displayName": "System Account"
                }
            },
            "quota": {
                "deleted": 0,
                "remaining": 0,
                "total": 0,
                "used": 0
            }
        } 
    ]
}

答案 1 :(得分:0)

似乎使用较新的版本,您可以使用FileName或FileType搜索https://docs.microsoft.com/en-us/microsoft-365/compliance/keyword-queries-and-search-conditions?view=o365-worldwide#searchable-site-properties

{"requests":[{"entityTypes":["microsoft.graph.driveItem"],"query":{"query_string":{"query":"fileextension:xlsx"}},"from":0,"size":25}]}