Stay organized with collections
Save and categorize content based on your preferences.
Merchant API code sample to get a business identity.
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.businessidentities.v1;importcom.google.api.gax.core.FixedCredentialsProvider;importcom.google.auth.oauth2.GoogleCredentials;importcom.google.shopping.merchant.accounts.v1.BusinessIdentity;importcom.google.shopping.merchant.accounts.v1.BusinessIdentityName;importcom.google.shopping.merchant.accounts.v1.BusinessIdentityServiceClient;importcom.google.shopping.merchant.accounts.v1.BusinessIdentityServiceSettings;importcom.google.shopping.merchant.accounts.v1.GetBusinessIdentityRequest;importshopping.merchant.samples.utils.Authenticator;importshopping.merchant.samples.utils.Config;/** This class demonstrates how to get the business identity of a Merchant Center account. */publicclassGetBusinessIdentitySample{publicstaticvoidgetBusinessIdentity(Configconfig)throwsException{// Obtains OAuth token based on the user's configuration.GoogleCredentialscredential=newAuthenticator().authenticate();// Creates service settings using the credentials retrieved above.BusinessIdentityServiceSettingsbusinessIdentityServiceSettings=BusinessIdentityServiceSettings.newBuilder().setCredentialsProvider(FixedCredentialsProvider.create(credential)).build();// Creates BusinessIdentity name to identify the BusinessIdentity.Stringname=BusinessIdentityName.newBuilder().setAccount(config.getAccountId().toString()).build().toString();// Calls the API and catches and prints any network failures/errors.try(BusinessIdentityServiceClientbusinessIdentityServiceClient=BusinessIdentityServiceClient.create(businessIdentityServiceSettings)){// The name has the format: accounts/{account}/businessIdentityGetBusinessIdentityRequestrequest=GetBusinessIdentityRequest.newBuilder().setName(name).build();System.out.println("Sending get BusinessIdentity request:");BusinessIdentityresponse=businessIdentityServiceClient.getBusinessIdentity(request);System.out.println("Retrieved BusinessIdentity below");System.out.println(response);}catch(Exceptione){System.out.println(e);}}publicstaticvoidmain(String[]args)throwsException{Configconfig=Config.load();getBusinessIdentity(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\BusinessIdentityServiceClient;use Google\Shopping\Merchant\Accounts\V1\GetBusinessIdentityRequest;/** * This class demonstrates how to get the business identity of a Merchant Center account. */class GetBusinessIdentitySample{ /** * Retrieves the business identity for the given Merchant Center account. * * @param array $config The configuration data containing the account ID. * @return void */ public static function getBusinessIdentity($config) { // 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. $businessIdentityServiceClient = new BusinessIdentityServiceClient($options); // Creates BusinessIdentity name to identify the BusinessIdentity. // The name has the format: accounts/{account}/businessIdentity $name = "accounts/" . $config['accountId'] . "/businessIdentity"; // Calls the API and catches and prints any network failures/errors. try { $request = (new GetBusinessIdentityRequest()) ->setName($name); print "Sending get BusinessIdentity request:\n"; $response = $businessIdentityServiceClient->getBusinessIdentity($request); print "Retrieved BusinessIdentity 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::getBusinessIdentity($config); }}// Run the script$sample = new GetBusinessIdentitySample();$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 get BusinessIdentity."""fromexamples.authenticationimportconfigurationfromexamples.authenticationimportgenerate_user_credentialsfromgoogle.shopping.merchant_accounts_v1importBusinessIdentityServiceClientfromgoogle.shopping.merchant_accounts_v1importGetBusinessIdentityRequest_ACCOUNT=configuration.Configuration().read_merchant_info()defget_business_identity():"""Gets the business identity of a Merchant Center account."""# Gets OAuth Credentials.credentials=generate_user_credentials.main()# Creates a client.client=BusinessIdentityServiceClient(credentials=credentials)# Creates BusinessIdentity name to identify the BusinessIdentity.name="accounts/"+_ACCOUNT+"/businessIdentity"# Creates the request.request=GetBusinessIdentityRequest(name=name)# Makes the request and catches and prints any error messages.try:response=client.get_business_identity(request=request)print("Retrieved BusinessIdentity below")print(response)exceptRuntimeErrorase:print(e)if__name__=="__main__":get_business_identity()
[[["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 Java code sample demonstrates how to retrieve the business identity of a Merchant Center account using the Merchant API.\u003c/p\u003e\n"],["\u003cp\u003eThe code utilizes the \u003ccode\u003eBusinessIdentityServiceClient\u003c/code\u003e to make a \u003ccode\u003eGetBusinessIdentity\u003c/code\u003e request.\u003c/p\u003e\n"],["\u003cp\u003eIt authenticates using OAuth and creates service settings with the retrieved credentials.\u003c/p\u003e\n"],["\u003cp\u003eThe sample constructs a \u003ccode\u003eBusinessIdentityName\u003c/code\u003e to identify the specific business identity being requested, using the account ID.\u003c/p\u003e\n"],["\u003cp\u003eThe response object \u003ccode\u003eBusinessIdentity\u003c/code\u003e contains the requested information about the business.\u003c/p\u003e\n"]]],["The code samples demonstrate how to retrieve a Merchant Center account's business identity using the Merchant API in Java, PHP, and Python. Key actions include obtaining OAuth credentials, creating a `BusinessIdentityServiceClient`, constructing a `BusinessIdentity` name with the account ID, and sending a `GetBusinessIdentityRequest`. The API response, containing the requested `BusinessIdentity`, is then printed. Error handling is included to manage network failures.\n"],null,["# Get a business identity\n\nMerchant API code sample to get a business identity. \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.businessidentities.v1;\n import com.google.api.gax.core.FixedCredentialsProvider;\n import com.google.auth.oauth2.GoogleCredentials;\n import com.google.shopping.merchant.accounts.v1.BusinessIdentity;\n import com.google.shopping.merchant.accounts.v1.BusinessIdentityName;\n import com.google.shopping.merchant.accounts.v1.BusinessIdentityServiceClient;\n import com.google.shopping.merchant.accounts.v1.BusinessIdentityServiceSettings;\n import com.google.shopping.merchant.accounts.v1.GetBusinessIdentityRequest;\n import shopping.merchant.samples.utils.Authenticator;\n import shopping.merchant.samples.utils.Config;\n\n /** This class demonstrates how to get the business identity of a Merchant Center account. */\n public class GetBusinessIdentitySample {\n\n public static void getBusinessIdentity(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 BusinessIdentityServiceSettings businessIdentityServiceSettings =\n BusinessIdentityServiceSettings.newBuilder()\n .setCredentialsProvider(FixedCredentialsProvider.create(credential))\n .build();\n\n // Creates BusinessIdentity name to identify the BusinessIdentity.\n String name =\n BusinessIdentityName.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 (BusinessIdentityServiceClient businessIdentityServiceClient =\n BusinessIdentityServiceClient.create(businessIdentityServiceSettings)) {\n\n // The name has the format: accounts/{account}/businessIdentity\n GetBusinessIdentityRequest request =\n GetBusinessIdentityRequest.newBuilder().setName(name).build();\n\n System.out.println(\"Sending get BusinessIdentity request:\");\n BusinessIdentity response = businessIdentityServiceClient.getBusinessIdentity(request);\n\n System.out.println(\"Retrieved BusinessIdentity 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 getBusinessIdentity(config);\n }\n } \n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/java/src/main/java/shopping/merchant/samples/accounts/businessidentities/v1/GetBusinessIdentitySample.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\\BusinessIdentityServiceClient;\n use Google\\Shopping\\Merchant\\Accounts\\V1\\GetBusinessIdentityRequest;\n\n /**\n * This class demonstrates how to get the business identity of a Merchant Center account.\n */\n class GetBusinessIdentitySample\n {\n /**\n * Retrieves the business identity for the given Merchant Center account.\n *\n * @param array $config The configuration data containing the account ID.\n * @return void\n */\n public static function getBusinessIdentity($config)\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 $businessIdentityServiceClient = new BusinessIdentityServiceClient($options);\n\n // Creates BusinessIdentity name to identify the BusinessIdentity.\n // The name has the format: accounts/{account}/businessIdentity\n $name = \"accounts/\" . $config['accountId'] . \"/businessIdentity\";\n\n // Calls the API and catches and prints any network failures/errors.\n try {\n $request = (new GetBusinessIdentityRequest())\n -\u003esetName($name);\n\n print \"Sending get BusinessIdentity request:\\n\";\n $response = $businessIdentityServiceClient-\u003egetBusinessIdentity($request);\n print \"Retrieved BusinessIdentity 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::getBusinessIdentity($config);\n }\n }\n\n // Run the script\n $sample = new GetBusinessIdentitySample();\n $sample-\u003ecallSample();\n\n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/php/examples/accounts/businessidentities/v1/GetBusinessIdentitySample.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 get BusinessIdentity.\"\"\"\n\n from examples.authentication import configuration\n from examples.authentication import generate_user_credentials\n from google.shopping.merchant_accounts_v1 import BusinessIdentityServiceClient\n from google.shopping.merchant_accounts_v1 import GetBusinessIdentityRequest\n\n _ACCOUNT = configuration.Configuration().read_merchant_info()\n\n\n def get_business_identity():\n \"\"\"Gets the business identity of a Merchant Center account.\"\"\"\n\n # Gets OAuth Credentials.\n credentials = generate_user_credentials.main()\n\n # Creates a client.\n client = BusinessIdentityServiceClient(credentials=credentials)\n\n # Creates BusinessIdentity name to identify the BusinessIdentity.\n name = \"accounts/\" + _ACCOUNT + \"/businessIdentity\"\n\n # Creates the request.\n request = GetBusinessIdentityRequest(name=name)\n\n # Makes the request and catches and prints any error messages.\n try:\n response = client.get_business_identity(request=request)\n print(\"Retrieved BusinessIdentity below\")\n print(response)\n except RuntimeError as e:\n print(e)\n\n\n if __name__ == \"__main__\":\n get_business_identity()\n\n https://github.com/google/merchant-api-samples/blob/c6de994268c785ce22af0065932518a9ac5b3c03/python/examples/accounts/businessidentities/v1/get_business_identity_sample.py"]]