can we use any google API which can provide information about the total charges spent using Google Cloud Platform? i have tried few APIs (detail shown in code).
API 1:
var google = require('googleapis');
var cloudbilling = google.cloudbilling('v1');
google.auth.getApplicationDefault(function(err, authClient) {
if (err) {
console.log('Authentication failed because of ', err);
return;
}
if (authClient.createScopedRequired && 
authClient.createScopedRequired()) {
var scopes = ['https://www.googleapis.com/auth/cloud-platform'];
authClient = authClient.createScoped(scopes);
 }
 var request = {
  name: "projects/<your-project-id>", 
// Auth client
  auth: authClient
};
 cloudbilling.projects.getBillingInfo(request, function(err, result) {
  if (err) {
   console.log(err);
}  else {
   console.log(result);
 }
   });
  });
What i am getting in json (about billing information) is:
data:
   { name: 'projects/<your-project-name>/billingInfo',
     projectId: '<project-Id>',
 billingAccountName: 'billingAccounts/<your-billing-id>',
 billingEnabled: true } 
   }
Now i have tried other APIs too, but they are also not providing the total charges spent!. Is there a way i can find the bills?
The info in the actuall bills is not (or at least not yet) available in any of the Cloud Billing APIs.
But there are other options for accessing the data via other paths:
To access a detailed breakdown of your charges, you can export your daily usage and cost estimates automatically to a CSV or JSON file stored in a Google Cloud Storage bucket you specify. You can then access the data via the Cloud Storage API, CLI tool, or Google Cloud Platform Console.
Tools for monitoring, analyzing and optimizing cost have become an important part of managing development. Billing export to BigQuery enables you to export your daily usage and cost estimates automatically throughout the day to a BigQuery dataset you specify. You can then access your billing data from BigQuery.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With