共用方式為


依照計量取得訂用帳戶的使用資料

適用于:合作夥伴中心 |適用于 Microsoft Cloud for US Government 的合作夥伴中心

您可以使用 MeterUsageRecord 資源集合,在目前的計費期間取得特定 Azure 服務或資源的計量使用量記錄。 此資源集合代表整個 Azure 方案中目前計費週期每個計量的匯總總計。

必要條件

  • 認證,如合作夥伴中心驗證所述。 此案例僅支援使用「應用程式+使用者」認證來進行驗證。

  • 客戶識別碼 (customer-tenant-id)。 如果您不知道客戶的識別碼,您可以選取 [客戶] 工作區,然後從客戶清單中選取客戶,然後從客戶清單中查詢該識別碼,然後查閱合作夥伴中心。 在客戶的 [帳戶] 頁面上,尋找 [客戶帳戶資訊] 區段中的 [Microsoft 識別碼] 。 Microsoft 識別碼與客戶識別碼 () customer-tenant-id 相同。

  • 訂用帳戶識別碼

這個新路由相當於 subscriptions/{subscription-id}/usagerecords/resources ,它只會繼續針對 Microsoft Azure (MS-AZR-0145P) 訂用帳戶運作。 這個新的路由將同時支援 Microsoft Azure (MS-AZR-0145P) 訂用帳戶和 Azure 方案。 若要取得 Azure 方案的這項資訊,您必須切換至這個新的路由。 除了下列各節所述的屬性以外,回應與舊路由相同。

C#

若要取得客戶在目前計費期間內特定 Azure 服務或資源的計量使用量記錄:

  1. 使用 IAggregatePartner.Customers 集合來呼叫 ById () 方法。

  2. 呼叫 Subscriptions 屬性和 UsageRecords,然後呼叫 Meters 屬性。 呼叫 Get () 或 GetAsync () 方法來完成。

    // IAggregatePartner partnerOperations;
    // var selectedCustomerId as string;
    // var selectedSubscriptionId as string;
    
    var usageRecords = partnerOperations.Customers.ById(selectedCustomerId).Subscriptions.ById(selectedSubscriptionId).UsageRecords.Meters.Get();
    

如需範例,請參閱下列範例:

REST 要求

要求的語法

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

URI 參數

下表列出必要的查詢參數,以取得客戶的評等使用量資訊。

名稱 類型 必要 描述
customer-tenant-id guid Y 與客戶對應的 GUID。
subscription-id guid Y 對應至合作夥伴中心訂用帳戶 資源的識別碼的 GUID,代表 Microsoft Azure (MS-AZR-0145P) 訂用帳戶或 Azure 方案。 針對 Azure 方案訂用帳戶資源,請在此路由中提供 plan-id 作為 subscription-id

要求標頭

如需詳細資訊,請參閱合作夥伴中心 REST 標頭

要求本文

無。

要求範例

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

REST 回應

如果成功,此方法會在回應本文中傳回PagedResourceCollection < MeterUsageRecord >資源。

回應成功和錯誤碼

每個回應都隨附 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

{
    "totalCount": 1,
    "items": [
        {
            "status": "active",
            "offerId": "MS-AZR-0145P",
            "resourceId": "a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
            "id": "a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
            "resourceName": "Microsoft Azure",
            "name": "Microsoft Azure",
            "totalCost": 22.861172,
            "currencyLocale": "fr-FR",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-01T23:04:41.193+00:00",
            "attributes": {
                "objectType": "SubscriptionMonthlyUsageRecord"
            }
        }
    ],
    "links": {
        "self": {
            "uri": "/customers/{customer-tenant-id}/subscriptions/usagerecords/",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Collection"
    }
}

Azure 方案的 REST 回應範例

在此範例中,客戶已購買 Azure 方案。

對於具有 Azure 方案的客戶,API 回應中有下列變更:

  • currencyLocale 會取代為 currencyCode
  • usdTotalCost 是新的欄位
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: Fri, 26 Feb 2016 20:31:45 GMT

{
    "totalCount": 4,
    "items": [
        {
            "subscriptionId": "{subscription-id}",
            "meterId": "DZH318Z0BNVX-005J-Data Transfer In (GB)",
            "meterName": "Data Transfer In",
            "category": "Bandwidth",
            "subcategory": "Bandwidth",
            "quantityUsed": 0.01129,
            "unit": "1 GB",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-17T21:08:44.2566667+00:00",
            "attributes": {
                "objectType": "MeterUsageRecord"
            }
        },
        {
            "subscriptionId": "{subscription-id}",
            "meterId": "DZH318Z0BNVX-005J-Data Transfer Out (GB)",
            "meterName": "Data Transfer Out",
            "category": "Bandwidth",
            "subcategory": "Bandwidth",
            "quantityUsed": 0.000224,
            "unit": "1 GB",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-17T21:08:44.2566667+00:00",
            "attributes": {
                "objectType": "MeterUsageRecord"
            }
        },
        {
            "subscriptionId": "{subscription-id}",
            "meterId": "DZH318Z0BNZ5-006G-10K Batch Write Operations",
            "meterName": "Batch Write Operations",
            "category": "Storage",
            "subcategory": "Tables",
            "quantityUsed": 0.2462,
            "unit": "10K",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-17T21:08:44.2566667+00:00",
            "attributes": {
                "objectType": "MeterUsageRecord"
            }
        },
        {
            "subscriptionId": "{subscription-id}",
            "meterId": "DZH318Z0BNZ5-006G-Data Stored (GB/Month)",
            "meterName": "LRS Data Stored",
            "category": "Storage",
            "subcategory": "Tables",
            "quantityUsed": 0.002632,
            "unit": "1 GB/Month",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-17T21:08:44.2566667+00:00",
            "attributes": {
                "objectType": "MeterUsageRecord"
            }
        }
    ],
    "links": {
        "self": {
            "uri": "/customers/<customer-tenant-id>/subscriptions/<subscription-id>/meterusagerecords",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Collection"
    }
}