0

I'm trying to get billingInfo for a google cloud project using python 3.6 I have done with request to billing API but the response is not expected, As Google's documentation for Billing Api says that it returns Name, ProjectId, billingAccountName & billingEnabled. But it only returns name and projectId even for a project which doesn't associate with a billing account. Here's my code:

            projectName = form.cleaned_data['project_id']
            # Get billing Info of selected project
            auth = getauth()
            service = discovery.build('cloudbilling', 'v1', http=auth, cache_discovery=False)
            name = 'projects/' + projectName
            billing_request = service.projects().getBillingInfo(name=name,)
            billing_response = billing_request.execute()
            data = billing_response
            print(json.dumps(data))
            if data['name']:
                return HttpResponse(json.dumps(data), content_type='application/json')
            else:
                data = []
                return HttpResponse(json.dumps(data), content_type='application/json')

and it returns the response as :

{"name": "projects/docker-184805/billingInfo", "projectId": "docker-184805"}

Even billing is not enabled for this project.

How can I get the proper billing info for a project on google cloud platform using API python client?

Help me, please!

Thanks in advance!

John Hanley
  • 74,467
  • 6
  • 95
  • 159
Abdul Rehman
  • 5,326
  • 9
  • 77
  • 150

1 Answers1

0

I ran your code in a project with no billing enabled (no associated billing account) and I received the same response as you, with only name and projectId. Then, I ran it in a project with enabled billing and I received the response as the documentation you pointed out suggests.

But it only returns name and projectId even for a project which doesn't associate with a billing account.

Just enable billing for your project and you will receive the proper billing info, with name, projectId, billingAccountName and billingEnabled.

Tudormi
  • 1,092
  • 7
  • 18