How to get started with Reporting APIs for Enterprise customers of EA Portal
I believe some folks are familiar with Billing API for Microsoft Azure and these APIs can be utilized even you're pay-as-you-go customers. But almost of all folks are unfamiliar with "Reporting APIs for Enterprise customers", because only customers who have EA contract can utilize this APIs.
docs.microsoft.com
I recommend to refer to Azure Billing Enterprise APIs | Microsoft Docs, but here is summary what you can do with the APIs
- Balance and Summary API - offers a monthly summary of information on balances, new purchases, Azure Marketplace service charges, adjustments and overage charges.
- Usage Detail API - offers a daily breakdown of consumed quantities and estimated charges by an Enrollment. The result also includes information on instances, meters and departments. The API can be queried by Billing period or by a specified start and end date.
- Marketplace Store Charge API - returns the usage-based marketplace charges breakdown by day for the specified Billing Period or start and end dates (one time fees are not included).
- Price Sheet API - provides the applicable rate for each Meter for the given Enrollment and Billing Period.
- Reserved Instance usage API - returns the usage of the Reserved Instance purchases. The Reserved Instance charges API shows the billing transactions made.
Preparation to use the APIs
You can utilize the APIs to pick up two items below.
It's easy to pick up "Enrollment Number". You just need to visit EA Portal and pick up Enrollment Number like below.
Next, follow an image below and you can generate new API Access Key.
After generating of the key, you can copy the key into your clip board.
Balance and Summary API
You can call this API easily by using script below.
$AuthorizationKey = "your API Access Key" $enrollmentNumber = "your enrollment number" $res = Invoke-WebRequest ` -Headers @{"Authorization" = "bearer $AuthorizationKey"} -Method GET ` -Uri https://consumption.azure.com/v2/enrollments/$enrollmentNumber/balancesummary ` -ContentType "application/json" # confirm entire response $res ## confirm response contents $res.Content | ConvertFrom-Json
You can confirm the response values of "$res" like below. This structure is even similar with other APIs.
StatusCode : 200 StatusDescription : OK Content : {"id":"enrollments/your enrollment number/billingperiods/your billing periods/balancesummaries","billingPeriodId":"your billing periods","currencyCode":"JPY ","beginningBalance":xxxxx92.00,"endingBalance":xxxxx85.00,"newPurchases":0.00,"adju... RawContent : HTTP/1.1 200 OK session-id: a03789eb-9b3d-49dd-8b12-c2dddb07dd62 x-ms-request-id: ade0cb92-3a78-4e2f-943f-b5a9bd4d8320 x-ms-correlation-request-id: f570130b-21b1-4bef-b1ff-d9e8a8e80e8b x-ms-client... Forms : {} Headers : {[session-id, a03789eb-9b3d-49dd-8b12-c2dddb07dd62], [x-ms-request-id, ade0cb92-3a78-4e2f-943f-b5a9bd4d8320], [x-ms-correlation-request-id, f570130b-21b1-4bef-b1ff-d9e8a8e80e8b], [x-ms-client-request-id, c9d7de6c-8937-48b5-a137-3f026d637cc5]...} Images : {} InputFields : {} Links : {} ParsedHtml : mshtml.HTMLDocumentClass RawContentLength : 429
You can confirm the response content values of "$res.Content" like below.
id : enrollments/"your enrollment number"/billingperiods/"your billing periods"/balancesummaries billingPeriodId : "your billing periods" currencyCode : JPY beginningBalance : xxxxx92.00 endingBalance : xxxxx85.00 newPurchases : 0.00 adjustments : 0.00 utilized : xxxxx7.00 serviceOverage : 0.00 chargesBilledSeparately : 0.00 totalOverage : 0.00 totalUsage : xxxxx7.00 azureMarketplaceServiceCharges : 0.0000000000 newPurchasesDetails : adjustmentDetails :
Reserved Instance usage API
You can call this API like below.
$AuthorizationKey = "your API Access Key" $enrollmentNumber = "your enrollment number" $startDate = "2019-05-01" $endDate = "2019-05-10" $res = Invoke-WebRequest ` -Headers @{"Authorization" = "bearer $AuthorizationKey"} -Method GET ` -Uri "https://consumption.azure.com/v2/enrollments/$enrollmentNumber/reservationdetails?startDate=$startDate&endDate=$endDate" ` -ContentType "application/json" $res.Content | ConvertFrom-Json
You can confirm the response content values of "$res.Content" like below.
.... reservationOrderId : xxxxxxxx-mmmm-yyyy-nnnn-zzzzzzzzzzzz reservationId : xxxxxxxx-mmmm-yyyy-nnnn-zzzzzzzzzzzz usageDate : 2019-05-04T00:00:00 skuName : Standard_DS1_v2 instanceId : /subscriptions/you subscription ID/resourcegroups/your resource group/providers/microsoft.compute/virtualmachines/your vm name totalReservedQuantity : 8.000000000000000 reservedHours : 192.000000000000000 usedHours : 23.950000000000000 .... reservationOrderId : xxxxxxxx-mmmm-yyyy-nnnn-zzzzzzzzzzzz reservationId : xxxxxxxx-mmmm-yyyy-nnnn-zzzzzzzzzzzz usageDate : 2019-05-10T00:00:00 skuName : Standard_B2s instanceId : /subscriptions/you subscription ID/resourcegroups/your resource group/providers/microsoft.compute/virtualmachines/your vm name totalReservedQuantity : 1.000000000000000 reservedHours : 24.000000000000000 usedHours : 24.000000000000000
You can retrieve which reserved instance orders have been used up or not. In addition that, you can verify which VMs are running as Reserved Instance by checking "instanceId".