Stay organized with collectionsSave and categorize content based on your preferences.
Merchant API code sample to update autofeed settings.
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.autofeedsettings.v1;importcom.google.api.gax.core.FixedCredentialsProvider;importcom.google.auth.oauth2.GoogleCredentials;importcom.google.protobuf.FieldMask;importcom.google.shopping.merchant.accounts.v1.AutofeedSettings;importcom.google.shopping.merchant.accounts.v1.AutofeedSettingsName;importcom.google.shopping.merchant.accounts.v1.AutofeedSettingsServiceClient;importcom.google.shopping.merchant.accounts.v1.AutofeedSettingsServiceSettings;importcom.google.shopping.merchant.accounts.v1.UpdateAutofeedSettingsRequest;importshopping.merchant.samples.utils.Authenticator;importshopping.merchant.samples.utils.Config;/** This class demonstrates how to update AutofeedSettings to be enabled. */publicclassUpdateAutofeedSettingsSample{publicstaticvoidupdateAutofeedSettings(Configconfig)throwsException{GoogleCredentialscredential=newAuthenticator().authenticate();AutofeedSettingsServiceSettingsautofeedSettingsServiceSettings=AutofeedSettingsServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();// Creates AutofeedSettings name to identify AutofeedSettings.Stringname=AutofeedSettingsName.newBuilder().setAccount(config.getAccountId().toString()).build().toString();// Create AutofeedSettings with the updated fields.AutofeedSettingsautofeedSettings=AutofeedSettings.newBuilder().setName(name).build();FieldMaskfieldMask=FieldMask.newBuilder().addPaths("*").build();try(AutofeedSettingsServiceClientautofeedSettingsServiceClient=AutofeedSettingsServiceClient.create(autofeedSettingsServiceSettings)){UpdateAutofeedSettingsRequestrequest=UpdateAutofeedSettingsRequest.newBuilder().setAutofeedSettings(autofeedSettings).setUpdateMask(fieldMask).build();System.out.println("Sending Update AutofeedSettings request");AutofeedSettingsresponse=autofeedSettingsServiceClient.updateAutofeedSettings(request);System.out.println("Updated AutofeedSettings Name below");System.out.println(response.getName());}catch(Exceptione){System.out.println(e);}}publicstaticvoidmain(String[]args)throwsException{Configconfig=Config.load();updateAutofeedSettings(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\Protobuf\FieldMask;use Google\Shopping\Merchant\Accounts\V1\AutofeedSettings;use Google\Shopping\Merchant\Accounts\V1\Client\AutofeedSettingsServiceClient;use Google\Shopping\Merchant\Accounts\V1\UpdateAutofeedSettingsRequest;/*** This class demonstrates how to update AutofeedSettings to be enabled.*/class UpdateAutofeedSettingsSample{/*** Update AutofeedSettings to be enabled.** @param array $config The configuration data for authentication and account ID.* @return void*/public static function updateAutofeedSettingsSample(array $config): void{// Get OAuth credentials.$credentials = Authentication::useServiceAccountOrTokenFile();// Create options for the client.$options = ['credentials' => $credentials];// Create a client.$autofeedSettingsServiceClient = new AutofeedSettingsServiceClient($options);// Create the AutofeedSettings name.$name = "accounts/" . $config['accountId'] . "/autofeedSettings";// Create AutofeedSettings object.$autofeedSettings = (new AutofeedSettings())->setName($name);// Create FieldMask.$fieldMask = (new FieldMask())->setPaths(["*"]);// Call the API.try {// Prepare the request.$request = (new UpdateAutofeedSettingsRequest())->setAutofeedSettings($autofeedSettings)->setUpdateMask($fieldMask);print "Sending Update AutofeedSettings request\n";$response = $autofeedSettingsServiceClient->updateAutofeedSettings($request);print "Updated AutofeedSettings Name below\n";print $response->getName() . "\n";} catch (ApiException $e) {print $e->getMessage();}}/*** Helper to execute the sample.** @return void*/public function callSample(): void{$config = Config::generateConfig();self::updateAutofeedSettingsSample($config);}}// Run the script$sample = new UpdateAutofeedSettingsSample();$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 update AutofeedSettings."""fromexamples.authenticationimportconfigurationfromexamples.authenticationimportgenerate_user_credentialsfromgoogle.protobufimportfield_mask_pb2fromgoogle.shopping.merchant_accounts_v1importAutofeedSettingsfromgoogle.shopping.merchant_accounts_v1importAutofeedSettingsServiceClientfromgoogle.shopping.merchant_accounts_v1importUpdateAutofeedSettingsRequest_ACCOUNT=configuration.Configuration().read_merchant_info()defupdate_autofeed_settings():"""Updates the AutofeedSettings of a Merchant Center account."""# Gets OAuth Credentials.credentials=generate_user_credentials.main()# Creates a client.client=AutofeedSettingsServiceClient(credentials=credentials)# Creates name to identify the AutofeedSettings.name="accounts/"+_ACCOUNT+"/autofeedSettings"# Create AutofeedSettings with the updated fields.autofeed_settings=AutofeedSettings(name=name,enable_products=False)# Create the field mask.field_mask=field_mask_pb2.FieldMask(paths=["enable_products"])# Creates the request.request=UpdateAutofeedSettingsRequest(autofeed_settings=autofeed_settings,update_mask=field_mask)# Makes the request and catches and prints any error messages.try:response=client.update_autofeed_settings(request=request)print("Updated AutofeedSettings Name below")print(response.name)exceptRuntimeErrorase:print("Update AutofeedSettings request failed")print(e)if__name__=="__main__":update_autofeed_settings()
[[["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 update AutofeedSettings using the Merchant API in Java.\u003c/p\u003e\n"],["\u003cp\u003eIt uses the \u003ccode\u003eAutofeedSettingsServiceClient\u003c/code\u003e to interact with the Merchant API and make the update request.\u003c/p\u003e\n"],["\u003cp\u003eThe code creates an \u003ccode\u003eAutofeedSettings\u003c/code\u003e object with updated fields, specifically focusing on enabling it.\u003c/p\u003e\n"],["\u003cp\u003eThe code builds and sends an \u003ccode\u003eUpdateAutofeedSettingsRequest\u003c/code\u003e, utilizing a \u003ccode\u003eFieldMask\u003c/code\u003e to indicate all fields should be updated, then prints the name of the updated settings.\u003c/p\u003e\n"]]],[],null,["# Update autofeed settings\n\nMerchant API code sample to update autofeed settings. \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.autofeedsettings.v1;\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.protobuf.FieldMask;\n import com.google.shopping.merchant.accounts.v1.AutofeedSettings;\n import com.google.shopping.merchant.accounts.v1.AutofeedSettingsName;\n import com.google.shopping.merchant.accounts.v1.AutofeedSettingsServiceClient;\n import com.google.shopping.merchant.accounts.v1.AutofeedSettingsServiceSettings;\n import com.google.shopping.merchant.accounts.v1.UpdateAutofeedSettingsRequest;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to update AutofeedSettings to be enabled. */\n public class UpdateAutofeedSettingsSample {\n\n public static void updateAutofeedSettings(Config config) throws Exception {\n\n GoogleCredentials credential = new Authenticator().authenticate();\n\n AutofeedSettingsServiceSettings autofeedSettingsServiceSettings =\n AutofeedSettingsServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n // Creates AutofeedSettings name to identify AutofeedSettings.\n String name =\n AutofeedSettingsName.newBuilder()\n .setAccount(config.getAccountId().toString())\n .build()\n .toString();\n\n // Create AutofeedSettings with the updated fields.\n AutofeedSettings autofeedSettings = AutofeedSettings.newBuilder().setName(name).build();\n\n FieldMask fieldMask = FieldMask.newBuilder().addPaths(\"*\").build();\n\n try (AutofeedSettingsServiceClient autofeedSettingsServiceClient =\n AutofeedSettingsServiceClient.create(autofeedSettingsServiceSettings)) {\n\n UpdateAutofeedSettingsRequest request =\n UpdateAutofeedSettingsRequest.newBuilder()\n .setAutofeedSettings(autofeedSettings)\n .setUpdateMask(fieldMask)\n .build();\n\n System.out.println(\"Sending Update AutofeedSettings request\");\n AutofeedSettings response = autofeedSettingsServiceClient.updateAutofeedSettings(request);\n System.out.println(\"Updated AutofeedSettings Name below\");\n System.out.println(response.getName());\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 updateAutofeedSettings(config);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/accounts/autofeedsettings/v1/UpdateAutofeedSettingsSample.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\\Protobuf\\FieldMask;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\AutofeedSettings;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\Client\\AutofeedSettingsServiceClient;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\UpdateAutofeedSettingsRequest;\n\n /**\n * This class demonstrates how to update AutofeedSettings to be enabled.\n */\n class UpdateAutofeedSettingsSample\n {\n\n /**\n * Update AutofeedSettings to be enabled.\n *\n * @param array $config The configuration data for authentication and account ID.\n * @return void\n */\n public static function updateAutofeedSettingsSample(array $config): void\n {\n // Get OAuth credentials.\n $credentials = Authentication::useServiceAccountOrTokenFile();\n\n // Create options for the client.\n $options = ['credentials' =\u003e $credentials];\n\n // Create a client.\n $autofeedSettingsServiceClient = new AutofeedSettingsServiceClient($options);\n\n // Create the AutofeedSettings name.\n $name = \"accounts/\" . $config['accountId'] . \"/autofeedSettings\";\n\n // Create AutofeedSettings object.\n $autofeedSettings = (new AutofeedSettings())\n -\u003esetName($name);\n\n // Create FieldMask.\n $fieldMask = (new FieldMask())\n -\u003esetPaths([\"*\"]);\n\n // Call the API.\n try {\n // Prepare the request.\n $request = (new UpdateAutofeedSettingsRequest())\n -\u003esetAutofeedSettings($autofeedSettings)\n -\u003esetUpdateMask($fieldMask);\n\n print \"Sending Update AutofeedSettings request\\n\";\n $response = $autofeedSettingsServiceClient-\u003eupdateAutofeedSettings($request);\n print \"Updated AutofeedSettings Name below\\n\";\n print $response-\u003egetName() . \"\\n\";\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::updateAutofeedSettingsSample($config);\n }\n }\n\n // Run the script\n $sample = new UpdateAutofeedSettingsSample();\n $sample-\u003ecallSample(); \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/accounts/autofeedsettings/v1/UpdateAutofeedSettingsSample.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 update AutofeedSettings.\"\"\"\n\n from examples.authentication import configuration\n from examples.authentication import generate_user_credentials\n from google.protobuf import field_mask_pb2\n from google.shopping.merchant_accounts_v1 import AutofeedSettings\n from google.shopping.merchant_accounts_v1 import AutofeedSettingsServiceClient\n from google.shopping.merchant_accounts_v1 import UpdateAutofeedSettingsRequest\n\n _ACCOUNT = configuration.Configuration().read_merchant_info()\n\n\n def update_autofeed_settings():\n \"\"\"Updates the AutofeedSettings of a Merchant Center account.\"\"\"\n\n # Gets OAuth Credentials.\n credentials = generate_user_credentials.main()\n\n # Creates a client.\n client = AutofeedSettingsServiceClient(credentials=credentials)\n\n # Creates name to identify the AutofeedSettings.\n name = \"accounts/\" + _ACCOUNT + \"/autofeedSettings\"\n\n # Create AutofeedSettings with the updated fields.\n autofeed_settings = AutofeedSettings(name=name, enable_products=False)\n\n # Create the field mask.\n field_mask = field_mask_pb2.FieldMask(paths=[\"enable_products\"])\n\n # Creates the request.\n request = UpdateAutofeedSettingsRequest(\n autofeed_settings=autofeed_settings, update_mask=field_mask\n )\n\n # Makes the request and catches and prints any error messages.\n try:\n response = client.update_autofeed_settings(request=request)\n print(\"Updated AutofeedSettings Name below\")\n print(response.name)\n except RuntimeError as e:\n print(\"Update AutofeedSettings request failed\")\n print(e)\n\n\n if __name__ == \"__main__\":\n update_autofeed_settings() \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/python/examples/accounts/autofeedsettings/v1/update_autofeed_settings_sample.py"]]