You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Graph API中用展开的Manager ID筛选同经理的Azure AD用户

正确筛选Azure AD中同一经理下属用户的Graph API查询方式
  • 正确的查询语法应直接在根层级用$filter筛选用户的manager/id,搭配$expand和$select获取所需字段:
    https://graph.microsoft.com/v1.0/users?$filter=manager/id eq '<manager-id>'&$select=userPrincipalName,displayName&$expand=manager($select=id,userPrincipalName)
    
  • 若要排除经理本人(避免因经理的manager字段指向自己而被纳入结果),可在$filter中追加排除条件:
    https://graph.microsoft.com/v1.0/users?$filter=manager/id eq '<manager-id>' and id ne '<manager-id>'&$select=userPrincipalName,displayName&$expand=manager($select=id,userPrincipalName)
    

此前查询失效的原因

  • 把$filter放在$expand内部时,筛选的是关联的manager实体而非用户本身,因此会返回所有用户,仅对符合条件的manager进行展开,不符合条件的用户的manager字段会为空,并非真正筛选出下属用户。
  • 你提到的第二个查询仅返回经理对象,大概率是因为该经理的manager字段恰好指向自己(比如顶层管理者),此时加上id ne '<manager-id>'的排除条件即可得到纯下属用户列表。

内容的提问来源于stack exchange,提问作者ChristofferL

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 11:45:36