0.0.20240510 • Published 8 days ago

@maxim_mazurok/gapi.client.cloudbilling-v1 v0.0.20240510

Weekly downloads
-
License
MIT
Repository
github
Last release
8 days ago

TypeScript typings for Cloud Billing API v1

Allows developers to manage billing for their Google Cloud Platform projects programmatically. For detailed description please check documentation.

Installing

Install typings for Cloud Billing API:

npm install @types/gapi.client.cloudbilling-v1 --save-dev

Usage

You need to initialize Google API client in your code:

gapi.load('client', () => {
  // now we can use gapi.client
  // ...
});

Then load api client wrapper:

gapi.client.load(
  'https://cloudbilling.googleapis.com/$discovery/rest?version=v1',
  () => {
    // now we can use:
    // gapi.client.cloudbilling
  }
);
// Deprecated, use discovery document URL, see https://github.com/google/google-api-javascript-client/blob/master/docs/reference.md#----gapiclientloadname----version----callback--
gapi.client.load('cloudbilling', 'v1', () => {
  // now we can use:
  // gapi.client.cloudbilling
});

Don't forget to authenticate your client before sending any request to resources:

// declare client_id registered in Google Developers Console
var client_id = '',
  scope = [
    // View and manage your Google Cloud Platform billing accounts
    'https://www.googleapis.com/auth/cloud-billing',

    // View your Google Cloud Platform billing accounts
    'https://www.googleapis.com/auth/cloud-billing.readonly',

    // See, edit, configure, and delete your Google Cloud data and see the email address for your Google Account.
    'https://www.googleapis.com/auth/cloud-platform',
  ],
  immediate = true;
// ...

gapi.auth.authorize(
  {client_id: client_id, scope: scope, immediate: immediate},
  authResult => {
    if (authResult && !authResult.error) {
      /* handle successful authorization */
    } else {
      /* handle authorization error */
    }
  }
);

After that you can use Cloud Billing API resources:

/*
This method creates [billing subaccounts](https://cloud.google.com/billing/docs/concepts#subaccounts). Google Cloud resellers should use the Channel Services APIs, [accounts.customers.create](https://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers/create) and [accounts.customers.entitlements.create](https://cloud.google.com/channel/docs/reference/rest/v1/accounts.customers.entitlements/create). When creating a subaccount, the current authenticated user must have the `billing.accounts.update` IAM permission on the parent account, which is typically given to billing account [administrators](https://cloud.google.com/billing/docs/how-to/billing-access). This method will return an error if the parent account has not been provisioned for subaccounts.
*/
await gapi.client.cloudbilling.billingAccounts.create({});

/*
Gets information about a billing account. The current authenticated user must be a [viewer of the billing account](https://cloud.google.com/billing/docs/how-to/billing-access).
*/
await gapi.client.cloudbilling.billingAccounts.get({name: 'name'});

/*
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](https://cloud.google.com/billing/docs/how-to/billing-access).
*/
await gapi.client.cloudbilling.billingAccounts.getIamPolicy({
  resource: 'resource',
});

/*
Lists the billing accounts that the current authenticated user has permission to [view](https://cloud.google.com/billing/docs/how-to/billing-access).
*/
await gapi.client.cloudbilling.billingAccounts.list({});

/*
Changes which parent organization a billing account belongs to.
*/
await gapi.client.cloudbilling.billingAccounts.move({name: 'name'});

/*
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](https://cloud.google.com/billing/docs/how-to/billing-access) of the billing account.
*/
await gapi.client.cloudbilling.billingAccounts.patch({name: 'name'});

/*
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](https://cloud.google.com/billing/docs/how-to/billing-access).
*/
await gapi.client.cloudbilling.billingAccounts.setIamPolicy({
  resource: 'resource',
});

/*
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.
*/
await gapi.client.cloudbilling.billingAccounts.testIamPermissions({
  resource: 'resource',
});

/*
Gets the billing information for a project. The current authenticated user must have the `resourcemanager.projects.get` permission for the project, which can be granted by assigning the [Project Viewer](https://cloud.google.com/iam/docs/understanding-roles#predefined_roles) role.
*/
await gapi.client.cloudbilling.projects.getBillingInfo({name: 'name'});

/*
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 Google Cloud 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](https://cloud.google.com/docs/permissions-overview#h.bgs0oxofvnoo ) and the [billing account](https://cloud.google.com/billing/docs/how-to/billing-access). 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.
*/
await gapi.client.cloudbilling.projects.updateBillingInfo({name: 'name'});

/*
Lists all public cloud services.
*/
await gapi.client.cloudbilling.services.list({});
0.0.20240510

8 days ago

0.0.20240507

12 days ago

0.0.20240503

15 days ago

0.0.20240419

29 days ago

0.0.20240412

1 month ago

0.0.20240315

2 months ago

0.0.20240311

2 months ago

0.0.20240301

3 months ago

0.0.20240214

3 months ago

0.0.20240209

3 months ago

0.0.20240206

3 months ago

0.0.20240126

4 months ago

0.0.20240119

4 months ago

0.0.20240112

4 months ago

0.0.20240102

5 months ago

0.0.20231215

5 months ago

0.0.20231208

5 months ago

0.0.20231201

6 months ago

0.0.20230818

9 months ago

0.0.20231109

6 months ago

0.0.20230813

9 months ago

0.0.20231115

6 months ago

0.0.20230929

8 months ago

0.0.20230728

10 months ago

0.0.20230803

10 months ago

0.0.20230804

10 months ago

0.0.20230922

8 months ago

0.0.20230724

10 months ago

0.0.20231020

7 months ago

0.0.20231025

7 months ago

0.0.20231103

7 months ago

0.0.20230915

8 months ago

0.0.20230717

10 months ago

0.0.20231006

7 months ago

0.0.20230710

10 months ago

0.0.20230629

11 months ago

0.0.20230908

8 months ago

0.0.20230825

9 months ago

0.0.20230901

9 months ago

0.0.20231120

6 months ago

0.0.20231124

6 months ago

0.0.20230612

11 months ago

0.0.20230616

11 months ago

0.0.20230614

11 months ago

0.0.20230515

1 year ago

0.0.20230521

1 year ago

0.0.20230509

1 year ago

0.0.20230502

1 year ago

0.0.20230501

1 year ago

0.0.20230605

12 months ago

0.0.20230507

1 year ago

0.0.20230409

1 year ago

0.0.20230313

1 year ago

0.0.20230424

1 year ago

0.0.20230402

1 year ago

0.0.20230309

1 year ago

0.0.20230416

1 year ago

0.0.20230322

1 year ago

0.0.20230320

1 year ago

0.0.20230130

1 year ago

0.0.20221206

1 year ago

0.0.20221029

2 years ago

0.0.20221024

2 years ago

0.0.20220817

2 years ago

0.0.20220908

2 years ago

0.0.20220914

2 years ago

0.0.20220722

2 years ago