5

Is there a way to get current usage/billing report/metric via Client SDK or API?

Example my app is using Cloud Speech API and would like to see how much I've incurred in costs on the app itself without having to login to console everytime.

I am basically exploring the nuget package Google.Apis.Cloudbilling.v1 but lack of much documentation is leaving me perplex.

What I have tried so far:

var service = new Google.Apis.Cloudbilling.v1.CloudbillingService();            
Google.Apis.Cloudbilling.v1.ProjectsResource.GetBillingInfoRequest request = service.Projects.GetBillingInfo("projects/my-project-123");
Google.Apis.Cloudbilling.v1.Data.ProjectBillingInfo response = request.Execute();

I have an GOOGLE_APPLICATION_CREDENTIALS set globally and enabled billing api via the console.

xoail
  • 2,978
  • 5
  • 36
  • 70
  • The documentation is effectively at https://cloud.google.com/billing/docs/ - with the API documentation at https://cloud.google.com/billing/reference/rest/. The library basically exposes that API for .NET in way which is hopefully *reasonably* straightforward. You've shown what you've tried so far, but not explained what happens vs what you expected to happen. – Jon Skeet Feb 05 '18 at 10:58
  • I wasn't sure if I was making the right calls coz the response of it is simply an object that simply tells me if billing is enabled or not. This is the response object it returns https://cloud.google.com/billing/reference/rest/v1/ProjectBillingInfo instead I am looking to fetch the dollar amount I owe for the current month. – xoail Feb 05 '18 at 12:36
  • Right, based on the documentation I don't think that's part of the functionality that the API provides, I'm afraid. That isn't a .NET aspect - it's just the functionality currently exposed. – Jon Skeet Feb 05 '18 at 12:50
  • I see. thanks for confirming it. – xoail Feb 05 '18 at 20:52
  • 4
    API indeed doesn't provide functionality you need, however you may consider setting up billing exports to GCS (this part has to be done manually AFAIK), then use GCS API to extract necessary information. Documentation is at https://cloud.google.com/billing/docs/how-to/export-data-file. BQ exports are available too. – Nikita Uchaev Feb 06 '18 at 12:40

0 Answers0