0

I want to automatically get the Billing Invoice details of my Azure Resource-group on a monthly basis using the Schedule Export feature in Azure Cost-Management. I'm able to create a monthly export. However, I'm not able to get the entire month's invoice details. Eg. Oct2020, Nov2020, Dec2020.

Instead this is the format in which my invoice is getting exported -->

Billing invoice period

This doesn't prove to be useful to me because I need to get the billing and invoice details for the entire month. And the invoice should automatically be exported monthly. Eg. Oct2020 then next -> Nov2020 then next -> Dec2020, so on & so forth.

Any advise on how to achieve this? Thanks in advance!

SD4
  • 439
  • 10
  • 27
  • 1
    I think you can use rest API to create a monthly export. For more details, please refer to https://learn.microsoft.com/en-us/rest/api/cost-management/exports/createorupdate – Jim Xu Oct 28 '20 at 09:22
  • Thanks so much @JimXu – SD4 Oct 28 '20 at 10:31
  • @JimXu Is there a way to get the Total cost of the month using the Rest Api monthly export? – SD4 Nov 02 '20 at 07:15
  • Could you please tell me how you call the rest API? – Jim Xu Nov 02 '20 at 07:43
  • https://learn.microsoft.com/en-us/rest/api/cost-management/exports/createorupdate I created a schedule export using this documentation. I was able to get the total cost of the billing period. There's a column called "PRE TAX COST" The summation of the values of that column gives the total billing cost of the particular billing period – SD4 Nov 02 '20 at 07:45
  • Hi. The export api cannot do that. You can use the query API get it : https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage#uri-parameters – Jim Xu Nov 02 '20 at 08:11
  • 1
    Because when we call export API, the dataset granularity must be 'Daily'. But when we call query API, it can be 'none' then it will return total cost. – Jim Xu Nov 02 '20 at 08:30
  • Oh okay @JimXu. But can we set a recurrence period to it? So it can give me the total cost of every month ? – SD4 Nov 02 '20 at 08:41
  • 1
    Hi The query api cannot do recurrence, we need to call the API manually or create a schedule-task to call the API. Regarding how to call query API, please refer to https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage – Jim Xu Nov 02 '20 at 08:48
  • Okay sure @JimXu I'll explore this. Thanks so much – SD4 Nov 02 '20 at 08:51
  • Hi @JimXu, can we use REST API (to create schedule export) from the Azure Portal or Azure CLI? – SD4 Nov 11 '20 at 04:31
  • Could you please describe the issue in detail? According to my understanding, you want to hiw to use CLI to call the rest api. Right? – Jim Xu Nov 11 '20 at 13:34
  • Yes that's right. Either CLI or Portal – SD4 Nov 12 '20 at 04:40
  • please refer to https://www.codeisahighway.com/native-azure-rest-api-calls-now-available-in-azure-cli-2-0-67/ – Jim Xu Nov 12 '20 at 04:58

1 Answers1

1

As you mentioned, the scheduled exports doesn’t support invoice-wise data export. However, here is what you can do:

  • Use Azure Cost Management Query API to generate the usage for the invoice period using the custom timeframe value.
  • Convert the JSON response to CSV.
  • Export the file to Storage Account.

Currently, the Query API supports grouping up to 10 dimensions. If you need the complete dataset, you can use Usage List API instead of Query API. In the Usage List API, you can specify the start and end date (as per your invoice) using the $filter parameter. Rest of the process is same.