Stay organized with collections
Save and categorize content based on your preferences.
Merchant API code sample to disable program.
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.programs.v1;importcom.google.api.gax.core.FixedCredentialsProvider;importcom.google.auth.oauth2.GoogleCredentials;importcom.google.shopping.merchant.accounts.v1.DisableProgramRequest;importcom.google.shopping.merchant.accounts.v1.Program;importcom.google.shopping.merchant.accounts.v1.ProgramName;importcom.google.shopping.merchant.accounts.v1.ProgramsServiceClient;importcom.google.shopping.merchant.accounts.v1.ProgramsServiceSettings;importshopping.merchant.samples.utils.Authenticator;importshopping.merchant.samples.utils.Config;/** This class demonstrates how to disable a shopping program for a Merchant Center account. */publicclassDisableProgramSample{publicstaticvoiddisableProgram(Configconfig,Stringprogram)throwsException{// Obtains OAuth token based on the user's configuration.GoogleCredentialscredential=newAuthenticator().authenticate();// Creates service settings using the credentials retrieved above.ProgramsServiceSettingsprogramsServiceSettings=ProgramsServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();// Creates program name to identify the program.Stringname=ProgramName.newBuilder().setAccount(config.getAccountId().toString()).setProgram(program).build().toString();// Calls the API and catches and prints any network failures/errors.try(ProgramsServiceClientprogramsServiceClient=ProgramsServiceClient.create(programsServiceSettings)){// The name has the format: accounts/{account}/programs/{program}DisableProgramRequestrequest=DisableProgramRequest.newBuilder().setName(name).build();System.out.println("Sending Disable Program request:");Programresponse=programsServiceClient.disableProgram(request);System.out.println("Disabled Program below");System.out.println(response);}catch(Exceptione){System.out.println(e);}}publicstaticvoidmain(String[]args)throwsException{Configconfig=Config.load();// Replace this with the name of the program to be disabled.Stringprogram="free-listings";disableProgram(config,program);}}
<?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\ProgramsServiceClient;use Google\Shopping\Merchant\Accounts\V1\DisableProgramRequest;/** * This class demonstrates how to disable a shopping program for a Merchant Center account. */class DisableProgramSample{ /** * Disables a program for the given Merchant Center account. * * @param array $config The configuration data for authentication and account ID. * @param string $program The program to disable. * @return void */ public static function disableProgram($config, $program): 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. $programsServiceClient = new ProgramsServiceClient($options); // Creates program name to identify the program. $name = $parent = "accounts/" . $config['accountId'] . "/programs/" . $program; // Calls the API and catches and prints any network failures/errors. try { // The name has the format: accounts/{account}/programs/{program} $request = new DisableProgramRequest(['name' => $name]); print "Sending Disable Program request:\n"; $response = $programsServiceClient->disableProgram($request); print "Disabled Program below\n"; print_r($response); } catch (ApiException $e) { print $e->getMessage(); } } /** * Helper to execute the sample. * * @return void */ public function callSample(): void { $config = Config::generateConfig(); // Replace this with the name of the program to be disabled. $program = "free-listings"; self::disableProgram($config, $program); }}// Run the script$sample = new DisableProgramSample();$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 for disabling a program for a Merchant Center account."""fromexamples.authenticationimportconfigurationfromexamples.authenticationimportgenerate_user_credentialsfromgoogle.shopping.merchant_accounts_v1importDisableProgramRequestfromgoogle.shopping.merchant_accounts_v1importProgramsServiceClient_ACCOUNT=configuration.Configuration().read_merchant_info()defdisable_program(program):"""Disables a program for the given Merchant Center account."""# Gets OAuth Credentials.credentials=generate_user_credentials.main()# Creates a client.client=ProgramsServiceClient(credentials=credentials)# Creates program name to identify the program.name="accounts/"+_ACCOUNT+"/programs/"+program# Creates the request.request=DisableProgramRequest(name=name)# Makes the request and catches and prints any error messages.try:response=client.disable_program(request=request)print("Disabled Program below")print(response)returnresponseexceptRuntimeErrorase:print(e)returnNoneif__name__=="__main__":# Replace this with the name of the program to be disabled.program_to_disable="free-listings"disable_program(program_to_disable)
[[["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 code sample demonstrates how to disable a shopping program within a Merchant Center account using the Merchant API.\u003c/p\u003e\n"],["\u003cp\u003eThe provided Java code uses the \u003ccode\u003eProgramsServiceClient\u003c/code\u003e to send a \u003ccode\u003eDisableProgramRequest\u003c/code\u003e to the Merchant API.\u003c/p\u003e\n"],["\u003cp\u003eThe code requires authentication via OAuth 2.0, which is handled by the \u003ccode\u003eAuthenticator\u003c/code\u003e utility class.\u003c/p\u003e\n"],["\u003cp\u003eThe program to be disabled is specified by its name, which has the format: \u003ccode\u003eaccounts/{account}/programs/{program}\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe code includes error handling to catch and print any network issues or API errors during the process.\u003c/p\u003e\n"]]],["The code samples demonstrate how to disable a shopping program for a Merchant Center account using the Merchant API in Java, PHP, and Python. The process involves authenticating with OAuth credentials, creating a `ProgramsServiceClient`, and constructing a `DisableProgramRequest` with the program's name. The API call sends a request to disable the program, with error handling for network or API issues. The response, representing the disabled program, is then printed. The example uses \"free-listings\" as a program to be disabled.\n"],null,["# Disable program\n\nMerchant API code sample to disable program. \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.programs.v1;\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.accounts.v1.DisableProgramRequest;\n import com.google.shopping.merchant.accounts.v1.Program;\n import com.google.shopping.merchant.accounts.v1.ProgramName;\n import com.google.shopping.merchant.accounts.v1.ProgramsServiceClient;\n import com.google.shopping.merchant.accounts.v1.ProgramsServiceSettings;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to disable a shopping program for a Merchant Center account. */\n public class DisableProgramSample {\n\n public static void disableProgram(Config config, String program) 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 ProgramsServiceSettings programsServiceSettings =\n ProgramsServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n // Creates program name to identify the program.\n String name =\n ProgramName.newBuilder()\n .setAccount(config.getAccountId().toString())\n .setProgram(program)\n .build()\n .toString();\n\n // Calls the API and catches and prints any network failures/errors.\n try (ProgramsServiceClient programsServiceClient =\n ProgramsServiceClient.create(programsServiceSettings)) {\n\n // The name has the format: accounts/{account}/programs/{program}\n DisableProgramRequest request = DisableProgramRequest.newBuilder().setName(name).build();\n\n System.out.println(\"Sending Disable Program request:\");\n Program response = programsServiceClient.disableProgram(request);\n\n System.out.println(\"Disabled Program 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 // Replace this with the name of the program to be disabled.\n String program = \"free-listings\";\n\n disableProgram(config, program);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/accounts/programs/v1/DisableProgramSample.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\\ProgramsServiceClient;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\DisableProgramRequest;\n\n /**\n * This class demonstrates how to disable a shopping program for a Merchant Center account.\n */\n class DisableProgramSample\n {\n /**\n * Disables a program for the given Merchant Center account.\n *\n * @param array $config The configuration data for authentication and account ID.\n * @param string $program The program to disable.\n * @return void\n */\n public static function disableProgram($config, $program): 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 $programsServiceClient = new ProgramsServiceClient($options);\n\n // Creates program name to identify the program.\n $name = $parent = \"accounts/\" . $config['accountId'] . \"/programs/\" . $program;\n\n // Calls the API and catches and prints any network failures/errors.\n try {\n // The name has the format: accounts/{account}/programs/{program}\n $request = new DisableProgramRequest(['name' =\u003e $name]);\n\n print \"Sending Disable Program request:\\n\";\n $response = $programsServiceClient-\u003edisableProgram($request);\n\n print \"Disabled Program below\\n\";\n print_r($response);\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 // Replace this with the name of the program to be disabled.\n $program = \"free-listings\";\n self::disableProgram($config, $program);\n }\n }\n\n // Run the script\n $sample = new DisableProgramSample();\n $sample-\u003ecallSample(); \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/accounts/programs/v1/DisableProgramSample.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 for disabling a program for a Merchant Center account.\"\"\"\n\n from examples.authentication import configuration\n from examples.authentication import generate_user_credentials\n from google.shopping.merchant_accounts_v1 import DisableProgramRequest\n from google.shopping.merchant_accounts_v1 import ProgramsServiceClient\n\n _ACCOUNT = configuration.Configuration().read_merchant_info()\n\n\n def disable_program(program):\n \"\"\"Disables a program for the given Merchant Center account.\"\"\"\n\n # Gets OAuth Credentials.\n credentials = generate_user_credentials.main()\n\n # Creates a client.\n client = ProgramsServiceClient(credentials=credentials)\n\n # Creates program name to identify the program.\n name = \"accounts/\" + _ACCOUNT + \"/programs/\" + program\n\n # Creates the request.\n request = DisableProgramRequest(name=name)\n\n # Makes the request and catches and prints any error messages.\n try:\n response = client.disable_program(request=request)\n print(\"Disabled Program below\")\n print(response)\n return response\n except RuntimeError as e:\n print(e)\n return None\n\n\n if __name__ == \"__main__\":\n # Replace this with the name of the program to be disabled.\n program_to_disable = \"free-listings\"\n disable_program(program_to_disable)\n\n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/python/examples/accounts/programs/v1/disable_program_sample.py"]]