I am trying to get billing cost of GCP project, but I could not see expected result for the client library that I am using in my code.
I want to get report or spend cost for current month, but it just providing me:
project_id: "my-project"
billing_account_name: "billingAccounts/XXXXX-XXXXX-XXXXX"
billing_enabled: true
I am using billing_v1.GetProjectBillingInfoRequest()
class to get result.
from google.cloud import billing_v1
from google.oauth2 import service_account
info = {
"client_email": "gcserviceacc@XYZ-project.iam.gserviceaccount.com",
"private_key_id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"private_key": "-----BEGIN PRIVATE KEY-----xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"token_uri": "https://oauth2.googleapis.com/token"
}
credentials = service_account.Credentials.from_service_account_info(info)
# Create a client
client = billing_v1.CloudBillingClient(credentials=credentials)
def sample_get_project_billing_info():
# Initialize request argument(s)
request = billing_v1.GetProjectBillingInfoRequest(
name="projects/my-project"
)
# Make the request
response = client.get_project_billing_info(request=request)
# Handle the response
print(response)
sample_get_project_billing_info()
output:
project_id: "my-project"
billing_account_name: "billingAccounts/XXXX-XXXX-XXXX"
billing_enabled: true