0

I am using the Azure Invoice API which has asks for the following parameters https://management.azure.com/providers/Microsoft.Billing/billingAccounts/**{billingAccountName}**/billingProfiles/**{billingProfileName}**/invoices/**{invoiceName}**?api-version=2019-10-01-preview

but after having all the parameters and running my Python code, I am facing an error which is defined below:

{'code': 'NotFound', 'message': 'The resource or one of its dependencies could not be found.'}

and I have given the Billing reader access to the Service Principle that I am using for generating access token. Is there anything required other than this role for reading Billing data of Azure? Is there a possibility that I am entering wrong parameters?

We are expecting to get the invoice data for Azure.

Albert Einstein
  • 7,472
  • 8
  • 36
  • 71
  • Please provide enough code so others can better understand or reproduce the problem. – Community Aug 13 '23 at 17:53
  • Hi @MEHRAB VERMA Could you provide your Python code in the question? – Venkatesan Aug 14 '23 at 03:32
  • Are you able to fire the rest api call via postman? If that is working then we know it is a problem with your code. Else it will be something with your parameters in the rest API call. – Anupam Chand Aug 14 '23 at 09:26

1 Answers1

1

I am facing an error defined below {'code': 'NotFound', 'message': 'The resource or one of its dependencies could not be found.'}

The above error occurs maybe you have passed incorrect parameters, incorrect permissions, or issues with the API itself.

You can use the below Python code to fetch invoice details from a user with billing reader role. it supports only users and groups to get the info of invoice details.

Portal:

enter image description here

Roles: enter image description here

Code:

from azure.identity import DefaultAzureCredential
from azure.mgmt.billing import BillingManagementClient


def main():
    client = BillingManagementClient(
        credential=credential=DefaultAzureCredential(),
        subscription_id="Your-subscription-id",
    )

    response = client.invoices.get(
        billing_account_name="<your-billing-account-name>",
        invoice_name="<Your-invoice-name>",
    )
    print(response)


if __name__ == "__main__":
    main()

Output:

enter image description here

Reference:

  1. Invoices - Get - REST API (Azure Billing) | Microsoft Learn
  2. Manage access to Azure billing - Microsoft Cost Management | Microsoft Learn
Venkatesan
  • 3,748
  • 1
  • 3
  • 15