Get usage summary for customer's subscription
Applies to: Partner Center | Partner Center for Microsoft Cloud for US Government
You can use the SubscriptionUsageSummary resource to get a subscription usage summary for a customer. This resource represents the subscription usage summary of a specific Azure service or resource during the current billing period.
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
).A subscription identifier
C#
To get a subscription usage summary for a customer's subscription:
Use your IAggregatePartner.Customers collection to call the ById() method.
Then call the Subscriptions property and the UsageSummary property. Finish by calling the Get() or GetAsync() methods.
// IAggregatePartner partnerOperations; // var selectedCustomerId as string; // var selectedSubscriptionId as string; var subscriptionUsageSummary = partnerOperations.Customers.ById(selectedCustomerId).Subscriptions.ById(selectedSubscriptionId).UsageSummary.Get();
For an example, see the following:
- Sample: Console test app
- Project: PartnerSDK.FeatureSamples
- Class: GetSubscriptionUsageSummary.cs
REST request
Request syntax
Method | Request URI |
---|---|
GET | {baseURL}/v1/customers/{customer-tenant-id}/subscriptions/{subscription-id}/usagesummary HTTP/1.1 |
URI parameters
This table lists the required query parameters to get the customer's rated usage information.
Name | Type | Required | Description |
---|---|---|---|
customer-tenant-id | guid | Y | A GUID corresponding to the customer. |
subscription-id | guid | Y | A GUID corresponding to the identifier of a subscription. For an Azure plan, this is the identifier of the corresponding Partner Center subscription resource, which represents the Azure plan. For Azure plan subscription resources, provide the plan-id as the subscription-id in this route. |
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/{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 response
If successful, this method returns a SubscriptionUsageSummary 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
{
"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"
}
}
REST response example for Azure plan
In this example, the customer purchased an Azure plan.
For customers with Azure plans, there are the following API response changes:
- currencyLocale is replaced with currencyCode
- usdTotalCost is a new field
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"
}
}