Stay organized with collections
Save and categorize content based on your preferences.
Merchant API code sample to get 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.packageshopping.merchant.samples.accounts.businessinfos.v1;importcom.google.api.gax.core.FixedCredentialsProvider;importcom.google.auth.oauth2.GoogleCredentials;importcom.google.shopping.merchant.accounts.v1.BusinessInfo;importcom.google.shopping.merchant.accounts.v1.BusinessInfoName;importcom.google.shopping.merchant.accounts.v1.BusinessInfoServiceClient;importcom.google.shopping.merchant.accounts.v1.BusinessInfoServiceSettings;importcom.google.shopping.merchant.accounts.v1.GetBusinessInfoRequest;importshopping.merchant.samples.utils.Authenticator;importshopping.merchant.samples.utils.Config;/** This class demonstrates how to get the business info of a Merchant Center account. */publicclassGetBusinessInfoSample{publicstaticvoidgetBusinessInfo(Configconfig)throwsException{// Obtains OAuth token based on the user's configuration.GoogleCredentialscredential=newAuthenticator().authenticate();// Creates service settings using the credentials retrieved above.BusinessInfoServiceSettingsbusinessInfoServiceSettings=BusinessInfoServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();// Creates BusinessInfo name to identify the BusinessInfo.Stringname=BusinessInfoName.newBuilder().setAccount(config.getAccountId().toString()).build().toString();// Calls the API and catches and prints any network failures/errors.try(BusinessInfoServiceClientbusinessInfoServiceClient=BusinessInfoServiceClient.create(businessInfoServiceSettings)){// The name has the format: accounts/{account}/businessInfoGetBusinessInfoRequestrequest=GetBusinessInfoRequest.newBuilder().setName(name).build();System.out.println("Sending get BusinessInfo request:");BusinessInforesponse=businessInfoServiceClient.getBusinessInfo(request);System.out.println("Retrieved BusinessInfo below");System.out.println(response);}catch(Exceptione){System.out.println(e);}}publicstaticvoidmain(String[]args)throwsException{Configconfig=Config.load();getBusinessInfo(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\BusinessInfoServiceClient;use Google\Shopping\Merchant\Accounts\V1\GetBusinessInfoRequest;/** * This class demonstrates how to get the business info of a Merchant Center account. */class GetBusinessInfoSample{ /** * Gets the business info of a Merchant Center account. * * @param array $config * The configuration data used for authentication and getting the account ID. * * @return void */ public static function getBusinessInfoSample(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"; // Calls the API and catches and prints any network failures/errors. try { $request = new GetBusinessInfoRequest(['name' => $name]); print "Sending get BusinessInfo request:\n"; $response = $businessInfoServiceClient->getBusinessInfo($request); print "Retrieved BusinessInfo 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(); self::getBusinessInfoSample($config); }}// Run the script$sample = new GetBusinessInfoSample();$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."""A module to get BusinessInfo."""fromexamples.authenticationimportconfigurationfromexamples.authenticationimportgenerate_user_credentialsfromgoogle.shopping.merchant_accounts_v1importBusinessInfoServiceClientfromgoogle.shopping.merchant_accounts_v1importGetBusinessInfoRequest_ACCOUNT=configuration.Configuration().read_merchant_info()defget_business_info():"""Gets the business information of a Merchant Center account."""# Get OAuth credentialscredentials=generate_user_credentials.main()# Create a BusinessInfoServiceClientbusiness_info_service_client=BusinessInfoServiceClient(credentials=credentials)# Create BusinessInfo namename="accounts/"+_ACCOUNT+"/businessInfo"# Create the requestrequest=GetBusinessInfoRequest(name=name)# Call the API and print the responsetry:print("Sending get BusinessInfo request:")response=business_info_service_client.get_business_info(request=request)print("Retrieved BusinessInfo below")print(response)exceptRuntimeErrorase:print(e)if__name__=="__main__":get_business_info()
[[["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 and Python demonstrating how to retrieve business information from a Merchant Center account using the Merchant API.\u003c/p\u003e\n"],["\u003cp\u003eThe Java code utilizes the \u003ccode\u003eBusinessInfoServiceClient\u003c/code\u003e to send a \u003ccode\u003eGetBusinessInfoRequest\u003c/code\u003e and receive the business information, handling credential authentication and service settings creation.\u003c/p\u003e\n"],["\u003cp\u003eThe Python sample similarly employs the \u003ccode\u003eBusinessInfoServiceClient\u003c/code\u003e to retrieve business info, including the creation of user credentials and building the request to interact with the API.\u003c/p\u003e\n"],["\u003cp\u003eBoth the Java and Python examples showcase how to format the request \u003ccode\u003ename\u003c/code\u003e properly to target a specific Merchant Center account's business information.\u003c/p\u003e\n"]]],["The code samples demonstrate retrieving a Merchant Center account's business information using the Merchant API in Java, PHP, and Python. Each sample authenticates using OAuth credentials, then creates a `BusinessInfoServiceClient`. They construct a `BusinessInfo` name using the account ID, format: `accounts/{account}/businessInfo`. A `GetBusinessInfoRequest` is built using this name. Finally, each sends this request via the API, receiving and printing the business information as a response and catching potential errors.\n"],null,["# Get business info\n\nMerchant API code sample to get business info. \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.businessinfos.v1;\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.accounts.v1.BusinessInfo;\n import com.google.shopping.merchant.accounts.v1.BusinessInfoName;\n import com.google.shopping.merchant.accounts.v1.BusinessInfoServiceClient;\n import com.google.shopping.merchant.accounts.v1.BusinessInfoServiceSettings;\n import com.google.shopping.merchant.accounts.v1.GetBusinessInfoRequest;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to get the business info of a Merchant Center account. */\n public class GetBusinessInfoSample {\n\n public static void getBusinessInfo(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 BusinessInfoServiceSettings businessInfoServiceSettings =\n BusinessInfoServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n // Creates BusinessInfo name to identify the BusinessInfo.\n String name =\n BusinessInfoName.newBuilder()\n .setAccount(config.getAccountId().toString())\n .build()\n .toString();\n\n // Calls the API and catches and prints any network failures/errors.\n try (BusinessInfoServiceClient businessInfoServiceClient =\n BusinessInfoServiceClient.create(businessInfoServiceSettings)) {\n\n // The name has the format: accounts/{account}/businessInfo\n GetBusinessInfoRequest request = GetBusinessInfoRequest.newBuilder().setName(name).build();\n\n System.out.println(\"Sending get BusinessInfo request:\");\n BusinessInfo response = businessInfoServiceClient.getBusinessInfo(request);\n\n System.out.println(\"Retrieved BusinessInfo 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 getBusinessInfo(config);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/accounts/businessinfos/v1/GetBusinessInfoSample.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\\BusinessInfoServiceClient;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\GetBusinessInfoRequest;\n\n /**\n * This class demonstrates how to get the business info of a Merchant Center account.\n */\n class GetBusinessInfoSample\n {\n /**\n * Gets the business info of a Merchant Center account.\n *\n * @param array $config\n * The configuration data used for authentication and getting the account ID.\n *\n * @return void\n */\n public static function getBusinessInfoSample(array $config): 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 $businessInfoServiceClient = new BusinessInfoServiceClient($options);\n\n // Creates BusinessInfo name to identify the BusinessInfo.\n // The name has the format: accounts/{account}/businessInfo\n $name = \"accounts/\" . $config['accountId'] . \"/businessInfo\";\n\n // Calls the API and catches and prints any network failures/errors.\n try {\n $request = new GetBusinessInfoRequest(['name' =\u003e $name]);\n print \"Sending get BusinessInfo request:\\n\";\n $response = $businessInfoServiceClient-\u003egetBusinessInfo($request);\n\n print \"Retrieved BusinessInfo 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 self::getBusinessInfoSample($config);\n }\n }\n\n // Run the script\n $sample = new GetBusinessInfoSample();\n $sample-\u003ecallSample(); \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/accounts/businessinfos/v1/GetBusinessInfoSample.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 \"\"\"A module to get BusinessInfo.\"\"\"\n\n\n from examples.authentication import configuration\n from examples.authentication import generate_user_credentials\n from google.shopping.merchant_accounts_v1 import BusinessInfoServiceClient\n from google.shopping.merchant_accounts_v1 import GetBusinessInfoRequest\n\n _ACCOUNT = configuration.Configuration().read_merchant_info()\n\n\n def get_business_info():\n \"\"\"Gets the business information of a Merchant Center account.\"\"\"\n\n # Get OAuth credentials\n credentials = generate_user_credentials.main()\n\n # Create a BusinessInfoServiceClient\n business_info_service_client = BusinessInfoServiceClient(\n credentials=credentials\n )\n\n # Create BusinessInfo name\n name = \"accounts/\" + _ACCOUNT + \"/businessInfo\"\n\n # Create the request\n request = GetBusinessInfoRequest(name=name)\n\n # Call the API and print the response\n try:\n print(\"Sending get BusinessInfo request:\")\n response = business_info_service_client.get_business_info(request=request)\n print(\"Retrieved BusinessInfo below\")\n print(response)\n except RuntimeError as e:\n print(e)\n\n\n if __name__ == \"__main__\":\n get_business_info()\n\n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/python/examples/accounts/businessinfos/v1/get_business_info_sample.py"]]