get azure total billing for a billing account using API/CLI

Gaurav Singh 130 Reputation points
2024-01-05T06:20:45.7233333+00:00

Hi Team,

I have referred the below articles and I am able to get the cost billing details per subscription wise,

Article 1

Article 2

 curl -s -X POST \     -H "Authorization: Bearer ${access_token}" \     -H "Content-Type: application/json" \     -d '{       "type": "Usage",       "timeframe": "Custom",       "timePeriod": {         "from": "'"${seven_days_ago}T00:00:00Z"'",         "to": "'"${seven_days_ago}T23:59:59Z"'"       },       "dataset": {         "granularity": "Daily",         "aggregation": {           "totalCost": {             "name": "Cost",             "function": "Sum"           }         },         "grouping": [           {             "type": "Dimension",             "name": "InvoiceSection"           },           {             "type": "Dimension",             "name": "SubscriptionId"           },           {             "type": "Dimension",             "name": "SubscriptionName"           }         ]       }     }' \     "https://management.azure.com/providers/Microsoft.Billing/billingAccounts/${billing_account_id}/providers/Microsoft.CostManagement/query?api-version=2019-11-01"

I want to retrieve the bill for the entire billing account including the Per Subscription Billing + Other Purches + Other Microsoft Purchases, in short, the billing that is on the portal should be retrieved using the script.

Can you please suggest parameters or any method that Can be used to achieve this.

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
3,672 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Monalla-MSFT 13,071 Reputation points Moderator
    2024-01-10T18:50:15.9433333+00:00

    @Gaurav Singh - Welcome to Microsoft Q&A and thanks for reaching out to us.

    It looks like you are trying to retrieve the billing details for the entire billing account, including per subscription billing, other purchases, and other Microsoft purchases. To retrieve the billing details for the entire billing account, please take a look at below:

    here are the details for the same: https://learn.microsoft.com/en-us/rest/api/billing/invoices/list-by-billing-subscription?view=rest-billing-2020-05-01&tabs=HTTP

    Hope this helps. and please feel free to reach out if you have any further questions.


    If the above response was helpful, please feel free to "Accept as Answer" and click "Yes" so it can be beneficial to the community.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.