Get a usage summary for all of a customer's subscriptions
Applies to: Partner Center | Partner Center for Microsoft Cloud for US Government
You can use the CustomerUsageSummary resource to get a customer's usage of a specific Azure service or resource during the current billing period.
Note
Generally, daily rated unbilled usage data is available via API or the Partner Center portal after 24 hours. Depending on your location and when the meters report usage, additional delays might occur.
Sometimes, you might not see the most recent unbilled usage data from the beginning of the month until the previous month's billed usage data is delivered. This is to make sure the billed usage data is delivered efficiently within the SLA. Once you receive the billed usage data, you can start retrieving all the updated unbilled usage data from the beginning of the month.
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 a usage summary for all of a customer's subscriptions:
Use your IAggregatePartner.Customers collection to call the ById() method.
Call the UsageSummary property, followed by the Get() or GetAsync() methods:
// IAggregatePartner partnerOperations; // var selectedCustomerId as string; var usageSummary = partnerOperations.Customers.ById(selectedCustomerId).UsageSummary.Get();
For an example, see the following:
- Sample: Console test app
- Project: PartnerSDK.FeatureSamples
- Class: GetCustomerUsageSummary.cs
REST request
Request syntax
Method | Request URI |
---|---|
GET | {baseURL}/v1/customers/{customer-tenant-id}/usagesummary 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}/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 CustomerUsageSummary 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) subscription
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
{
"budget":{
"ammount":300.000000,
"attributes":{
"objectType":"SpendingBudget"
}
},
"id":"65726577-C208-40FD-9735-8C85AC9CAC68",
"name":"600 test",
"billingStartDate":"2016-02-06T00:00:00-08:00",
"billingEndDate":"2016-03-05T00:00:00-08:00",
"totalCost":0.0,
"currencyLocale":"en-US",
"lastModifiedDate":"2016-02-26T09:42:54.5130558+00:00",
"links":{
"self":{
"uri":"/customers/{customer-tenant-id}/usagesummary",
"method":"GET",
"headers":[]
}
},
"attributes":{
"objectType":"CustomerUsageSummary"
}
}
Response example for Azure plan
In this example, the customer purchased an Azure plan.
For customers with Azure plans, there are the following changes to 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
{
"budget": {
"amount": 97,
"attributes": {
"objectType": "SpendingBudget"
}
},
"resourceId": "a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
"resourceName": "Modern Azure Customer UK",
"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",
"attributes": {
"objectType": "CustomerUsageSummary"
}
}