BillingAccounts and BillingSubscriptions API's are return empty data

Martin D 31 Reputation points

I'm trying to call these API's from an application by using a service principal but I only get an empty Json response.{subscriptionId}/invoices

I've assigned the "Billing Reader" and the "Cost Management Reader" roles in Azure IAM to the app registration on the subscription I want to get the data from. I get json data when I use the "Try it" feature on the web pages as I run in a user context.

Does anyone know what I'm missing here as it seems to be a permission that is missing or if I have the wrong agreement or billing account type?

My Billing account type is "Microsoft Online Services Program".

Thanks in advance!

Azure Cost Management
Azure Cost Management
A Microsoft offering that enables tracking of cloud usage and expenditures for Azure and other cloud providers.
2,006 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Ryan Hill 25,476 Reputation points Microsoft Employee

    If it was an authentication error, I would imagine you would get an error response rather than an empty json array. One thing I can suggest doing is using the api-version value that's being used in the Try it experience on the documentation. Or you could run a F12 Network browser trace, looking for this API call from the portal and using that same api-version value. I would also check the Bearer token your app service is using to check for any inconsistencies in the claims.

    EDIT 2022 Aug 23 I've received further clarification on this matter. The reason why you're getting an empty result is because you've added permissions to billing subscriptions tied to a subscription but not access to billing accounts which is not scoped at the subscription level. I'm assuming followed this doc for guidance. See Billing accounts and scopes in the Azure portal, if you haven't already, to get a better understanding how billing accounts are structured.

    Try elevating access for your service principal to return the billing account information.

  2. suganthi 1 Reputation point

    i too face the same error , with service principle it show empty value , any solution ?

    0 comments No comments