Update business info

Merchant API code sample to update business info.

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. 
 package 
  
 shopping.merchant.samples.accounts.businessinfos.v1 
 ; 
 import 
  
 com.google.api.gax.core.FixedCredentialsProvider 
 ; 
 import 
  
 com.google.auth.oauth2.GoogleCredentials 
 ; 
 import 
  
 com.google.protobuf.FieldMask 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.BusinessInfo 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.BusinessInfoName 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.BusinessInfoServiceClient 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.BusinessInfoServiceSettings 
 ; 
 import 
  
 com.google.shopping.merchant.accounts.v1.UpdateBusinessInfoRequest 
 ; 
 import 
  
 com.google.type.PostalAddress 
 ; 
 import 
  
 shopping.merchant.samples.utils.Authenticator 
 ; 
 import 
  
 shopping.merchant.samples.utils.Config 
 ; 
 /** This class demonstrates how to update a BusinessInfo to a new address. */ 
 public 
  
 class 
 UpdateBusinessInfoSample 
  
 { 
  
 public 
  
 static 
  
 void 
  
 updateBusinessInfo 
 ( 
 Config 
  
 config 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 GoogleCredentials 
  
 credential 
  
 = 
  
 new 
  
 Authenticator 
 (). 
 authenticate 
 (); 
  
 BusinessInfoServiceSettings 
  
 businessInfoServiceSettings 
  
 = 
  
 BusinessInfoServiceSettings 
 . 
 newBuilder 
 () 
  
 . 
 setCredentialsProvider 
 ( 
 FixedCredentialsProvider 
 . 
 create 
 ( 
 credential 
 )) 
  
 . 
 build 
 (); 
  
 // Creates BusinessInfo name to identify BusinessInfo. 
  
 String 
  
 name 
  
 = 
  
 BusinessInfoName 
 . 
 newBuilder 
 () 
  
 . 
 setAccount 
 ( 
 config 
 . 
 getAccountId 
 (). 
 toString 
 ()) 
  
 . 
 build 
 () 
  
 . 
 toString 
 (); 
  
 // Create a BusinessInfo with the updated fields. 
  
 // Note that you cannot update the RegionCode or the Phone of the business 
  
 BusinessInfo 
  
 businessInfo 
  
 = 
  
 BusinessInfo 
 . 
 newBuilder 
 () 
  
 . 
 setName 
 ( 
 name 
 ) 
  
 . 
 setAddress 
 ( 
  
 PostalAddress 
 . 
 newBuilder 
 () 
  
 . 
 setLanguageCode 
 ( 
 "en" 
 ) 
  
 . 
 setPostalCode 
 ( 
 "C1107" 
 ) 
  
 . 
 addAddressLines 
 ( 
  
 "Av. Alicia Moreau de Justo 350, Cdad. Autónoma de Buenos Aires, Argentina" 
 ) 
  
 . 
 build 
 ()) 
  
 . 
 build 
 (); 
  
 FieldMask 
  
 fieldMask 
  
 = 
  
 FieldMask 
 . 
 newBuilder 
 (). 
 addPaths 
 ( 
 "address" 
 ). 
 build 
 (); 
  
 try 
  
 ( 
 BusinessInfoServiceClient 
  
 businessInfoServiceClient 
  
 = 
  
 BusinessInfoServiceClient 
 . 
 create 
 ( 
 businessInfoServiceSettings 
 )) 
  
 { 
  
 UpdateBusinessInfoRequest 
  
 request 
  
 = 
  
 UpdateBusinessInfoRequest 
 . 
 newBuilder 
 () 
  
 . 
 setBusinessInfo 
 ( 
 businessInfo 
 ) 
  
 . 
 setUpdateMask 
 ( 
 fieldMask 
 ) 
  
 . 
 build 
 (); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Sending Update BusinessInfo request" 
 ); 
  
 BusinessInfo 
  
 response 
  
 = 
  
 businessInfoServiceClient 
 . 
 updateBusinessInfo 
 ( 
 request 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Updated BusinessInfo Name below" 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 response 
 . 
 getName 
 ()); 
  
 } 
  
 catch 
  
 ( 
 Exception 
  
 e 
 ) 
  
 { 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 e 
 ); 
  
 } 
  
 } 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 [] 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 Config 
  
 config 
  
 = 
  
 Config 
 . 
 load 
 (); 
  
 updateBusinessInfo 
 ( 
 config 
 ); 
  
 } 
 } 
  
 

PHP

 < ?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\BusinessInfo; 
 use Google\Shopping\Merchant\Accounts\V1\Client\BusinessInfoServiceClient; 
 use Google\Shopping\Merchant\Accounts\V1\UpdateBusinessInfoRequest; 
 use Google\Type\PostalAddress; 
 /** 
 * This class demonstrates how to update a BusinessInfo to a new address. 
 */ 
 class UpdateBusinessInfoSample 
 { 
 /** 
 * Updates a BusinessInfo to a new address. 
 * 
 * @param array $config 
 *      The configuration data used for authentication and getting the account ID. 
 * 
 * @return void 
 */ 
 public static function updateBusinessInfoSample(array $config): 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. 
 $businessInfoServiceClient = new BusinessInfoServiceClient($options); 
 // Creates BusinessInfo name to identify the BusinessInfo. 
 // The name has the format: accounts/{account}/businessInfo 
 $name = "accounts/" . $config['accountId'] . "/businessInfo"; 
 // Create a BusinessInfo with the updated fields. 
 // Note that you cannot update the RegionCode or the Phone of the business 
 $businessInfo = new BusinessInfo([ 
 'name' => $name, 
 'address' => new PostalAddress([ 
 'language_code' => 'en', 
 'postal_code' => 'C1107', 
 'address_lines' => [ 
 'Av. Alicia Moreau de Justo 350, Cdad. Autónoma de Buenos Aires, Argentina' 
 ] 
 ]) 
 ]); 
 $fieldMask = (new FieldMask())->setPaths(['address']); 
 try { 
 $request = new UpdateBusinessInfoRequest([ 
 'business_info' => $businessInfo, 
 'update_mask' => $fieldMask 
 ]); 
 print "Sending Update BusinessInfo request\n"; 
 $response = $businessInfoServiceClient->updateBusinessInfo($request); 
 print "Updated BusinessInfo 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::updateBusinessInfoSample($config); 
 } 
 } 
 // Run the script 
 $sample = new UpdateBusinessInfoSample(); 
 $sample->callSample(); 
  
 

Python

  # -*- 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. 
 """A module to update BusinessInfo.""" 
 from 
  
 examples.authentication 
  
 import 
 configuration 
 from 
  
 examples.authentication 
  
 import 
 generate_user_credentials 
 from 
  
 google.protobuf 
  
 import 
 field_mask_pb2 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 BusinessInfo 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 BusinessInfoServiceClient 
 from 
  
 google.shopping.merchant_accounts_v1 
  
 import 
 UpdateBusinessInfoRequest 
 from 
  
 google.type 
  
 import 
 postal_address_pb2 
 FieldMask 
 = 
 field_mask_pb2 
 . 
 FieldMask 
 _ACCOUNT 
 = 
 configuration 
 . 
 Configuration 
 () 
 . 
 read_merchant_info 
 () 
 def 
  
 update_business_info 
 (): 
  
 """Updates a BusinessInfo to a new address.""" 
 # Get OAuth credentials 
 credentials 
 = 
 generate_user_credentials 
 . 
 main 
 () 
 # Create a BusinessInfoServiceClient 
 business_info_service_client 
 = 
 BusinessInfoServiceClient 
 ( 
 credentials 
 = 
 credentials 
 ) 
 # Create BusinessInfo name 
 name 
 = 
 "accounts/" 
 + 
 _ACCOUNT 
 + 
 "/businessInfo" 
 # Create a PostalAddress 
 address 
 = 
 postal_address_pb2 
 . 
 PostalAddress 
 ( 
 language_code 
 = 
 "en" 
 , 
 postal_code 
 = 
 "C1107" 
 , 
 address_lines 
 = 
 [ 
 "Av. Alicia Moreau de Justo 350, Cdad. Autónoma de Buenos Aires," 
 " Argentina" 
 ], 
 ) 
 # Create a BusinessInfo object 
 business_info 
 = 
 BusinessInfo 
 ( 
 name 
 = 
 name 
 , 
 address 
 = 
 address 
 ) 
 # Create a FieldMask 
 field_mask 
 = 
 FieldMask 
 ( 
 paths 
 = 
 [ 
 "address" 
 ]) 
 # Create the request 
 request 
 = 
 UpdateBusinessInfoRequest 
 ( 
 business_info 
 = 
 business_info 
 , 
 update_mask 
 = 
 field_mask 
 ) 
 # Call the API and print the response 
 try 
 : 
 print 
 ( 
 "Sending Update BusinessInfo request" 
 ) 
 response 
 = 
 business_info_service_client 
 . 
 update_business_info 
 ( 
 request 
 = 
 request 
 ) 
 print 
 ( 
 "Updated BusinessInfo Name below" 
 ) 
 print 
 ( 
 response 
 . 
 name 
 ) 
 except 
 RuntimeError 
 as 
 e 
 : 
 print 
 ( 
 e 
 ) 
 if 
 __name__ 
 == 
 "__main__" 
 : 
 update_business_info 
 () 
  
 
Create a Mobile Website
View Site in Mobile | Classic
Share by: