Send Requests

After you've set everything up, you can send requests to the Google Cloud Billing API.

The following code samples demonstrate how to send a few simple requests:

  • Get a list of billing accounts.
  • Retrieve a particular billing account.
  • Enable billing on a project.

For a full list of methods, see the REST or RPC reference documentation.

Get a list of billing accounts

The API method to list all billing accounts (REST, RPC) is the simpest method in the API, as it has no required parameters, so it's a good place to start. The method simply returns all billing accounts that you have permission to view.

Protocol

GET https://cloudbilling.googleapis.com/v1/billingAccounts

Java

    ListBillingAccountsResponse result = service.billingAccounts().list().execute();

Retrieve a particular billing account

To retrieve a particular billing account (REST, RPC), you'll need to know the billing account ID. This example uses the sample ID 012345-567890-ABCDEF.

Protocol

GET https://cloudbilling.googleapis.com/v1/billingAccounts/012345-567890-ABCDEF

Java

    BillingAccount result = service.billingAccounts()
        .get("billingAccounts/00C5EA-61187E-D842F2").execute();

Enable billing on a project

To enable billing on a project, you need to call the API to associate the project with an existing billing account (REST, RPC). The following sample code associates project tokyo-rain-123 with billing account 012345-567890-ABCDEF. Incidentally, the same API method can be used to disable billing on a project, by setting billingAccountName to empty.

Protocol

PUT https://cloudbilling.googleapis.com/v1/projects/tokyo-rain-123/billingInfo

{
  "billingAccountName": "billingAccounts/012345-567890-ABCDEF"
}

Java

    service.projects().updateBillingInfo(
            "projects/tokyo-rain-123",
            new ProjectBillingInfo().setBillingAccountName("billingAccounts/012345-567890-ABCDEF"))
        .execute();

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.