googleapis / google-api-go-client

Auto-generated Google APIs for Go.
https://pkg.go.dev/google.golang.org/api
BSD 3-Clause "New" or "Revised" License
3.96k stars 1.11k forks source link

Projects.GetBillingInfo does not properly take the specified project into account #1537

Closed FranckVE closed 2 years ago

FranckVE commented 2 years ago

Projects.GetBillingInfo does not use the specified GCP project (in my case it returned an error because the other GCP project it took in consideration did not have billing enabled).

I had to write a direct call to the Google API using the REST http request, while keeping the Application Default Credentials.

Environment details

Steps to reproduce

        gcpProjectID := "my-fifth-gcp-project"
    ctx := context.Background()
    cloudBillingManagerService, err := cloudbilling.NewService(ctx)
    if err != nil {
        fmt.Printf("err in cloudbilling.NewService\n")
        log.Fatal(err)
    }
    getProjectBillingInfo, errGetBillingInfo := cloudBillingManagerService.Projects.GetBillingInfo("projects/" + gcpProjectID).Do()
    if errGetBillingInfo != nil {
        fmt.Printf("getProjectBillingInfo %v\n", getProjectBillingInfo)
        return nil, errGetBillingInfo
    }

It would generate an error because another (other than the one specified in gcpProjectID) more recent project does not have billing enabled.

googleapi: Error 403: Cloud Billing API has not been used in project 123456789 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview?project=123456789 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
Details:
[
  {
    "@type": "type.googleapis.com/google.rpc.Help",
    "links": [
      {
        "description": "Google developers console API activation",
        "url": "https://console.developers.google.com/apis/api/cloudbilling.googleapis.com/overview?project=123456789"
      }
    ]
  },
  {
    "@type": "type.googleapis.com/google.rpc.ErrorInfo",
    "domain": "googleapis.com",
    "metadata": {
      "consumer": "projects/123456789",
      "service": "cloudbilling.googleapis.com"
    },
    "reason": "SERVICE_DISABLED"
  }
]
, accessNotConfigured

The problem is that project "123456789" is not the project number of the project specified in gcpProjectID !

codyoss commented 2 years ago

What project are you running the code from? APIs will need to be enabled from the calling project. This also seems like a question for the API itself and not these clients which are auto-generated from a spec. If you have further issues I suggest reaching out with one of the options on the Cloud Billing Support Page. Hope that helps

FranckVE commented 2 years ago