microsoft-graph-api - 架构扩展 : "Unsupported or invalid query filter clause specified for property ' companyName' of resource 'User' .“

标签 microsoft-graph-api microsoft-graph-sdks

我目前正在构建一个应用程序,它要求我根据自定义属性从 Graph API 检索用户,在这种情况下,extoe82ql2v_test/companyName 但到目前为止,API 响应为 为资源“用户”的属性“公司名称”指定的查询过滤器子句不受支持或无效。”

检索扩展的请求:

https://graph.microsoft.com/v1.0/schemaExtensions?$filter=id eq 'extoe82ql2v_test'

结果:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions",
    "value": [
        {
            "id": "extoe82ql2v_test",
            "description": "Extend data for users",
            "targetTypes": [
                "User"
            ],
            "status": "InDevelopment",
            "owner": "d9a847ce-ca03-4779-88d6-c7e4f98297fe",
            "properties": [
                {
                    "name": "companyName",
                    "type": "String"
                },
                {
                    "name": "managerMail",
                    "type": "String"
                },
                {
                    "name": "arrivalDate",
                    "type": "DateTime"
                },
                {
                    "name": "expiryDate",
                    "type": "DateTime"
                }
            ]
        }
    ]
}

根据extoe82ql2v_test/companyName检索用户的请求:

https://graph.microsoft.com/v1.0/users?$select=extoe82ql2v_test,givenName,surname,mail,mobilePhone,department,companyName,accountEnabled&$filter=extoe82ql2v_test/companyName eq '测试'

结果:

{
    "error": {
        "code": "Request_UnsupportedQuery",
        "message": "Unsupported or invalid query filter clause specified for property 'companyName' of resource 'User'.",
        "innerError": {
            "date": "2020-07-24T20:46:51",
            "request-id": "639b8131-70dd-4436-b624-88167fe105eb"
        }
    }
}

与 Microsoft Graph .NET SDK 相同的查询:

var res = await _graphClient.Users.Request()
    .Select($"extoe82ql2v_test,givenName,surname,mail,mobilePhone,department,companyName,accountEnabled")
    .Filter($"extoe82ql2v_test/companyName eq 'test'").GetAsync()

我不明白问题是什么,因为我遵循了 official documentation 的内容说到过滤自定义属性

非常感谢任何帮助

编辑:这是没有$filter$select的样子

请求: https://graph.microsoft.com/v1.0/users?$select=givenName,surname,mail,mobilePhone,department,companyName,accountEnabled,extoe82ql2v_test

响应:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(givenName,surname,mail,mobilePhone,department,companyName,accountEnabled,extoe82ql2v_test)",
    "value": [
        {
            "givenName": "Antoine",
            "surname": "D",
            "mail": "antoine.d@contoso.com",
            "mobilePhone": null,
            "department": null,
            "companyName": null,
            "accountEnabled": true,
            "extoe82ql2v_test": {
                "@odata.type": "#microsoft.graph.ComplexExtensionValue",
                "expiryDate": "2020-12-31T00:00:00Z",
                "arrivalDate": "2020-07-22T00:00:00Z",
                "managerMail": "antoine.d@contoso.com",
                "companyName": "test"
            }
        }
    ]
}

编辑 2: 我使用另一个自定义属性 extoe82ql2v_test/managerMail 成功过滤了用户,这是一个进步,但我仍然需要在 extoe82ql2v_test/companyName 上应用过滤器并使其工作

编辑 3: 在 extoe82ql2v_test/expiryDateextoe82ql2v_test/arrivalDate 上过滤也有效,这两个属性都无法过滤但至少我知道它们有效。至于extoe82ql2v_test/companyName,我想知道是不是因为这个属性同时存在于schema extensions和User Graph对象中?

最佳答案

我刚刚遇到了同样的问题,并通过在查询参数中添加“$count=true”使其工作。

我还注意到它似乎需要在请求 header 中使用 ConsistencyLevel=eventual

例如:

  • https://graph.microsoft.com/v1.0/users?$filter=CompanyName eq 'xxxx'&$select=id,displayName,CompanyName

Bad Request - 400 - 146ms

{
 "error": {
   "code": "Request_UnsupportedQuery",
   "message": "Unsupported or invalid query filter clause specified for property 'companyName' of resource 'User'.",
   ...
}
  • https://graph.microsoft.com/v1.0/users?$count=true&$filter=CompanyName eq 'xxxx'&$select=id,displayName,CompanyName(带标题ConsistencyLevel=eventual)

OK - 200 - 404ms

\o/

(我通过查看这个问题得到了提示 Microsoft Graph API cannot filter /users by companyName? )

关于microsoft-graph-api - 架构扩展 : "Unsupported or invalid query filter clause specified for property ' companyName' of resource 'User' .“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63081403/

相关文章:

sharepoint - 无法从 Azure AD 导入的用户获取用户属性

c# - Microsoft Graph API 更新其他用户的照片?

oauth-2.0 - 在 Microsoft Graph API 中,获得管理员同意的应用是否可以为与批准它的管理员不同的用户生成 token ?

azure-active-directory - Microsoft Graph - 用户照片 : Microsoft. Fast.Profile.Core.Exception.ImageNotFoundException

azure - 非管理员的 Microsoft Graph API 权限?

c# - 如何获取最近编辑的文件列表?

c# - Azure AD 图 : Secure binary serialization is not supported on this platform

microsoft-graph-api - 微软图形 : Unable to filter by binary singleValueExtendedProperty

php - "Access denied"Microsoft Graph 制作文件夹时

php - 如何在微软的php graph api中访问响应数据