onPremisesExtensionAttributes 的 Microsoft Graph 过滤器

问题描述 投票:0回答:2

我有一个具有以下属性的 Microsoft Graph 用户:

"onPremisesExtensionAttributes": {
            "extensionAttribute1": "attr1",
            "extensionAttribute2": null,
            "extensionAttribute3": null,
            "extensionAttribute4": null,
             etc.
        },

我似乎找不到任何有关如何过滤此属性的文档或示例。我试过了:

https://graph.microsoft.com/beta/users?$filter=extensionAttribute1 eq 'attr1'
https://graph.microsoft.com/beta/users?$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'attr1'
https://graph.microsoft.com/beta/users?$filter=onPremisesExtensionAttributes/any(x:startswith(x,'attr1'))

所有这些都会导致错误请求,所以显然出了问题。

"code": "BadRequest",
"message": "Invalid filter clause",

问题:如何针对 onPremisesExtensionAttributes 或包含命名属性列表的任何其他属性(例如,extensionAttribute1...n)格式化过滤器? 对于字符串列表(例如 proxyAddresses),您可以这样做:

$filter=proxyAddresses/any(x:startswith(x,%27smtp:myemail%27))
office365 azure-active-directory microsoft-graph-api
2个回答
12
投票

您现在可以过滤

onPremisesExtensionAttributes

https://graph.microsoft.com/v1.0/users?$count=true&$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'attr1'

需要注意的两个要点:

  1. 您需要将
    ConsistencyLevel
    HTTP 请求标头设置为
    eventual
    。否则,您将收到
    400
    状态代码,并显示以下消息
    Property 'extensionAttribute1' does not exist as a declared property or extension property.
  2. 即使您不关心计数,也需要包含
    $count=true
    ,否则您将收到
    400
    状态代码,并显示以下消息
    Property 'extensionAttribute1' does not exist as a declared property or extension property.

来源:https://developer.microsoft.com/en-us/office/blogs/microsoft-graph-advanced-queries-for-directory-objects-are-now-generally-available/.


0
投票

很好用 如果您使用的是 powershell 和 ms graph api(google howto toke 有效)

$headers = @{ 
 "Authorization" = "Bearer $token" 
 "ConsistencyLevel" = "eventual"
} 


# API Endpoint 

$uri = "https://graph.microsoft.com/v1.0/users?`$count=true&`$select=displayName,id,department,jobtitle,extensions&`$filter=(onPremisesExtensionAttributes/extensionAttribute1 eq 'VALUE')"


# Make the API call 
try {
$response = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get 

} catch {
Write-Host "Some Error";
Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ 
Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
Continue
}
© www.soinside.com 2019 - 2024. All rights reserved.