CloudBillingClient

CloudBillingClient

Retrieves GCP Console billing accounts and associates them with projects.

Constructor

new CloudBillingClient(optionsopt)

Construct an instance of CloudBillingClient.

Parameters:
Name Type Attributes Description
options object <optional>

The configuration object. See the subsequent parameters for more details.

Properties
Name Type Attributes Description
credentials object <optional>

Credentials object.

Properties
Name Type Attributes Description
client_email string <optional>
private_key string <optional>
email string <optional>

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename string <optional>

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port number <optional>

The port on which to connect to the remote host.

projectId string <optional>

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

apiEndpoint string <optional>

The domain name of the API remote host.

Members

(static) apiEndpoint

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

(static) port

The port for this API service.

(static) scopes

The scopes needed to make gRPC calls for every method defined in this service.

(static) servicePath

The DNS address for this API service.

Methods

billingAccountPath(billing_account) → {string}

Return a fully-qualified billingAccount resource name string.

Parameters:
Name Type Description
billing_account string

close()

Terminate the GRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

createBillingAccount(request, optionsopt) → {Promise}

Creates a billing account. This method can only be used to create billing subaccounts by GCP resellers. When creating a subaccount, the current authenticated user must have the billing.accounts.update IAM permission on the master account, which is typically given to billing account administrators. This method will return an error if the master account has not been provisioned as a reseller account.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
billingAccount google.cloud.billing.v1.BillingAccount

Required. The billing account resource to create. Currently CreateBillingAccount only supports subaccount creation, so any created billing accounts must be under a provided master billing account.

options object <optional>

Call options. See CallOptions for more details.

getBillingAccount(request, optionsopt) → {Promise}

Gets information about a billing account. The current authenticated user must be a viewer of the billing account.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Required. The resource name of the billing account to retrieve. For example, billingAccounts/012345-567890-ABCDEF.

options object <optional>

Call options. See CallOptions for more details.

getIamPolicy(request, optionsopt) → {Promise}

Gets the access control policy for a billing account. The caller must have the billing.accounts.getIamPolicy permission on the account, which is often given to billing account viewers.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

options object <optional>

Call options. See CallOptions for more details.

getProjectBillingInfo(request, optionsopt) → {Promise}

Gets the billing information for a project. The current authenticated user must have permission to view the project.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Required. The resource name of the project for which billing information is retrieved. For example, projects/tokyo-rain-123.

options object <optional>

Call options. See CallOptions for more details.

getProjectId(callback)

Return the project ID used by this class.

Parameters:
Name Type Description
callback function

the callback to be called with the current project Id.

initialize() → {Promise}

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

listBillingAccounts(request, optionsopt) → {Promise}

Lists the billing accounts that the current authenticated user has permission to view.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
pageSize number

Requested page size. The maximum page size is 100; this is also the default.

pageToken string

A token identifying a page of results to return. This should be a next_page_token value returned from a previous ListBillingAccounts call. If unspecified, the first page of results is returned.

filter string

Options for how to filter the returned billing accounts. Currently this only supports filtering for subaccounts under a single provided reseller billing account. (e.g. "master_billing_account=billingAccounts/012345-678901-ABCDEF"). Boolean algebra and other fields are not currently supported.

options object <optional>

Call options. See CallOptions for more details.

listBillingAccountsStream(request, optionsopt) → {Stream}

Equivalent to listBillingAccounts, but returns a NodeJS Stream object.

This fetches the paged responses for listBillingAccounts continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
pageSize number

Requested page size. The maximum page size is 100; this is also the default.

pageToken string

A token identifying a page of results to return. This should be a next_page_token value returned from a previous ListBillingAccounts call. If unspecified, the first page of results is returned.

filter string

Options for how to filter the returned billing accounts. Currently this only supports filtering for subaccounts under a single provided reseller billing account. (e.g. "master_billing_account=billingAccounts/012345-678901-ABCDEF"). Boolean algebra and other fields are not currently supported.

options object <optional>

Call options. See CallOptions for more details.

See:

listProjectBillingInfo(request, optionsopt) → {Promise}

Lists the projects associated with a billing account. The current authenticated user must have the billing.resourceAssociations.list IAM permission, which is often given to billing account viewers.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Required. The resource name of the billing account associated with the projects that you want to list. For example, billingAccounts/012345-567890-ABCDEF.

pageSize number

Requested page size. The maximum page size is 100; this is also the default.

pageToken string

A token identifying a page of results to be returned. This should be a next_page_token value returned from a previous ListProjectBillingInfo call. If unspecified, the first page of results is returned.

options object <optional>

Call options. See CallOptions for more details.

listProjectBillingInfoStream(request, optionsopt) → {Stream}

Equivalent to listProjectBillingInfo, but returns a NodeJS Stream object.

This fetches the paged responses for listProjectBillingInfo continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Required. The resource name of the billing account associated with the projects that you want to list. For example, billingAccounts/012345-567890-ABCDEF.

pageSize number

Requested page size. The maximum page size is 100; this is also the default.

pageToken string

A token identifying a page of results to be returned. This should be a next_page_token value returned from a previous ListProjectBillingInfo call. If unspecified, the first page of results is returned.

options object <optional>

Call options. See CallOptions for more details.

See:

matchBillingAccountFromBillingAccountName(billingAccountName) → {string}

Parse the billing_account from BillingAccount resource.

Parameters:
Name Type Description
billingAccountName string

A fully-qualified path representing BillingAccount resource.

matchServiceFromServiceName(serviceName) → {string}

Parse the service from Service resource.

Parameters:
Name Type Description
serviceName string

A fully-qualified path representing Service resource.

matchServiceFromSkuName(skuName) → {string}

Parse the service from Sku resource.

Parameters:
Name Type Description
skuName string

A fully-qualified path representing Sku resource.

matchSkuFromSkuName(skuName) → {string}

Parse the sku from Sku resource.

Parameters:
Name Type Description
skuName string

A fully-qualified path representing Sku resource.

servicePath(service) → {string}

Return a fully-qualified service resource name string.

Parameters:
Name Type Description
service string

setIamPolicy(request, optionsopt) → {Promise}

Sets the access control policy for a billing account. Replaces any existing policy. The caller must have the billing.accounts.setIamPolicy permission on the account, which is often given to billing account administrators.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

options object <optional>

Call options. See CallOptions for more details.

skuPath(service, sku) → {string}

Return a fully-qualified sku resource name string.

Parameters:
Name Type Description
service string
sku string

testIamPermissions(request, optionsopt) → {Promise}

Tests the access control policy for a billing account. This method takes the resource and a set of permissions as input and returns the subset of the input permissions that the caller is allowed for that resource.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

options object <optional>

Call options. See CallOptions for more details.

updateBillingAccount(request, optionsopt) → {Promise}

Updates a billing account's fields. Currently the only field that can be edited is display_name. The current authenticated user must have the billing.accounts.update IAM permission, which is typically given to the administrator of the billing account.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Required. The name of the billing account resource to be updated.

account google.cloud.billing.v1.BillingAccount

Required. The billing account resource to replace the resource on the server.

updateMask google.protobuf.FieldMask

The update mask applied to the resource. Only "display_name" is currently supported.

options object <optional>

Call options. See CallOptions for more details.

updateProjectBillingInfo(request, optionsopt) → {Promise}

Sets or updates the billing account associated with a project. You specify the new billing account by setting the billing_account_name in the ProjectBillingInfo resource to the resource name of a billing account. Associating a project with an open billing account enables billing on the project and allows charges for resource usage. If the project already had a billing account, this method changes the billing account used for resource usage charges.

Note: Incurred charges that have not yet been reported in the transaction history of the GCP Console might be billed to the new billing account, even if the charge occurred before the new billing account was assigned to the project.

The current authenticated user must have ownership privileges for both the project and the billing account.

You can disable billing on the project by setting the billing_account_name field to empty. This action disassociates the current billing account from the project. Any billable activity of your in-use services will stop, and your application could stop functioning as expected. Any unbilled charges to date will be billed to the previously associated account. The current authenticated user must be either an owner of the project or an owner of the billing account for the project.

Note that associating a project with a closed billing account will have much the same effect as disabling billing on the project: any paid resources used by the project will be shut down. Thus, unless you wish to disable billing, you should always call this method with the name of an open billing account.

Parameters:
Name Type Attributes Description
request Object

The request object that will be sent.

Properties
Name Type Description
name string

Required. The resource name of the project associated with the billing information that you want to update. For example, projects/tokyo-rain-123.

projectBillingInfo google.cloud.billing.v1.ProjectBillingInfo

The new billing information for the project. Read-only fields are ignored; thus, you can leave empty all fields except billing_account_name.

options object <optional>

Call options. See CallOptions for more details.