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

如何从Microsoft Graph API获取正确订阅ID?与管理门户ID不一致

问题

客户拥有3个订阅:Exchange Online (Plan 1)、Microsoft 365 E3、Microsoft Teams Room Pro。在Microsoft 365管理门户中查看这些订阅时,点击Exchange Online Plan 1后,浏览器URL中assets后的ID为1f623e61-6645-4d63-d853-XXYZ。但调用Graph API的https://graph.microsoft.com/v1.0/directory/subscriptions端点返回的结果中,id字段与该ID不一致,commerceSubscriptionId也不匹配。请问是否调用了错误的端点,或是遗漏了什么?

调用示例代码:

$url ="https://graph.microsoft.com/v1.0/directory/subscriptions";

// 返回结果示例
stdClass Object
(
[@odata.context] => https://graph.microsoft.com/v1.0/$metadata#directory/subscriptions
[value] => Array
    (
        [0] => stdClass Object
            (
                [createdDateTime] => 2023-04-27T15:27:35Z
                [commerceSubscriptionId] => 1234567-de25-4aff-858c-AABBCCDD
                [id] => 123456-2a6d-4630-9931-SomethingNotCloseToOtherId
                [isTrial] => 
                [nextLifecycleDateTime] => 2025-04-03T00:00:00Z
                [skuId] => c5928f49-12ba-48f7-ada3-0d743a3601d5
                [skuPartNumber] => SomeExchangeSKu
                [status] => Enabled
                [totalLicenses] => 5
                [ownerTenantId] => 
                [ownerId] => 
                [ownerType] => 
                [serviceStatus] => Array
            )
    )
)
解决方案

你调用的端点确实不对,具体说明如下:

  • directory/subscriptions的用途:这个端点返回的是Azure AD目录级别的订阅(比如Azure AD Premium P1/P2等),并非Microsoft 365的服务订阅(Exchange、E3这类许可证订阅)。
  • 正确的端点:要获取Microsoft 365管理门户中显示的订阅,应该调用https://graph.microsoft.com/v1.0/subscribedSkus端点。
  • 字段对应关系:
    • 管理门户URL中assets后的ID,对应subscribedSkus返回结果里的subscriptionId字段;
    • skuPartNumber字段会显示订阅的标识(比如Exchange Online Plan 1对应的是EXCHANGESTANDARD,Microsoft 365 E3对应的是ENTERPRISEPACK);
    • 返回的id字段格式为{租户ID}_{SKU ID},是租户内该SKU的唯一标识,和管理门户的URL ID不直接对应。
  • 验证方式:调用subscribedSkus后,你会看到包含subscriptionId的结果,其值会和管理门户URL中的assets ID完全匹配。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.14 12:28:16