获取客户订阅的使用情况摘要

适用于:合作伙伴中心 | Microsoft Cloud for US Government 合作伙伴中心

可以使用 SubscriptionUsageSummary 资源获取客户的订阅使用情况摘要。 此资源表示当前计费周期内特定 Azure 服务或资源的订阅使用情况摘要。

必备条件

  • 合作伙伴中心身份验证中所述的凭据。 此方案只支持使用应用凭据和用户凭据进行身份验证。

  • 客户 ID (customer-tenant-id)。 如果不知道客户的 ID,可以通过选择“客户”工作区、客户列表中的“客户”和“帐户”,在合作伙伴中心中查找该 ID。 在客户的“帐户”页上的“客户帐户信息” 部分查找 Microsoft ID。 Microsoft ID 与客户 ID (customer-tenant-id) 相同。

  • 订阅标识符

C#

获取客户订阅的订阅使用情况摘要:

  1. 使用 IAggregatePartner.Customers 集合调用 ById () 方法。

  2. 然后调用 Subscriptions 属性和 UsageSummary 属性。 通过调用 Get () 或 GetAsync () 方法完成。

    // IAggregatePartner partnerOperations;
    // var selectedCustomerId as string;
    // var selectedSubscriptionId as string;
    
    var subscriptionUsageSummary = partnerOperations.Customers.ById(selectedCustomerId).Subscriptions.ById(selectedSubscriptionId).UsageSummary.Get();
    

有关示例,请参阅以下内容:

  • 示例: 控制台测试应用
  • 项目: PartnerSDK.FeatureSamples
  • 类: GetSubscriptionUsageSummary.cs

REST 请求

请求语法

方法 请求 URI
GET {baseURL}/v1/customers/{customer-tenant-id}/subscriptions/{subscription-id}/usagesummary HTTP/1.1

URI 参数

下表列出了获取客户的分级使用情况信息所需的查询参数。

名称 类型 必须 说明
customer-tenant-id guid Y 与客户对应的 GUID。
subscription-id guid Y 对应于订阅标识符的 GUID。 对于 Azure 计划,这是相应合作伙伴中心 订阅资源的标识符,它表示 Azure 计划。 对于 Azure 计划订阅资源,请在此路由中提供 plan-id 作为 订阅 ID

请求标头

有关详细信息,请参阅合作伙伴中心 REST 标头

请求正文

无。

请求示例

GET https://api.partnercenter.microsoft.com/v1/customers/{customer-tenant-id}/subscriptions/{subscription-id}/usagesummary HTTP/1.1
Authorization: Bearer <token>
Accept: application/json
MS-RequestId: e128c8e2-4c33-4940-a3e2-2e59b0abdc67
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd

REST 响应

如果成功,此方法在响应正文中返回 SubscriptionUsageSummary 资源。

响应的成功和错误代码

每个响应都带有一个 HTTP 状态代码,用于指示成功或失败以及其他调试信息。 请使用网络跟踪工具来读取此代码、错误类型和其他参数。 有关完整列表,请参阅 错误代码

Microsoft Azure (MS-AZR-0145P) 订阅的响应示例

在此示例中,客户购买了 145P Azure PayG 产品/服务。

对于具有 Microsoft Azure (MS-AZR-0145P) 订阅的客户,API 响应不会有任何变化。

HTTP/1.1 200 OK
Content-Length: 1120
Content-Type: application/json
MS-CorrelationId: aaaa0000-bb11-2222-33cc-444444dddddd
MS-RequestId: e128c8e2-4c33-4940-a3e2-2e59b0abdc67
Date: Tue, 17 Sep 2019 20:31:45 GMT

{
    "resourceId": "a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
    "id": "a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
    "resourceName": "Microsoft Azure",
    "name": "Microsoft Azure",
    "billingStartDate": "2019-08-28T00:00:00-07:00",
    "billingEndDate": "2019-09-27T00:00:00-07:00",
    "totalCost": 22.861172,
    "currencyLocale": "fr-FR",
    "lastModifiedDate": "2019-09-01T23:04:41.193+00:00",
    "links": {
        "self": {
            "uri": "/customers/<customer-tenant-id>/subscriptions/<subscription-id>/usagesummary",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "SubscriptionUsageSummary"
    }
}

Azure 计划的 REST 响应示例

在此示例中,客户购买了 Azure 计划。

对于使用 Azure 计划的客户,有以下 API 响应更改:

  • currencyLocale 替换为 currencyCode
  • usdTotalCost 是一个新字段
HTTP/1.1 200 OK
Content-Length: 1120
Content-Type: application/json
MS-CorrelationId: bbbb1111-cc22-3333-44dd-555555eeeeee
MS-RequestId: e128c8e2-4c33-4940-a3e2-2e59b0abdc67
Date: Tue, 17 Sep 2019 20:31:45 GMT

{
    "resourceId": "b1b1b1b1-cccc-dddd-eeee-f2f2f2f2f2f2",
    "resourceName": "Azure plan",
    "billingStartDate": "2019-09-01T00:00:00+00:00",
    "billingEndDate": "2019-10-01T00:00:00+00:00",
    "totalCost": 28.82860766744404945074,
    "currencyCode": "GBP",
    "usdTotalCost": 35.23000000000000362337,
    "lastModifiedDate": "2019-09-18T17:09:26.16+00:00",
    "links": {
        "self": {
            "uri": "/customers/<customer-tenant-id>/subscriptions/<subscription-id>/usagesummary",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "SubscriptionUsageSummary"
    }
}