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

如何让Graph API返回的用户assignedPlans仅保留指定PowerApps服务条目?

解决Microsoft Graph API返回指定assignedPlans条目的问题

核心原因

assignedPlans是用户实体的非导航/非复杂集合属性,OData的$expand仅支持对导航属性执行展开筛选操作,因此直接使用$expand=assignedPlans($filter=...)会触发报错。

可行解决方案

方案1:客户端侧过滤查询结果

先执行原查询筛选出拥有激活状态PowerAppsService的用户,再在客户端代码中对每个用户的assignedPlans数组进行二次过滤:

  • 原查询示例(用于筛选目标用户):
GET https://graph.microsoft.com/v1.0/users?$filter=assignedPlans/any(p: p/service eq 'PowerAppsService' and p/capabilityStatus eq 'Enabled')
  • 客户端过滤逻辑示例(以JavaScript为例):
// 假设users为接口返回的用户数组
const filteredUsers = users.map(user => ({
  ...user,
  assignedPlans: user.assignedPlans.filter(plan => 
    plan.service === 'PowerAppsService' && plan.capabilityStatus === 'Enabled'
  )
}));

方案2:使用licenseDetails端点替代查询

若需在服务端层面精准获取PowerApps相关服务计划,可调用/users/{id}/licenseDetails端点,该端点返回的servicePlans属性支持过滤:

  • 查询示例:
GET https://graph.microsoft.com/v1.0/users/{user-id}/licenseDetails?$expand=servicePlans($filter=servicePlanName eq 'PowerAppsService' and provisioningStatus eq 'Success')

注:需确认PowerAppsService对应的servicePlanName或servicePlanId(不同区域、许可证类型可能存在差异,可通过/subscribedSkus端点查看所有可用服务计划)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 12:53:14