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

如何通过Microsoft Graph API分页获取Azure AD PIM角色合格分配

解决Microsoft Graph roleEligibilitySchedules端点无@odata.nextLink的分页问题

针对你遇到的roleManagement/directory/roleEligibilitySchedules端点不返回@odata.nextLink导致无法自动分页的问题,可以试试以下几种方案:

  • 改用Delta查询端点
    微软Graph的部分角色管理资源需要通过Delta端点实现全量/增量分页获取,换成这个端点试试:
    https://graph.microsoft.com/v1.0/roleManagement/directory/roleEligibilitySchedules/delta
    这个端点会在存在更多数据时返回@odata.nextLink,你可以循环调用该链接直到没有nextLink出现,即可获取全部数据。

  • 手动分页(临时方案)
    如果Delta端点不适用,你可以用$skip参数配合$top手动实现分页:

    • 第一次请求:https://graph.microsoft.com/v1.0/roleManagement/directory/roleEligibilitySchedules?$top=2
    • 第二次请求:https://graph.microsoft.com/v1.0/roleManagement/directory/roleEligibilitySchedules?$top=2&$skip=2
    • 后续每次递增$skip的值,直到返回结果为空,说明已获取完所有数据。不过这种方法要注意数据变更的问题,分页过程中若有记录新增/删除,可能会出现数据重复或遗漏。
  • 确认数据总量
    先调用带$count=true的请求确认总记录数:
    https://graph.microsoft.com/v1.0/roleManagement/directory/roleEligibilitySchedules?$count=true
    (需要在请求头中添加ConsistencyLevel: eventual才能返回count值)
    如果总记录数小于等于你设置的$top值,自然不会返回nextLink,先确认是否真的有更多数据需要获取。

  • 检查权限配置
    确保你的应用或账号拥有足够权限,比如DirectoryRoleEligibilitySchedule.Read.All或更高权限,权限不足可能导致API隐藏部分数据或分页信息。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 13:04:55