6

I need to get Usage Details at Billing Account Scope for that firstly I used this API but It returns an empty value. I used the Bearer Access token for hitting this API.Is anything other than this am I missed?

Postman Request attached as screenshot

Postman Request attached as screenshot

DAK
  • 282
  • 1
  • 18

2 Answers2

3

I believe you're using the wrong API. To get Billing info you must provide billing account name:

GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}?api-version=2019-10-01-preview

https://learn.microsoft.com/en-us/rest/api/billing/2019-10-01-preview/billingaccounts/get

PS: you can use the "try it" and test if it will return the information you need.

You can also query usage API and use one of the available dimensions to get cost related info:

POST https://management.azure.com/{scope}/providers/Microsoft.CostManagement/query?api-version=2019-11-01

https://learn.microsoft.com/en-us/rest/api/cost-management/query/usage

Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • Thank you, for using this api GET https://management.azure.com/providers/Microsoft.Billing/billingAccounts/{billingAccountName}?api-version=2019-10-01-preview I need Billing Account Name. – DAK Jul 18 '20 at 07:39
  • @DAK did you manage to find an answer? I am struggling with this also – isioutis May 10 '21 at 13:39
  • No, not able get it.@isioutis that api requires billing account name – DAK May 12 '21 at 06:39
  • @DAK the API in the original question I mean , where it gets the list of billing accounts . I managed to get it to work but not on all my customers . Mostly I get empty list as you did . – isioutis May 15 '21 at 14:43
  • log into your account and go to https://portal.azure.com/#blade/Microsoft_Azure_GTM/ModernBillingMenuBlade/BillingAccounts – Thiago Custodio May 15 '21 at 15:10
  • @ThiagoCustodio I need to get the billing account list from the API . – isioutis May 16 '21 at 15:56
  • @isioutis to list you should use the following: https://learn.microsoft.com/en-us/rest/api/billing/2019-10-01-preview/billingaccounts/list – Thiago Custodio May 17 '21 at 12:46
  • @Thiago Custodio That is the problem . The specific API call does not work as expected . It returns empty list ( while in portal I can actually see the billing accounts ) . There is no reference in documentation which permissions or how to setup so that this API call works correctly . – isioutis May 18 '21 at 05:54
  • @isioutis you should create a service principal and grant this https://learn.microsoft.com/en-us/azure/cost-management-billing/manage/manage-billing-access#give-read-only-access-to-billing – Thiago Custodio May 18 '21 at 12:42
  • @ThiagoCustodio this doc shows how to add permission on specific subscription . My problem starts higher . I need to get the billing account list so I can get the billing account id/name from API . – isioutis May 25 '21 at 08:07
1

This api will return a value if account belongs to Modern billing

user_17
  • 26
  • 3