Jaa


Get subscription usage records for a customer

Applies to: Partner Center | Partner Center for Microsoft Cloud for US Government

You can use the SubscriptionMonthlyUsageRecord resource collection to get subscription usage records for a customer of a specific Azure service or resource during the current billing period. This resource represents all subscriptions for the customer. For a customer with an Azure plan, this resource returns a list of those plans (not individual Azure subscriptions).

Prerequisites

  • Credentials as described in Partner Center authentication. This scenario supports authentication with App+User credentials only.

  • A customer ID (customer-tenant-id). If you don't know the customer's ID, you can look it up in Partner Center by selecting the Customers workspace, then the customer from the customer list, then Account. On the customer’s Account page, look for the Microsoft ID in the Customer Account Info section. The Microsoft ID is the same as the customer ID (customer-tenant-id).

C#

To get subscription usage records for a customer of a specific Azure service or resource during the current billing period, do the following steps:

  1. Use your IAggregatePartner.Customers collection to call the ById() method.

  2. Then call the Subscriptions property and the UsageRecords property. Finish by calling the Get() or GetAsync() methods.

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

For an example, see the following:

  • Sample: Console test app
  • Project: PartnerSDK.FeatureSamples
  • Class: GetSubscriptionUsageRecords.cs

REST request

Request syntax

Method Request URI
GET {baseURL}/v1/customers/{customer-tenant-id}/subscriptions/usagerecords HTTP/1.1

URI parameter

This table lists the required query parameter to get the customer's rated usage information.

Name Type Required Description
customer-tenant-id guid Y A GUID corresponding to the customer.

Request headers

For more information, see Partner Center REST headers.

Request body

None.

Request example

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

REST response

If successful, this method returns a SubscriptionMonthlyUsageRecord resource in the response body.

Response success and error codes

Each response comes with an HTTP status code that indicates success or failure and additional debugging information. Use a network trace tool to read this code, the error type, and additional parameters. For a full list, see Error Codes.

Response example for Microsoft Azure (MS-AZR-0145P) subscriptions

In this example, the customer purchased a 145P Azure PayG offer.

For customers with Microsoft Azure (MS-AZR-0145P) subscriptions, there will be no change to the API response.

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"
    }
}

REST response example for Azure plan

In this example, the customer purchased an Azure plan.

For customers with Azure plans, there are the following changes in the API response:

  • currencyLocale is replaced with currencyCode
  • usdTotalCost is a new field
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": 2,
    "items": [
        {
            "status": "active",
            "partnerOnRecord": "some-id",
            "offerId": "DZH318Z0BPS6:0001:DZH318Z0BML6",
            "resourceId": "b1b1b1b1-cccc-dddd-eeee-f2f2f2f2f2f2",
            "id": "b1b1b1b1-cccc-dddd-eeee-f2f2f2f2f2f2",
            "resourceName": "Azure plan",
            "name": "Azure plan",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-18T17:09:26.16+00:00",
            "attributes": {
                "objectType": "SubscriptionMonthlyUsageRecord"
            }
        },
        {
            "status": "active",
            "partnerOnRecord": "some-id",
            "offerId": "DZH318Z0BPS6:0001:DZH318Z0BML6",
            "resourceId": "c2c2c2c2-dddd-eeee-ffff-a3a3a3a3a3a3",
            "id": "c2c2c2c2-dddd-eeee-ffff-a3a3a3a3a3a3",
            "resourceName": "Azure plan",
            "name": "Azure plan",
            "totalCost": 0,
            "currencyCode": "GBP",
            "usdTotalCost": 0,
            "lastModifiedDate": "2019-09-18T17:09:26.16+00:00",
            "attributes": {
                "objectType": "SubscriptionMonthlyUsageRecord"
            }
        }
    ],
    "links": {
        "self": {
            "uri": "/customers/<customer-tenant-id>/subscriptions/usagerecords",
            "method": "GET",
            "headers": []
        }
    },
    "attributes": {
        "objectType": "Collection"
    }
}