Stay organized with collections
Save and categorize content based on your preferences.
Merchant API code sample to list quota.
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.packageshopping.merchant.samples.quota.v1;importcom.google.api.gax.core.FixedCredentialsProvider;importcom.google.auth.oauth2.GoogleCredentials;importcom.google.shopping.merchant.quota.v1.ListQuotaGroupsRequest;importcom.google.shopping.merchant.quota.v1.QuotaGroup;importcom.google.shopping.merchant.quota.v1.QuotaServiceClient;importcom.google.shopping.merchant.quota.v1.QuotaServiceClient.ListQuotaGroupsPagedResponse;importcom.google.shopping.merchant.quota.v1.QuotaServiceSettings;importshopping.merchant.samples.utils.Authenticator;importshopping.merchant.samples.utils.Config;/** This class demonstrates how to list quota for a given Merchant Center account. */publicclassListQuotaSample{publicstaticvoidlistQuotas(StringaccountId)throwsException{GoogleCredentialscredential=newAuthenticator().authenticate();QuotaServiceSettingsquotasServiceSettings=QuotaServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();try(QuotaServiceClientquotaServiceClient=QuotaServiceClient.create(quotasServiceSettings)){ListQuotaGroupsRequestrequest=ListQuotaGroupsRequest.newBuilder().setParent(String.format("accounts/%s",accountId)).build();System.out.println("Sending list quotas request:");ListQuotaGroupsPagedResponseresponse=quotaServiceClient.listQuotaGroups(request);intcount=0;// Iterates over all rows in all pages and prints the quota group in each row.// Automatically uses the `nextPageToken` if returned to fetch all pages of data.for(QuotaGroupquota:response.iterateAll()){System.out.println(quota);count++;}System.out.print("The following count of quota were returned: ");System.out.println(count);}catch(Exceptione){System.out.println("Failed to list quota.");System.out.println(e);}}publicstaticvoidmain(String[]args)throwsException{Configconfig=Config.load();listQuotas(config.getAccountId().toString());}}
<?php/** * 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. */require_once __DIR__ . '/../../../vendor/autoload.php';require_once __DIR__ . '/../../Authentication/Authentication.php';require_once __DIR__ . '/../../Authentication/Config.php';use Google\ApiCore\ApiException;use Google\Shopping\Merchant\Quota\V1\Client\QuotaServiceClient;use Google\Shopping\Merchant\Quota\V1\ListQuotaGroupsRequest;/** * This class demonstrates how to list quota for a given Merchant Center account. */class ListQuotaSample{ /** * A helper function to create the parent string. * * @param string $accountId * The account that owns the quota. * * @return string The parent has the format: `accounts/{account_id}` */ private static function getParent(string $accountId): string { return sprintf("accounts/%s", $accountId); } /** * Lists quotas for a given Merchant Center account. * * @param string $accountId * The Merchant Center account ID. * @throws ApiException */ public static function listQuotas(string $accountId): void { // Gets the OAuth credentials to make the request. $credentials = Authentication::useServiceAccountOrTokenFile(); // Creates options config containing credentials for the client to use. $options = ['credentials' => $credentials]; // Creates a client. $quotaServiceClient = new QuotaServiceClient($options); // Creates the parent resource name. $parent = self::getParent($accountId); // Creates the request. $request = new ListQuotaGroupsRequest(['parent' => $parent]); print "Sending list quotas request:\n"; // Calls the API and catches and prints any network failures/errors. try { $response = $quotaServiceClient->listQuotaGroups($request); $count = 0; // Iterates over all rows in all pages and prints the quota group in each row. foreach ($response->iterateAllElements() as $quota) { print_r($quota); $count++; } print "The following count of quota were returned: "; print $count . "\n"; } catch (ApiException $e) { print "Failed to list quota.\n"; print $e->getMessage() . "\n"; } } /** * Helper to execute the sample. * @throws ApiException */ public function callSample(): void { $config = Config::generateConfig(); self::listQuotas($config['accountId']); }}// Run the script$sample = new ListQuotaSample();$sample->callSample();
# -*- 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."""A module to list quota for a given Merchant Center account."""fromexamples.authenticationimportconfigurationfromexamples.authenticationimportgenerate_user_credentialsfromgoogle.shoppingimportmerchant_quota_v1_ACCOUNT=configuration.Configuration().read_merchant_info()_PARENT=f"accounts/{_ACCOUNT}"deflist_quotas():"""This class demonstrates how to list quota for a given Merchant Center account."""# Gets OAuth Credentials.credentials=generate_user_credentials.main()# Creates a client.client=merchant_quota_v1.QuotaServiceClient(credentials=credentials)# Creates the request.request=merchant_quota_v1.ListQuotaGroupsRequest(parent=_PARENT)print("Sending list quotas request:")# Makes the request.response=client.list_quota_groups(request=request)count=0# Iterates over all rows in all pages and prints the quota group in each row.# Automatically uses the `next_page_token` if returned to fetch all pages of# data.forquotainresponse:print(quota)count+=1print("The following count of quota were returned: ")print(count)if__name__=="__main__":list_quotas()
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-13 UTC."],[],[],null,["# List quota\n\nMerchant API code sample to list quota. \n\n### Java\n\n // Copyright 2025 Google LLC\n //\n // Licensed under the Apache License, Version 2.0 (the \"License\");\n // you may not use this file except in compliance with the License.\n // You may obtain a copy of the License at\n //\n // https://www.apache.org/licenses/LICENSE-2.0\n //\n // Unless required by applicable law or agreed to in writing, software\n // distributed under the License is distributed on an \"AS IS\" BASIS,\n // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n // See the License for the specific language governing permissions and\n // limitations under the License.\n\n package shopping.merchant.samples.quota.v1;\n\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.quota.v1.ListQuotaGroupsRequest;\n import com.google.shopping.merchant.quota.v1.QuotaGroup;\n import com.google.shopping.merchant.quota.v1.QuotaServiceClient;\n import com.google.shopping.merchant.quota.v1.QuotaServiceClient.ListQuotaGroupsPagedResponse;\n import com.google.shopping.merchant.quota.v1.QuotaServiceSettings;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to list quota for a given Merchant Center account. */\n public class ListQuotaSample {\n\n public static void listQuotas(String accountId) throws Exception {\n GoogleCredentials credential = new Authenticator().authenticate();\n\n QuotaServiceSettings quotasServiceSettings =\n QuotaServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n try (QuotaServiceClient quotaServiceClient = QuotaServiceClient.create(quotasServiceSettings)) {\n\n ListQuotaGroupsRequest request =\n ListQuotaGroupsRequest.newBuilder()\n .setParent(String.format(\"accounts/%s\", accountId))\n .build();\n\n System.out.println(\"Sending list quotas request:\");\n ListQuotaGroupsPagedResponse response = quotaServiceClient.listQuotaGroups(request);\n\n int count = 0;\n\n // Iterates over all rows in all pages and prints the quota group in each row.\n // Automatically uses the `nextPageToken` if returned to fetch all pages of data.\n for (QuotaGroup quota : response.iterateAll()) {\n System.out.println(quota);\n count++;\n }\n System.out.print(\"The following count of quota were returned: \");\n System.out.println(count);\n\n } catch (Exception e) {\n System.out.println(\"Failed to list quota.\");\n System.out.println(e);\n }\n }\n\n public static void main(String[] args) throws Exception {\n Config config = Config.load();\n listQuotas(config.getAccountId().toString());\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/quota/v1/ListQuotaSample.java\n\n### PHP\n\n \u003c?php\n /**\n * Copyright 2025 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n require_once __DIR__ . '/../../../vendor/autoload.php';\n require_once __DIR__ . '/../../Authentication/Authentication.php';\n require_once __DIR__ . '/../../Authentication/Config.php';\n use Google\\ApiCore\\ApiException;\n use Google\\Shopping\\Merchant\\Quota\\V1\\Client\\QuotaServiceClient;\n use Google\\Shopping\\Merchant\\Quota\\V1\\ListQuotaGroupsRequest;\n\n /**\n * This class demonstrates how to list quota for a given Merchant Center account.\n */\n class ListQuotaSample\n {\n\n /**\n * A helper function to create the parent string.\n *\n * @param string $accountId\n * The account that owns the quota.\n *\n * @return string The parent has the format: `accounts/{account_id}`\n */\n private static function getParent(string $accountId): string\n {\n return sprintf(\"accounts/%s\", $accountId);\n }\n\n\n /**\n * Lists quotas for a given Merchant Center account.\n *\n * @param string $accountId\n * The Merchant Center account ID.\n * @throws ApiException\n */\n public static function listQuotas(string $accountId): void\n {\n // Gets the OAuth credentials to make the request.\n $credentials = Authentication::useServiceAccountOrTokenFile();\n\n // Creates options config containing credentials for the client to use.\n $options = ['credentials' =\u003e $credentials];\n\n // Creates a client.\n $quotaServiceClient = new QuotaServiceClient($options);\n\n // Creates the parent resource name.\n $parent = self::getParent($accountId);\n\n // Creates the request.\n $request = new ListQuotaGroupsRequest(['parent' =\u003e $parent]);\n\n print \"Sending list quotas request:\\n\";\n\n // Calls the API and catches and prints any network failures/errors.\n try {\n $response = $quotaServiceClient-\u003elistQuotaGroups($request);\n\n $count = 0;\n\n // Iterates over all rows in all pages and prints the quota group in each row.\n foreach ($response-\u003eiterateAllElements() as $quota) {\n print_r($quota);\n $count++;\n }\n print \"The following count of quota were returned: \";\n print $count . \"\\n\";\n } catch (ApiException $e) {\n print \"Failed to list quota.\\n\";\n print $e-\u003egetMessage() . \"\\n\";\n }\n }\n\n /**\n * Helper to execute the sample.\n * @throws ApiException\n */\n public function callSample(): void\n {\n $config = Config::generateConfig();\n self::listQuotas($config['accountId']);\n }\n }\n\n // Run the script\n $sample = new ListQuotaSample();\n $sample-\u003ecallSample();\n\n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/quota/v1/ListQuotaSample.php\n\n### Python\n\n # -*- coding: utf-8 -*-\n # Copyright 2025 Google LLC\n #\n # Licensed under the Apache License, Version 2.0 (the \"License\");\n # you may not use this file except in compliance with the License.\n # You may obtain a copy of the License at\n #\n # http://www.apache.org/licenses/LICENSE-2.0\n #\n # Unless required by applicable law or agreed to in writing, software\n # distributed under the License is distributed on an \"AS IS\" BASIS,\n # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n # See the License for the specific language governing permissions and\n # limitations under the License.\n \"\"\"A module to list quota for a given Merchant Center account.\"\"\"\n\n from examples.authentication import configuration\n from examples.authentication import generate_user_credentials\n from google.shopping import merchant_quota_v1\n\n _ACCOUNT = configuration.Configuration().read_merchant_info()\n _PARENT = f\"accounts/{_ACCOUNT}\"\n\n\n def list_quotas():\n \"\"\"This class demonstrates how to list quota for a given Merchant Center account.\"\"\"\n\n # Gets OAuth Credentials.\n credentials = generate_user_credentials.main()\n\n # Creates a client.\n client = merchant_quota_v1.QuotaServiceClient(credentials=credentials)\n\n # Creates the request.\n request = merchant_quota_v1.ListQuotaGroupsRequest(parent=_PARENT)\n\n print(\"Sending list quotas request:\")\n # Makes the request.\n response = client.list_quota_groups(request=request)\n\n count = 0\n\n # Iterates over all rows in all pages and prints the quota group in each row.\n # Automatically uses the `next_page_token` if returned to fetch all pages of\n # data.\n for quota in response:\n print(quota)\n count += 1\n print(\"The following count of quota were returned: \")\n print(count)\n\n\n if __name__ == \"__main__\":\n list_quotas()\n\n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/python/examples/quota/v1/list_quota_sample.py"]]