Cloud Quotas client libraries
This page shows how to get started with the Cloud Client Libraries for the Cloud Quotas API. Client libraries make it easier to access Google Cloud APIs from a supported language. Although you can use Google Cloud APIs directly by making raw requests to the server, client libraries provide simplifications that significantly reduce the amount of code you need to write.
Read more about the Cloud Client Libraries and the older Google API Client Libraries in Client libraries explained.
Install the client library
C++
For information about this client library's requirements and install dependencies, see Setting up a C++ development environment.C#
Install theGoogle.Cloud.CloudQuotas.V1 package
from NuGet. Add it to your project in the normal way (for example by right-clicking
on the project in Visual Studio and choosing "Manage NuGet Packages...").
Ensure you enable pre-release packages (for example, in the Visual Studio NuGet
user interface, check the "Include prerelease" box). Some of the following samples
might only work with the latest pre-release version (1.0.0-beta01) of
Google.Cloud.CloudQuotas.V1.
For more information, see Setting Up a C# Development Environment.
Go
go get cloud.google.com/go/cloudquotas
For more information, see Setting Up a Go Development Environment.
Java
If you are using Maven, add
the following to your pom.xml file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.70.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-cloudquotas</artifactId>
</dependency>
</dependencies>If you are using Gradle, add the following to your dependencies:
implementation'com.google.cloud:google-cloud-cloudquotas:0.45.0'If you are using sbt, add the following to your dependencies:
libraryDependencies+="com.google.cloud"%"google-cloud-cloudquotas"%"0.45.0"For more information, see Setting Up a Java Development Environment.
Node.js
npm install @google-cloud/cloudquotas
For more information, see Setting Up a Node.js Development Environment.
PHP
composer require google/cloud
For more information, see Using PHP on Google Cloud.
Python
pip install google-cloud-quotas
For more information, see Setting Up a Python Development Environment.
Ruby
gem install google-cloud-cloud_quotas
For more information, see Setting Up a Ruby Development Environment.
Set up authentication
To authenticate calls to Google Cloud APIs, client libraries support Application Default Credentials (ADC); the libraries look for credentials in a set of defined locations and use those credentials to authenticate requests to the API. With ADC, you can make credentials available to your application in a variety of environments, such as local development or production, without needing to modify your application code.For production environments, the way you set up ADC depends on the service and context. For more information, see Set up Application Default Credentials.
For a local development environment, you can set up ADC with the credentials that are associated with your Google Account:
-
Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloudinit
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloudauthapplication-defaultlogin
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
A sign-in screen appears. After you sign in, your credentials are stored in the local credential file used by ADC.
Use the client library
The following example shows how to use the client library.
C++
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! [all]
#include"google/cloud/cloudquotas/v1/cloud_quotas_client.h"
#include"google/cloud/location.h"
#include <iostream>
#include <string>
intmain(intargc,char*argv[])try{
if(argc!=2){
std::cerr << "Usage: " << argv[0] << " project-id\n";
return1;
}
namespacecloudquotas=::google::cloud::cloudquotas_v1;
autoclient=
cloudquotas::CloudQuotasClient(cloudquotas::MakeCloudQuotasConnection());
autoconstparent=google::cloud::Location(argv[1],"global").FullName();
for(autor:client.ListQuotaPreferences(parent)){
if(!r)throwstd::move(r).status();
std::cout << r->DebugString() << "\n";
}
return0;
}catch(google::cloud::Statusconst&status){
std::cerr << "google::cloud::Status thrown: " << status << "\n";
return1;
}
//! [all]
C#
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Generated code. DO NOT EDIT!
namespaceGoogleCSharpSnippets
{
usingGoogle.Api.Gax ;
usingGoogle.Cloud.CloudQuotas.V1 ;
usingGoogle.Protobuf.WellKnownTypes ;
usingSystem;
usingSystem.Linq;
usingSystem.Threading.Tasks;
/// <summary>Generated snippets.</summary>
publicsealedclassAllGeneratedCloudQuotasClientSnippets
{
/// <summary>Snippet for ListQuotaInfos</summary>
publicvoidListQuotaInfosRequestObject()
{
// Snippet: ListQuotaInfos(ListQuotaInfosRequest, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
ListQuotaInfosRequest request=newListQuotaInfosRequest
{
ParentAsServiceName=ServiceName .FromProjectLocationService ("[PROJECT]","[LOCATION]","[SERVICE]"),
};
// Make the request
PagedEnumerable<ListQuotaInfosResponse,QuotaInfo>response=cloudQuotasClient.ListQuotaInfos (request);
// Iterate over all response items, lazily performing RPCs as required
foreach(QuotaInfo iteminresponse)
{
// Do something with each item
Console.WriteLine(item);
}
// Or iterate over pages (of server-defined size), performing one RPC per page
foreach(ListQuotaInfosResponse pageinresponse.AsRawResponses())
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaInfo iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
}
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaInfo>singlePage=response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaInfo iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaInfosAsync</summary>
publicasyncTaskListQuotaInfosRequestObjectAsync()
{
// Snippet: ListQuotaInfosAsync(ListQuotaInfosRequest, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
ListQuotaInfosRequest request=newListQuotaInfosRequest
{
ParentAsServiceName=ServiceName .FromProjectLocationService ("[PROJECT]","[LOCATION]","[SERVICE]"),
};
// Make the request
PagedAsyncEnumerable<ListQuotaInfosResponse,QuotaInfo>response=cloudQuotasClient.ListQuotaInfosAsync (request);
// Iterate over all response items, lazily performing RPCs as required
awaitresponse.ForEachAsync((QuotaInfoitem)=>
{
// Do something with each item
Console.WriteLine(item);
});
// Or iterate over pages (of server-defined size), performing one RPC per page
awaitresponse.AsRawResponses().ForEachAsync((ListQuotaInfosResponsepage)=>
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaInfo iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
});
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaInfo>singlePage=awaitresponse.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaInfo iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaInfos</summary>
publicvoidListQuotaInfos()
{
// Snippet: ListQuotaInfos(string, string, int?, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
stringparent="projects/[PROJECT]/locations/[LOCATION]/services/[SERVICE]";
// Make the request
PagedEnumerable<ListQuotaInfosResponse,QuotaInfo>response=cloudQuotasClient.ListQuotaInfos (parent);
// Iterate over all response items, lazily performing RPCs as required
foreach(QuotaInfo iteminresponse)
{
// Do something with each item
Console.WriteLine(item);
}
// Or iterate over pages (of server-defined size), performing one RPC per page
foreach(ListQuotaInfosResponse pageinresponse.AsRawResponses())
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaInfo iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
}
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaInfo>singlePage=response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaInfo iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaInfosAsync</summary>
publicasyncTaskListQuotaInfosAsync()
{
// Snippet: ListQuotaInfosAsync(string, string, int?, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
stringparent="projects/[PROJECT]/locations/[LOCATION]/services/[SERVICE]";
// Make the request
PagedAsyncEnumerable<ListQuotaInfosResponse,QuotaInfo>response=cloudQuotasClient.ListQuotaInfosAsync (parent);
// Iterate over all response items, lazily performing RPCs as required
awaitresponse.ForEachAsync((QuotaInfoitem)=>
{
// Do something with each item
Console.WriteLine(item);
});
// Or iterate over pages (of server-defined size), performing one RPC per page
awaitresponse.AsRawResponses().ForEachAsync((ListQuotaInfosResponsepage)=>
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaInfo iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
});
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaInfo>singlePage=awaitresponse.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaInfo iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaInfos</summary>
publicvoidListQuotaInfosResourceNames()
{
// Snippet: ListQuotaInfos(ServiceName, string, int?, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
ServiceName parent=ServiceName .FromProjectLocationService ("[PROJECT]","[LOCATION]","[SERVICE]");
// Make the request
PagedEnumerable<ListQuotaInfosResponse,QuotaInfo>response=cloudQuotasClient.ListQuotaInfos (parent);
// Iterate over all response items, lazily performing RPCs as required
foreach(QuotaInfo iteminresponse)
{
// Do something with each item
Console.WriteLine(item);
}
// Or iterate over pages (of server-defined size), performing one RPC per page
foreach(ListQuotaInfosResponse pageinresponse.AsRawResponses())
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaInfo iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
}
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaInfo>singlePage=response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaInfo iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaInfosAsync</summary>
publicasyncTaskListQuotaInfosResourceNamesAsync()
{
// Snippet: ListQuotaInfosAsync(ServiceName, string, int?, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
ServiceName parent=ServiceName .FromProjectLocationService ("[PROJECT]","[LOCATION]","[SERVICE]");
// Make the request
PagedAsyncEnumerable<ListQuotaInfosResponse,QuotaInfo>response=cloudQuotasClient.ListQuotaInfosAsync (parent);
// Iterate over all response items, lazily performing RPCs as required
awaitresponse.ForEachAsync((QuotaInfoitem)=>
{
// Do something with each item
Console.WriteLine(item);
});
// Or iterate over pages (of server-defined size), performing one RPC per page
awaitresponse.AsRawResponses().ForEachAsync((ListQuotaInfosResponsepage)=>
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaInfo iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
});
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaInfo>singlePage=awaitresponse.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaInfo iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for GetQuotaInfo</summary>
publicvoidGetQuotaInfoRequestObject()
{
// Snippet: GetQuotaInfo(GetQuotaInfoRequest, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
GetQuotaInfoRequest request=newGetQuotaInfoRequest
{
QuotaInfoName=QuotaInfoName .FromProjectLocationServiceQuotaInfo ("[PROJECT]","[LOCATION]","[SERVICE]","[QUOTA_INFO]"),
};
// Make the request
QuotaInfo response=cloudQuotasClient.GetQuotaInfo (request);
// End snippet
}
/// <summary>Snippet for GetQuotaInfoAsync</summary>
publicasyncTaskGetQuotaInfoRequestObjectAsync()
{
// Snippet: GetQuotaInfoAsync(GetQuotaInfoRequest, CallSettings)
// Additional: GetQuotaInfoAsync(GetQuotaInfoRequest, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
GetQuotaInfoRequest request=newGetQuotaInfoRequest
{
QuotaInfoName=QuotaInfoName .FromProjectLocationServiceQuotaInfo ("[PROJECT]","[LOCATION]","[SERVICE]","[QUOTA_INFO]"),
};
// Make the request
QuotaInfo response=awaitcloudQuotasClient.GetQuotaInfoAsync (request);
// End snippet
}
/// <summary>Snippet for GetQuotaInfo</summary>
publicvoidGetQuotaInfo()
{
// Snippet: GetQuotaInfo(string, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
stringname="projects/[PROJECT]/locations/[LOCATION]/services/[SERVICE]/quotaInfos/[QUOTA_INFO]";
// Make the request
QuotaInfo response=cloudQuotasClient.GetQuotaInfo (name);
// End snippet
}
/// <summary>Snippet for GetQuotaInfoAsync</summary>
publicasyncTaskGetQuotaInfoAsync()
{
// Snippet: GetQuotaInfoAsync(string, CallSettings)
// Additional: GetQuotaInfoAsync(string, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
stringname="projects/[PROJECT]/locations/[LOCATION]/services/[SERVICE]/quotaInfos/[QUOTA_INFO]";
// Make the request
QuotaInfo response=awaitcloudQuotasClient.GetQuotaInfoAsync (name);
// End snippet
}
/// <summary>Snippet for GetQuotaInfo</summary>
publicvoidGetQuotaInfoResourceNames()
{
// Snippet: GetQuotaInfo(QuotaInfoName, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
QuotaInfoName name=QuotaInfoName .FromProjectLocationServiceQuotaInfo ("[PROJECT]","[LOCATION]","[SERVICE]","[QUOTA_INFO]");
// Make the request
QuotaInfo response=cloudQuotasClient.GetQuotaInfo (name);
// End snippet
}
/// <summary>Snippet for GetQuotaInfoAsync</summary>
publicasyncTaskGetQuotaInfoResourceNamesAsync()
{
// Snippet: GetQuotaInfoAsync(QuotaInfoName, CallSettings)
// Additional: GetQuotaInfoAsync(QuotaInfoName, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
QuotaInfoName name=QuotaInfoName .FromProjectLocationServiceQuotaInfo ("[PROJECT]","[LOCATION]","[SERVICE]","[QUOTA_INFO]");
// Make the request
QuotaInfo response=awaitcloudQuotasClient.GetQuotaInfoAsync (name);
// End snippet
}
/// <summary>Snippet for ListQuotaPreferences</summary>
publicvoidListQuotaPreferencesRequestObject()
{
// Snippet: ListQuotaPreferences(ListQuotaPreferencesRequest, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
ListQuotaPreferencesRequest request=newListQuotaPreferencesRequest
{
ParentAsLocationName=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]"),
Filter="",
OrderBy="",
};
// Make the request
PagedEnumerable<ListQuotaPreferencesResponse,QuotaPreference>response=cloudQuotasClient.ListQuotaPreferences (request);
// Iterate over all response items, lazily performing RPCs as required
foreach(QuotaPreference iteminresponse)
{
// Do something with each item
Console.WriteLine(item);
}
// Or iterate over pages (of server-defined size), performing one RPC per page
foreach(ListQuotaPreferencesResponse pageinresponse.AsRawResponses())
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaPreference iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
}
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaPreference>singlePage=response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaPreference iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaPreferencesAsync</summary>
publicasyncTaskListQuotaPreferencesRequestObjectAsync()
{
// Snippet: ListQuotaPreferencesAsync(ListQuotaPreferencesRequest, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
ListQuotaPreferencesRequest request=newListQuotaPreferencesRequest
{
ParentAsLocationName=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]"),
Filter="",
OrderBy="",
};
// Make the request
PagedAsyncEnumerable<ListQuotaPreferencesResponse,QuotaPreference>response=cloudQuotasClient.ListQuotaPreferencesAsync (request);
// Iterate over all response items, lazily performing RPCs as required
awaitresponse.ForEachAsync((QuotaPreferenceitem)=>
{
// Do something with each item
Console.WriteLine(item);
});
// Or iterate over pages (of server-defined size), performing one RPC per page
awaitresponse.AsRawResponses().ForEachAsync((ListQuotaPreferencesResponsepage)=>
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaPreference iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
});
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaPreference>singlePage=awaitresponse.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaPreference iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaPreferences</summary>
publicvoidListQuotaPreferences()
{
// Snippet: ListQuotaPreferences(string, string, int?, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
stringparent="projects/[PROJECT]/locations/[LOCATION]";
// Make the request
PagedEnumerable<ListQuotaPreferencesResponse,QuotaPreference>response=cloudQuotasClient.ListQuotaPreferences (parent);
// Iterate over all response items, lazily performing RPCs as required
foreach(QuotaPreference iteminresponse)
{
// Do something with each item
Console.WriteLine(item);
}
// Or iterate over pages (of server-defined size), performing one RPC per page
foreach(ListQuotaPreferencesResponse pageinresponse.AsRawResponses())
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaPreference iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
}
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaPreference>singlePage=response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaPreference iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaPreferencesAsync</summary>
publicasyncTaskListQuotaPreferencesAsync()
{
// Snippet: ListQuotaPreferencesAsync(string, string, int?, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
stringparent="projects/[PROJECT]/locations/[LOCATION]";
// Make the request
PagedAsyncEnumerable<ListQuotaPreferencesResponse,QuotaPreference>response=cloudQuotasClient.ListQuotaPreferencesAsync (parent);
// Iterate over all response items, lazily performing RPCs as required
awaitresponse.ForEachAsync((QuotaPreferenceitem)=>
{
// Do something with each item
Console.WriteLine(item);
});
// Or iterate over pages (of server-defined size), performing one RPC per page
awaitresponse.AsRawResponses().ForEachAsync((ListQuotaPreferencesResponsepage)=>
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaPreference iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
});
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaPreference>singlePage=awaitresponse.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaPreference iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaPreferences</summary>
publicvoidListQuotaPreferencesResourceNames()
{
// Snippet: ListQuotaPreferences(LocationName, string, int?, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
LocationName parent=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]");
// Make the request
PagedEnumerable<ListQuotaPreferencesResponse,QuotaPreference>response=cloudQuotasClient.ListQuotaPreferences (parent);
// Iterate over all response items, lazily performing RPCs as required
foreach(QuotaPreference iteminresponse)
{
// Do something with each item
Console.WriteLine(item);
}
// Or iterate over pages (of server-defined size), performing one RPC per page
foreach(ListQuotaPreferencesResponse pageinresponse.AsRawResponses())
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaPreference iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
}
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaPreference>singlePage=response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaPreference iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for ListQuotaPreferencesAsync</summary>
publicasyncTaskListQuotaPreferencesResourceNamesAsync()
{
// Snippet: ListQuotaPreferencesAsync(LocationName, string, int?, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
LocationName parent=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]");
// Make the request
PagedAsyncEnumerable<ListQuotaPreferencesResponse,QuotaPreference>response=cloudQuotasClient.ListQuotaPreferencesAsync (parent);
// Iterate over all response items, lazily performing RPCs as required
awaitresponse.ForEachAsync((QuotaPreferenceitem)=>
{
// Do something with each item
Console.WriteLine(item);
});
// Or iterate over pages (of server-defined size), performing one RPC per page
awaitresponse.AsRawResponses().ForEachAsync((ListQuotaPreferencesResponsepage)=>
{
// Do something with each page of items
Console.WriteLine("A page of results:");
foreach(QuotaPreference iteminpage)
{
// Do something with each item
Console.WriteLine(item);
}
});
// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
intpageSize=10;
Page<QuotaPreference>singlePage=awaitresponse.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach(QuotaPreference iteminsinglePage)
{
// Do something with each item
Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
stringnextPageToken=singlePage.NextPageToken;
// End snippet
}
/// <summary>Snippet for GetQuotaPreference</summary>
publicvoidGetQuotaPreferenceRequestObject()
{
// Snippet: GetQuotaPreference(GetQuotaPreferenceRequest, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
GetQuotaPreferenceRequest request=newGetQuotaPreferenceRequest
{
QuotaPreferenceName=QuotaPreferenceName .FromProjectLocationQuotaPreference ("[PROJECT]","[LOCATION]","[QUOTA_PREFERENCE]"),
};
// Make the request
QuotaPreference response=cloudQuotasClient.GetQuotaPreference (request);
// End snippet
}
/// <summary>Snippet for GetQuotaPreferenceAsync</summary>
publicasyncTaskGetQuotaPreferenceRequestObjectAsync()
{
// Snippet: GetQuotaPreferenceAsync(GetQuotaPreferenceRequest, CallSettings)
// Additional: GetQuotaPreferenceAsync(GetQuotaPreferenceRequest, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
GetQuotaPreferenceRequest request=newGetQuotaPreferenceRequest
{
QuotaPreferenceName=QuotaPreferenceName .FromProjectLocationQuotaPreference ("[PROJECT]","[LOCATION]","[QUOTA_PREFERENCE]"),
};
// Make the request
QuotaPreference response=awaitcloudQuotasClient.GetQuotaPreferenceAsync (request);
// End snippet
}
/// <summary>Snippet for GetQuotaPreference</summary>
publicvoidGetQuotaPreference()
{
// Snippet: GetQuotaPreference(string, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
stringname="projects/[PROJECT]/locations/[LOCATION]/quotaPreferences/[QUOTA_PREFERENCE]";
// Make the request
QuotaPreference response=cloudQuotasClient.GetQuotaPreference (name);
// End snippet
}
/// <summary>Snippet for GetQuotaPreferenceAsync</summary>
publicasyncTaskGetQuotaPreferenceAsync()
{
// Snippet: GetQuotaPreferenceAsync(string, CallSettings)
// Additional: GetQuotaPreferenceAsync(string, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
stringname="projects/[PROJECT]/locations/[LOCATION]/quotaPreferences/[QUOTA_PREFERENCE]";
// Make the request
QuotaPreference response=awaitcloudQuotasClient.GetQuotaPreferenceAsync (name);
// End snippet
}
/// <summary>Snippet for GetQuotaPreference</summary>
publicvoidGetQuotaPreferenceResourceNames()
{
// Snippet: GetQuotaPreference(QuotaPreferenceName, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
QuotaPreferenceName name=QuotaPreferenceName .FromProjectLocationQuotaPreference ("[PROJECT]","[LOCATION]","[QUOTA_PREFERENCE]");
// Make the request
QuotaPreference response=cloudQuotasClient.GetQuotaPreference (name);
// End snippet
}
/// <summary>Snippet for GetQuotaPreferenceAsync</summary>
publicasyncTaskGetQuotaPreferenceResourceNamesAsync()
{
// Snippet: GetQuotaPreferenceAsync(QuotaPreferenceName, CallSettings)
// Additional: GetQuotaPreferenceAsync(QuotaPreferenceName, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
QuotaPreferenceName name=QuotaPreferenceName .FromProjectLocationQuotaPreference ("[PROJECT]","[LOCATION]","[QUOTA_PREFERENCE]");
// Make the request
QuotaPreference response=awaitcloudQuotasClient.GetQuotaPreferenceAsync (name);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreference</summary>
publicvoidCreateQuotaPreferenceRequestObject()
{
// Snippet: CreateQuotaPreference(CreateQuotaPreferenceRequest, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
CreateQuotaPreferenceRequest request=newCreateQuotaPreferenceRequest
{
ParentAsLocationName=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]"),
QuotaPreferenceId="",
QuotaPreference=newQuotaPreference (),
IgnoreSafetyChecks=
{
QuotaSafetyCheck .Unspecified ,
},
};
// Make the request
QuotaPreference response=cloudQuotasClient.CreateQuotaPreference (request);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreferenceAsync</summary>
publicasyncTaskCreateQuotaPreferenceRequestObjectAsync()
{
// Snippet: CreateQuotaPreferenceAsync(CreateQuotaPreferenceRequest, CallSettings)
// Additional: CreateQuotaPreferenceAsync(CreateQuotaPreferenceRequest, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
CreateQuotaPreferenceRequest request=newCreateQuotaPreferenceRequest
{
ParentAsLocationName=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]"),
QuotaPreferenceId="",
QuotaPreference=newQuotaPreference (),
IgnoreSafetyChecks=
{
QuotaSafetyCheck .Unspecified ,
},
};
// Make the request
QuotaPreference response=awaitcloudQuotasClient.CreateQuotaPreferenceAsync (request);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreference</summary>
publicvoidCreateQuotaPreference1()
{
// Snippet: CreateQuotaPreference(string, QuotaPreference, string, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
stringparent="projects/[PROJECT]/locations/[LOCATION]";
QuotaPreference quotaPreference=newQuotaPreference ();
stringquotaPreferenceId="";
// Make the request
QuotaPreference response=cloudQuotasClient.CreateQuotaPreference (parent,quotaPreference,quotaPreferenceId);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreferenceAsync</summary>
publicasyncTaskCreateQuotaPreference1Async()
{
// Snippet: CreateQuotaPreferenceAsync(string, QuotaPreference, string, CallSettings)
// Additional: CreateQuotaPreferenceAsync(string, QuotaPreference, string, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
stringparent="projects/[PROJECT]/locations/[LOCATION]";
QuotaPreference quotaPreference=newQuotaPreference ();
stringquotaPreferenceId="";
// Make the request
QuotaPreference response=awaitcloudQuotasClient.CreateQuotaPreferenceAsync (parent,quotaPreference,quotaPreferenceId);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreference</summary>
publicvoidCreateQuotaPreference1ResourceNames()
{
// Snippet: CreateQuotaPreference(LocationName, QuotaPreference, string, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
LocationName parent=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]");
QuotaPreference quotaPreference=newQuotaPreference ();
stringquotaPreferenceId="";
// Make the request
QuotaPreference response=cloudQuotasClient.CreateQuotaPreference (parent,quotaPreference,quotaPreferenceId);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreferenceAsync</summary>
publicasyncTaskCreateQuotaPreference1ResourceNamesAsync()
{
// Snippet: CreateQuotaPreferenceAsync(LocationName, QuotaPreference, string, CallSettings)
// Additional: CreateQuotaPreferenceAsync(LocationName, QuotaPreference, string, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
LocationName parent=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]");
QuotaPreference quotaPreference=newQuotaPreference ();
stringquotaPreferenceId="";
// Make the request
QuotaPreference response=awaitcloudQuotasClient.CreateQuotaPreferenceAsync (parent,quotaPreference,quotaPreferenceId);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreference</summary>
publicvoidCreateQuotaPreference2()
{
// Snippet: CreateQuotaPreference(string, QuotaPreference, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
stringparent="projects/[PROJECT]/locations/[LOCATION]";
QuotaPreference quotaPreference=newQuotaPreference ();
// Make the request
QuotaPreference response=cloudQuotasClient.CreateQuotaPreference (parent,quotaPreference);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreferenceAsync</summary>
publicasyncTaskCreateQuotaPreference2Async()
{
// Snippet: CreateQuotaPreferenceAsync(string, QuotaPreference, CallSettings)
// Additional: CreateQuotaPreferenceAsync(string, QuotaPreference, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
stringparent="projects/[PROJECT]/locations/[LOCATION]";
QuotaPreference quotaPreference=newQuotaPreference ();
// Make the request
QuotaPreference response=awaitcloudQuotasClient.CreateQuotaPreferenceAsync (parent,quotaPreference);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreference</summary>
publicvoidCreateQuotaPreference2ResourceNames()
{
// Snippet: CreateQuotaPreference(LocationName, QuotaPreference, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
LocationName parent=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]");
QuotaPreference quotaPreference=newQuotaPreference ();
// Make the request
QuotaPreference response=cloudQuotasClient.CreateQuotaPreference (parent,quotaPreference);
// End snippet
}
/// <summary>Snippet for CreateQuotaPreferenceAsync</summary>
publicasyncTaskCreateQuotaPreference2ResourceNamesAsync()
{
// Snippet: CreateQuotaPreferenceAsync(LocationName, QuotaPreference, CallSettings)
// Additional: CreateQuotaPreferenceAsync(LocationName, QuotaPreference, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
LocationName parent=LocationName .FromProjectLocation ("[PROJECT]","[LOCATION]");
QuotaPreference quotaPreference=newQuotaPreference ();
// Make the request
QuotaPreference response=awaitcloudQuotasClient.CreateQuotaPreferenceAsync (parent,quotaPreference);
// End snippet
}
/// <summary>Snippet for UpdateQuotaPreference</summary>
publicvoidUpdateQuotaPreferenceRequestObject()
{
// Snippet: UpdateQuotaPreference(UpdateQuotaPreferenceRequest, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
UpdateQuotaPreferenceRequest request=newUpdateQuotaPreferenceRequest
{
UpdateMask=newFieldMask (),
QuotaPreference=newQuotaPreference (),
AllowMissing=false,
ValidateOnly=false,
IgnoreSafetyChecks=
{
QuotaSafetyCheck .Unspecified ,
},
};
// Make the request
QuotaPreference response=cloudQuotasClient.UpdateQuotaPreference (request);
// End snippet
}
/// <summary>Snippet for UpdateQuotaPreferenceAsync</summary>
publicasyncTaskUpdateQuotaPreferenceRequestObjectAsync()
{
// Snippet: UpdateQuotaPreferenceAsync(UpdateQuotaPreferenceRequest, CallSettings)
// Additional: UpdateQuotaPreferenceAsync(UpdateQuotaPreferenceRequest, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
UpdateQuotaPreferenceRequest request=newUpdateQuotaPreferenceRequest
{
UpdateMask=newFieldMask (),
QuotaPreference=newQuotaPreference (),
AllowMissing=false,
ValidateOnly=false,
IgnoreSafetyChecks=
{
QuotaSafetyCheck .Unspecified ,
},
};
// Make the request
QuotaPreference response=awaitcloudQuotasClient.UpdateQuotaPreferenceAsync (request);
// End snippet
}
/// <summary>Snippet for UpdateQuotaPreference</summary>
publicvoidUpdateQuotaPreference()
{
// Snippet: UpdateQuotaPreference(QuotaPreference, FieldMask, CallSettings)
// Create client
CloudQuotasClient cloudQuotasClient=CloudQuotasClient .Create ();
// Initialize request argument(s)
QuotaPreference quotaPreference=newQuotaPreference ();
FieldMask updateMask=newFieldMask ();
// Make the request
QuotaPreference response=cloudQuotasClient.UpdateQuotaPreference (quotaPreference,updateMask);
// End snippet
}
/// <summary>Snippet for UpdateQuotaPreferenceAsync</summary>
publicasyncTaskUpdateQuotaPreferenceAsync()
{
// Snippet: UpdateQuotaPreferenceAsync(QuotaPreference, FieldMask, CallSettings)
// Additional: UpdateQuotaPreferenceAsync(QuotaPreference, FieldMask, CancellationToken)
// Create client
CloudQuotasClient cloudQuotasClient=awaitCloudQuotasClient .CreateAsync ();
// Initialize request argument(s)
QuotaPreference quotaPreference=newQuotaPreference ();
FieldMask updateMask=newFieldMask ();
// Make the request
QuotaPreference response=awaitcloudQuotasClient.UpdateQuotaPreferenceAsync (quotaPreference,updateMask);
// End snippet
}
}
}
Go
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
packagecloudquotas_test
import(
"context"
cloudquotas"cloud.google.com/go/cloudquotas/apiv1"
cloudquotaspb"cloud.google.com/go/cloudquotas/apiv1/cloudquotaspb"
"google.golang.org/api/iterator"
)
funcExampleNewClient(){
ctx:=context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c,err:=cloudquotas.NewClient (ctx)
iferr!=nil{
// TODO: Handle error.
}
deferc.Close ()
// TODO: Use client.
_=c
}
funcExampleNewRESTClient(){
ctx:=context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c,err:=cloudquotas.NewRESTClient (ctx)
iferr!=nil{
// TODO: Handle error.
}
deferc.Close ()
// TODO: Use client.
_=c
}
funcExampleClient_CreateQuotaPreference(){
ctx:=context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c,err:=cloudquotas.NewClient (ctx)
iferr!=nil{
// TODO: Handle error.
}
deferc.Close ()
req:=&cloudquotaspb.CreateQuotaPreferenceRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/cloudquotas/apiv1/cloudquotaspb#CreateQuotaPreferenceRequest.
}
resp,err:=c.CreateQuotaPreference(ctx,req)
iferr!=nil{
// TODO: Handle error.
}
// TODO: Use resp.
_=resp
}
funcExampleClient_GetQuotaInfo(){
ctx:=context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c,err:=cloudquotas.NewClient (ctx)
iferr!=nil{
// TODO: Handle error.
}
deferc.Close ()
req:=&cloudquotaspb.GetQuotaInfoRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/cloudquotas/apiv1/cloudquotaspb#GetQuotaInfoRequest.
}
resp,err:=c.GetQuotaInfo(ctx,req)
iferr!=nil{
// TODO: Handle error.
}
// TODO: Use resp.
_=resp
}
funcExampleClient_GetQuotaPreference(){
ctx:=context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c,err:=cloudquotas.NewClient (ctx)
iferr!=nil{
// TODO: Handle error.
}
deferc.Close ()
req:=&cloudquotaspb.GetQuotaPreferenceRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/cloudquotas/apiv1/cloudquotaspb#GetQuotaPreferenceRequest.
}
resp,err:=c.GetQuotaPreference(ctx,req)
iferr!=nil{
// TODO: Handle error.
}
// TODO: Use resp.
_=resp
}
funcExampleClient_ListQuotaInfos(){
ctx:=context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c,err:=cloudquotas.NewClient (ctx)
iferr!=nil{
// TODO: Handle error.
}
deferc.Close ()
req:=&cloudquotaspb.ListQuotaInfosRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/cloudquotas/apiv1/cloudquotaspb#ListQuotaInfosRequest.
}
it:=c.ListQuotaInfos(ctx,req)
for{
resp,err:=it.Next()
iferr==iterator.Done{
break
}
iferr!=nil{
// TODO: Handle error.
}
// TODO: Use resp.
_=resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_=it.Response.(*cloudquotaspb.ListQuotaInfosResponse)
}
}
funcExampleClient_ListQuotaPreferences(){
ctx:=context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c,err:=cloudquotas.NewClient (ctx)
iferr!=nil{
// TODO: Handle error.
}
deferc.Close ()
req:=&cloudquotaspb.ListQuotaPreferencesRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/cloudquotas/apiv1/cloudquotaspb#ListQuotaPreferencesRequest.
}
it:=c.ListQuotaPreferences(ctx,req)
for{
resp,err:=it.Next()
iferr==iterator.Done{
break
}
iferr!=nil{
// TODO: Handle error.
}
// TODO: Use resp.
_=resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_=it.Response.(*cloudquotaspb.ListQuotaPreferencesResponse)
}
}
funcExampleClient_UpdateQuotaPreference(){
ctx:=context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c,err:=cloudquotas.NewClient (ctx)
iferr!=nil{
// TODO: Handle error.
}
deferc.Close ()
req:=&cloudquotaspb.UpdateQuotaPreferenceRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/cloudquotas/apiv1/cloudquotaspb#UpdateQuotaPreferenceRequest.
}
resp,err:=c.UpdateQuotaPreference(ctx,req)
iferr!=nil{
// TODO: Handle error.
}
// TODO: Use resp.
_=resp
}
Java
/*
* Copyright 2025 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
packagecom.google.api.cloudquotas.v1.samples;
importcom.google.api.cloudquotas.v1.CloudQuotasClient ;
importcom.google.api.cloudquotas.v1.GetQuotaInfoRequest ;
importcom.google.api.cloudquotas.v1.QuotaInfo ;
importcom.google.api.cloudquotas.v1.QuotaInfoName ;
publicclass SyncGetQuotaInfo{
publicstaticvoidmain(String[]args)throwsException{
syncGetQuotaInfo();
}
publicstaticvoidsyncGetQuotaInfo()throwsException{
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try(CloudQuotasClient cloudQuotasClient=CloudQuotasClient .create()){
GetQuotaInfoRequest request=
GetQuotaInfoRequest .newBuilder()
.setName(
QuotaInfoName .ofProjectLocationServiceQuotaInfoName (
"[PROJECT]","[LOCATION]","[SERVICE]","[QUOTA_INFO]")
.toString())
.build();
QuotaInfo response=cloudQuotasClient.getQuotaInfo(request);
}
}
}
Node.js
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **
'use strict';
functionmain(name){
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
* Required. The resource name of the quota info.
* An example name:
* `projects/123/locations/global/services/compute.googleapis.com/quotaInfos/CpusPerProjectPerRegion`
*/
// const name = 'abc123'
// Imports the Cloudquotas library
const{CloudQuotasClient}=require('@google-cloud/cloudquotas').v1;
// Instantiates a client
constcloudquotasClient=newCloudQuotasClient ();
asyncfunctioncallGetQuotaInfo(){
// Construct request
constrequest={
name,
};
// Run request
constresponse=awaitcloudquotasClient.getQuotaInfo(request);
console.log(response);
}
callGetQuotaInfo();
}
process.on('unhandledRejection',err=>{
console.error(err.message);
process.exitCode=1;
});
main(...process.argv.slice(2));
PHP
<?php
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* GENERATED CODE WARNING
* This file was automatically generated - do not edit!
*/
require_once __DIR__ . '/../../../vendor/autoload.php';
use Google\ApiCore\ApiException;
use Google\Cloud\CloudQuotas\V1\Client\CloudQuotasClient;
use Google\Cloud\CloudQuotas\V1\GetQuotaInfoRequest;
use Google\Cloud\CloudQuotas\V1\QuotaInfo;
/**
* Retrieve the QuotaInfo of a quota for a project, folder or organization.
*
* @param string $formattedName The resource name of the quota info.
*
* An example name:
* `projects/123/locations/global/services/compute.googleapis.com/quotaInfos/CpusPerProjectPerRegion`
* Please see {@see CloudQuotasClient::quotaInfoName()} for help formatting this field.
*/
function get_quota_info_sample(string $formattedName): void
{
// Create a client.
$cloudQuotasClient = new CloudQuotasClient();
// Prepare the request message.
$request = (new GetQuotaInfoRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var QuotaInfo $response */
$response = $cloudQuotasClient->getQuotaInfo($request);
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
} catch (ApiException $ex) {
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
}
}
/**
* Helper to execute the sample.
*
* This sample has been automatically generated and should be regarded as a code
* template only. It will require modifications to work:
* - It may require correct/in-range values for request initialization.
* - It may require specifying regional endpoints when creating the service client,
* please see the apiEndpoint client configuration option for more details.
*/
function callSample(): void
{
$formattedName = CloudQuotasClient::quotaInfoName(
'[PROJECT]',
'[LOCATION]',
'[SERVICE]',
'[QUOTA_INFO]'
);
get_quota_info_sample($formattedName);
}
Python
# -*- coding: utf-8 -*-
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Generated code. DO NOT EDIT!
#
# Snippet for GetQuotaInfo
# NOTE: This snippet has been automatically generated for illustrative purposes only.
# It may require modifications to work in your environment.
# To install the latest published package dependency, execute the following:
# python3 -m pip install google-cloud-quotas
# This snippet has been automatically generated and should be regarded as a
# code template only.
# It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in:
# https://googleapis.dev/python/google-api-core/latest/client_options.html
fromgoogle.cloudimport cloudquotas_v1
defsample_get_quota_info():
# Create a client
client = cloudquotas_v1 .CloudQuotasClient ()
# Initialize request argument(s)
request = cloudquotas_v1 .GetQuotaInfoRequest (
name="name_value",
)
# Make the request
response = client.get_quota_info (request=request)
# Handle the response
print(response)
Ruby
# frozen_string_literal: true
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Auto-generated by gapic-generator-ruby. DO NOT EDIT!
require"google/cloud/cloud_quotas/v1"
##
# Snippet for the get_quota_info call in the CloudQuotas service
#
# This snippet has been automatically generated and should be regarded as a code
# template only. It will require modifications to work:
# - It may require correct/in-range values for request initialization.
# - It may require specifying regional endpoints when creating the service
# client as shown in https://cloud.google.com/ruby/docs/reference.
#
# This is an auto-generated example demonstrating basic usage of
# Google::Cloud::CloudQuotas::V1::CloudQuotas::Client#get_quota_info.
#
defget_quota_info
# Create a client object. The client can be reused for multiple calls.
client=Google::Cloud::CloudQuotas::V1::CloudQuotas::Client.new
# Create a request. To set request fields, pass in keyword arguments.
request=Google::Cloud::CloudQuotas::V1::GetQuotaInfoRequest.new
# Call the get_quota_info method.
result=client.get_quota_inforequest
# The returned object is of type Google::Cloud::CloudQuotas::V1::QuotaInfo.
presult
end
Additional resources
C++
The following list contains links to more resources related to the client library for C++:
C#
The following list contains links to more resources related to the client library for C#:
Go
The following list contains links to more resources related to the client library for Go:
Java
The following list contains links to more resources related to the client library for Java:
Node.js
The following list contains links to more resources related to the client library for Node.js:
PHP
The following list contains links to more resources related to the client library for PHP:
Python
The following list contains links to more resources related to the client library for Python:
Ruby
The following list contains links to more resources related to the client library for Ruby: