The Azure Billing API allows to programmatically read Azure costs. On the one hand, there are is the usage of your resources (how much [unit] you already used for [resource]), on the other hand there are the basic costs for resources – so e.g. the costs for a storage account or a specific virtual machine in a specific region. Each of these two use cases has its own API: the RateCard API which returns the potential costs of the resources (“basic costs”) and the Resource Usage API which returns the usage of your resource of a subscription.
In this blog post, I’ll focus on the RateCard API. There is a sample available on GitHub, but when I used it, I ran into some issues. So I decided to developed a simple C# console application and blog about my experiences. The application reads data from the RateCard API and creates a CSV file out of it. The CSV file can be opened in Excel and should already help to do some calculations.
The application/this post is mostly inspired by: https://github.com/Azure-Samples/billing-dotnet-ratecard-api.
Update February 7, 2017: I built a .net library and published it as NuGet package which you can use to get data from the usage api and the ratecard api. The library also combines the usage and ratecard data and calculates the costs. The code is published on GitHub and I blogged about the usage and the configuration of it:
- Blog post: Using the Azure Billing API and calculate the costs
- NuGet Package: https://www.nuget.org/packages/CodeHollow.AzureBillingApi/
- GitHub Repository: https://github.com/codehollow/AzureBillingApi
This blog post is still valid, it shows the how to configure and build an application that uses the Azure Billing RateCard REST API.