首页 > 解决方案 > Microsoft Graph API 查询因提供的筛选器而失败

问题描述

在我的 .NET 应用程序中,我正在尝试使用 Microsoft Graph API 从 Azure AD B2C 获取用户。我还想根据自定义用户属性过滤这些用户。

我已经建立了这个网址

https://graph.microsoft.com/v1.0/users?$select=extension_{Id}_lastUpdatedDate&$filter=extension_{Id}_lastUpdatedDate eq '2019-08-10'

这会返回 400 错误,extension_{Id}_lastUpdatedDate说不存在

{
  "error": {
    "code": "Request_UnsupportedQuery",
    "message": "Property 'extension_{Id}_lastUpdatedDate' does not exist as a declared property or extension property.",
    "innerError": {
      "request-id": "a925b2f4-fef8-47a1-b644-9b2e652f1746",
      "date": "2019-09-13T14:14:00"
    }
  }
}

但是,当我发送完全相同的请求时,除了查询的过滤器部分,就像这样

https://graph.microsoft.com/v1.0/users?$select=extension_{Id}_lastUpdatedDate

我收到 200 的结果,听起来该字段存在并且为 AD 中的所有用户正确填写

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(extension_{Id}_lastUpdatedDate)",
    "value": [
        {"extension_{Id}_lastUpdatedDate": "2018-07-12T14:31:47.208Z"}, 
        {"extension_{Id}_lastUpdatedDate": "2018-05-30T14:28:47.208Z"}, 
        {"extension_{Id}_lastUpdatedDate": "2018-06-30T14:28:47.208Z"}, 
        {"extension_{Id}_lastUpdatedDate": "2018-07-30T14:28:47.208Z"}, 
        {"extension_{Id}_lastUpdatedDate": "2018-08-30T14:28:47.208Z"}, 
        {"extension_{Id}_lastUpdatedDate": "2018-07-12T14:31:47.208Z"}, 
        {"extension_{Id}_lastUpdatedDate": "2018-07-30T14:31:47.208Z"}, 
        {"extension_{Id}_lastUpdatedDate": "2018-07-30T14:31:47.208Z"}
    ]
}

有谁知道这里发生了什么?如果我看到选择查询中的字段,错误消息所说的内容对我来说几乎是不可能的。

标签: .netazure-active-directorymicrosoft-graph-apiazure-ad-b2c

解决方案


我遇到了同样的问题。API 在 $filter 函数中区分大小写,但在 $select 函数中不区分大小写。因此,请确保您的 $filter 具有区分大小写的正确名称。

这不起作用:

https://graph.microsoft.com/v1.0/users?$select=extension_{id}_tenantId,displayName&$filter=extension_{id}_tenantId eq 1

这有效:

https://graph.microsoft.com/v1.0/users?$select=extension_{id}_tenantId,displayName&$filter=extension_{id}_TenantId eq 1

推荐阅读