Stay organized with collections
Save and categorize content based on your preferences.
Merchant API code sample to retrieve latest terms of service.
Java
// 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.packageshopping.merchant.samples.accounts.termsofservices.v1;importcom.google.api.gax.core.FixedCredentialsProvider;importcom.google.auth.oauth2.GoogleCredentials;importcom.google.shopping.merchant.accounts.v1.RetrieveLatestTermsOfServiceRequest;importcom.google.shopping.merchant.accounts.v1.TermsOfService;importcom.google.shopping.merchant.accounts.v1.TermsOfServiceKind;importcom.google.shopping.merchant.accounts.v1.TermsOfServiceServiceClient;importcom.google.shopping.merchant.accounts.v1.TermsOfServiceServiceSettings;importshopping.merchant.samples.utils.Authenticator;importshopping.merchant.samples.utils.Config;/** This class demonstrates how to retrieve the latest TermsOfService a specific region and kind. */publicclassRetrieveLatestTermsOfServiceSample{publicstaticvoidretrieveLatestTermsOfService(Configconfig)throwsException{// Obtains OAuth token based on the user's configuration.GoogleCredentialscredential=newAuthenticator().authenticate();// Creates service settings using the credentials retrieved above.TermsOfServiceServiceSettingstermsOfServiceServiceSettings=TermsOfServiceServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();// Calls the API and catches and prints any network failures/errors.try(TermsOfServiceServiceClienttermsOfServiceServiceClient=TermsOfServiceServiceClient.create(termsOfServiceServiceSettings)){RetrieveLatestTermsOfServiceRequestrequest=RetrieveLatestTermsOfServiceRequest.newBuilder().setRegionCode("US").setKind(TermsOfServiceKind.MERCHANT_CENTER).build();System.out.println("Sending Retrieve Latest TermsOfService request:");TermsOfServiceresponse=termsOfServiceServiceClient.retrieveLatestTermsOfService(request);System.out.println("Retrieved TermsOfService below");System.out.println(response);}catch(Exceptione){System.out.println(e);}}publicstaticvoidmain(String[]args)throwsException{Configconfig=Config.load();retrieveLatestTermsOfService(config);}}
<?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\Accounts\V1\Client\TermsOfServiceServiceClient;use Google\Shopping\Merchant\Accounts\V1\RetrieveLatestTermsOfServiceRequest;use Google\Shopping\Merchant\Accounts\V1\TermsOfServiceKind;/** * Demonstrates how to retrieve the latest TermsOfService. */class RetrieveLatestTermsOfService{ /** * Retrieves the latest TermsOfService. * * @param array $config The configuration data. * @return void */ public static function retrieveLatestTermsOfService($config): void { // Get OAuth credentials. $credentials = Authentication::useServiceAccountOrTokenFile(); // Create client options. $options = ['credentials' => $credentials]; // Create a TermsOfServiceServiceClient. $termsOfServiceServiceClient = new TermsOfServiceServiceClient($options); try { // Prepare the request. $request = new RetrieveLatestTermsOfServiceRequest([ 'region_code' => "US", 'kind' => TermsOfServiceKind::MERCHANT_CENTER, ]); print "Sending Retrieve Latest TermsOfService request:\n"; $response = $termsOfServiceServiceClient->retrieveLatestTermsOfService($request); print "Retrieved TermsOfService below\n"; print $response->serializeToJsonString() . PHP_EOL; } catch (ApiException $e) { print $e->getMessage(); } } /** * Helper to execute the sample. * * @return void */ public function callSample(): void { $config = Config::generateConfig(); self::retrieveLatestTermsOfService($config); }}// Run the script$sample = new RetrieveLatestTermsOfService();$sample->callSample();
# -*- coding: utf-8 -*-# 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## 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."""Module for retrieving the latest TermsOfService."""fromexamples.authenticationimportgenerate_user_credentialsfromgoogle.shopping.merchant_accounts_v1importRetrieveLatestTermsOfServiceRequestfromgoogle.shopping.merchant_accounts_v1importTermsOfServiceKindfromgoogle.shopping.merchant_accounts_v1importTermsOfServiceServiceClient# Replace with your actual values._REGION_CODE="US"# Replace with your region code_KIND=(TermsOfServiceKind.MERCHANT_CENTER)# Replace with your TermsOfServiceKinddefretrieve_latest_terms_of_service():"""Retrieves the latest TermsOfService for a specific region and kind."""credentials=generate_user_credentials.main()client=TermsOfServiceServiceClient(credentials=credentials)request=RetrieveLatestTermsOfServiceRequest(region_code=_REGION_CODE,kind=_KIND)try:print("Sending Retrieve Latest TermsOfService request:")response=client.retrieve_latest_terms_of_service(request=request)print("Retrieved TermsOfService below")print(response)exceptRuntimeErrorase:print(e)if__name__=="__main__":retrieve_latest_terms_of_service()
[[["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."],[[["\u003cp\u003eThis webpage provides code samples in Java, PHP, and Python demonstrating how to retrieve the latest Terms of Service using the Merchant API.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples show how to authenticate and use the \u003ccode\u003eTermsOfServiceServiceClient\u003c/code\u003e to send a \u003ccode\u003eRetrieveLatestTermsOfServiceRequest\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eEach sample code showcases how to specify a \u003ccode\u003eregion_code\u003c/code\u003e (e.g., "US") and \u003ccode\u003ekind\u003c/code\u003e (e.g., \u003ccode\u003eMERCHANT_CENTER\u003c/code\u003e) to get the relevant Terms of Service.\u003c/p\u003e\n"],["\u003cp\u003eThe code samples display the successful response after the API call, including the retrieved Terms of Service information.\u003c/p\u003e\n"],["\u003cp\u003eThe code examples are found in the google merchant-api-samples github.\u003c/p\u003e\n"]]],[],null,["# Retrieve latest terms of service\n\nMerchant API code sample to retrieve latest terms of service. \n\n### Java\n\n // Copyright 2024 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.accounts.termsofservices.v1;\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.accounts.v1.RetrieveLatestTermsOfServiceRequest;\n import com.google.shopping.merchant.accounts.v1.TermsOfService;\n import com.google.shopping.merchant.accounts.v1.TermsOfServiceKind;\n import com.google.shopping.merchant.accounts.v1.TermsOfServiceServiceClient;\n import com.google.shopping.merchant.accounts.v1.TermsOfServiceServiceSettings;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to retrieve the latest TermsOfService a specific region and kind. */\n public class RetrieveLatestTermsOfServiceSample {\n\n public static void retrieveLatestTermsOfService(Config config) throws Exception {\n\n // Obtains OAuth token based on the user's configuration.\n GoogleCredentials credential = new Authenticator().authenticate();\n\n // Creates service settings using the credentials retrieved above.\n TermsOfServiceServiceSettings termsOfServiceServiceSettings =\n TermsOfServiceServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n // Calls the API and catches and prints any network failures/errors.\n try (TermsOfServiceServiceClient termsOfServiceServiceClient =\n TermsOfServiceServiceClient.create(termsOfServiceServiceSettings)) {\n\n RetrieveLatestTermsOfServiceRequest request =\n RetrieveLatestTermsOfServiceRequest.newBuilder()\n .setRegionCode(\"US\")\n .setKind(TermsOfServiceKind.MERCHANT_CENTER)\n .build();\n\n System.out.println(\"Sending Retrieve Latest TermsOfService request:\");\n TermsOfService response = termsOfServiceServiceClient.retrieveLatestTermsOfService(request);\n\n System.out.println(\"Retrieved TermsOfService below\");\n System.out.println(response);\n } catch (Exception e) {\n System.out.println(e);\n }\n }\n\n public static void main(String[] args) throws Exception {\n Config config = Config.load();\n\n retrieveLatestTermsOfService(config);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/accounts/termsofservices/v1/RetrieveLatestTermsOfServiceSample.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 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\\Accounts\\V1\\Client\\TermsOfServiceServiceClient;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\RetrieveLatestTermsOfServiceRequest;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\TermsOfServiceKind;\n\n /**\n * Demonstrates how to retrieve the latest TermsOfService.\n */\n class RetrieveLatestTermsOfService\n {\n /**\n * Retrieves the latest TermsOfService.\n *\n * @param array $config The configuration data.\n * @return void\n */\n public static function retrieveLatestTermsOfService($config): void\n {\n // Get OAuth credentials.\n $credentials = Authentication::useServiceAccountOrTokenFile();\n\n // Create client options.\n $options = ['credentials' =\u003e $credentials];\n\n // Create a TermsOfServiceServiceClient.\n $termsOfServiceServiceClient = new TermsOfServiceServiceClient($options);\n\n try {\n // Prepare the request.\n $request = new RetrieveLatestTermsOfServiceRequest([\n 'region_code' =\u003e \"US\",\n 'kind' =\u003e TermsOfServiceKind::MERCHANT_CENTER,\n ]);\n\n print \"Sending Retrieve Latest TermsOfService request:\\n\";\n $response = $termsOfServiceServiceClient-\u003eretrieveLatestTermsOfService($request);\n\n print \"Retrieved TermsOfService below\\n\";\n print $response-\u003eserializeToJsonString() . PHP_EOL;\n } catch (ApiException $e) {\n print $e-\u003egetMessage();\n }\n }\n\n /**\n * Helper to execute the sample.\n *\n * @return void\n */\n public function callSample(): void\n {\n $config = Config::generateConfig();\n\n self::retrieveLatestTermsOfService($config);\n }\n }\n\n // Run the script\n $sample = new RetrieveLatestTermsOfService();\n $sample-\u003ecallSample(); \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/accounts/termsofservices/v1/RetrieveLatestTermsOfServiceSample.php\n\n### Python\n\n # -*- coding: utf-8 -*-\n # Copyright 2024 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 \"\"\"Module for retrieving the latest TermsOfService.\"\"\"\n\n\n from examples.authentication import generate_user_credentials\n from google.shopping.merchant_accounts_v1 import RetrieveLatestTermsOfServiceRequest\n from google.shopping.merchant_accounts_v1 import TermsOfServiceKind\n from google.shopping.merchant_accounts_v1 import TermsOfServiceServiceClient\n\n # Replace with your actual values.\n _REGION_CODE = \"US\" # Replace with your region code\n _KIND = (\n TermsOfServiceKind.MERCHANT_CENTER\n ) # Replace with your TermsOfServiceKind\n\n\n def retrieve_latest_terms_of_service():\n \"\"\"Retrieves the latest TermsOfService for a specific region and kind.\"\"\"\n\n credentials = generate_user_credentials.main()\n client = TermsOfServiceServiceClient(credentials=credentials)\n\n request = RetrieveLatestTermsOfServiceRequest(\n region_code=_REGION_CODE, kind=_KIND\n )\n\n try:\n print(\"Sending Retrieve Latest TermsOfService request:\")\n response = client.retrieve_latest_terms_of_service(request=request)\n print(\"Retrieved TermsOfService below\")\n print(response)\n except RuntimeError as e:\n print(e)\n\n\n if __name__ == \"__main__\":\n retrieve_latest_terms_of_service()\n\n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/python/examples/accounts/termsofservices/v1/retrieve_latest_terms_of_service_sample.py"]]