A Google business groupis like a shared folder for your locations. A business group provides a safe way to share management of your locations with multiple users. For more information, see About business groups .
Before you upload your local inventory, specify the business group that your Merchant Center account will be responsible for. You can get the list of eligible business groups from the Business Profile using the Merchant API, but to get access you first need to link your account to a Business Profile.
Request access to a Business Profile
To get access to a Business Profile, use the gbpAccounts.LinkGbpAccount
method:
POST https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID}
/gbpAccounts:linkGbpAccount
{
"gbpEmail": "admin@example.com",
}
Replace the following:
-
ACCOUNT_ID: the unique identifier of your Merchant Center account -
GBP_EMAIL: the email of the administrator for the Business Profile
Upon calling this method, the service sends an email to the specified administrator, asking to either accept or decline the access request. If the administrator does not respond within 7 days, the request expires automatically.
List the available business groups
Once the administrator has approved the request, you can check available
business groups using the gbpAccounts.List
method.
Here's a sample request and successful response:
GET https://merchantapi.googleapis.com/accounts/v1/accounts/ {ACCOUNT_ID}
/gbpAccounts
Response:
200 OK
{
"gbpAccounts": [
{
"name": "accounts/ {ACCOUNT_ID}
/gbpAccounts/12345",
"gbpAccountId": 12345,
"type": USER,
"gbpAccountName": "admin@example.com",
"listingCount": 15
}, {
"name": "accounts/ {ACCOUNT_ID}
/gbpAccounts/67890",
"gbpAccountId": 67890,
"type": BUSINESS_ACCOUNT,
"gbpAccountName": "Google My Business Account",
"listingCount": 23
}
],
"nextPageToken": 50
}
You can utilize this code sample to retrieve all the eligible business groups:
Java
import
com.google.api.gax.core.FixedCredentialsProvider
;
import
com.google.auth.oauth2.GoogleCredentials
;
import
com.google.shopping.merchant.accounts.v1.AccountName
;
import
com.google.shopping.merchant.accounts.v1.GbpAccount
;
import
com.google.shopping.merchant.accounts.v1.GbpAccountsServiceClient
;
import
com.google.shopping.merchant.accounts.v1.GbpAccountsServiceClient.ListGbpAccountsPagedResponse
;
import
com.google.shopping.merchant.accounts.v1.GbpAccountsServiceSettings
;
import
com.google.shopping.merchant.accounts.v1.ListGbpAccountsRequest
;
import
shopping.merchant.samples.utils.Authenticator
;
import
shopping.merchant.samples.utils.Config
;
/**
* This class demonstrates how to get the list of GBP accounts for a given Merchant Center account
*/
public
class
ListGbpAccountsSample
{
public
static
void
listGbpAccounts
(
Config
config
)
throws
Exception
{
// Obtains OAuth token based on the user's configuration.
GoogleCredentials
credential
=
new
Authenticator
().
authenticate
();
// Creates service settings using the credentials retrieved above.
GbpAccountsServiceSettings
gbpAccountsServiceSettings
=
GbpAccountsServiceSettings
.
newBuilder
()
.
setCredentialsProvider
(
FixedCredentialsProvider
.
create
(
credential
))
.
build
();
String
accountId
=
config
.
getAccountId
().
toString
();
// Creates parent to identify the omnichannelSetting from which to list all Lfp Providers.
String
parent
=
AccountName
.
newBuilder
().
setAccount
(
accountId
).
build
().
toString
();
// Calls the API and catches and prints any network failures/errors.
try
(
GbpAccountsServiceClient
gbpAccountsServiceClient
=
GbpAccountsServiceClient
.
create
(
gbpAccountsServiceSettings
))
{
ListGbpAccountsRequest
request
=
ListGbpAccountsRequest
.
newBuilder
().
setParent
(
parent
).
build
();
System
.
out
.
println
(
"Sending list GBP accounts request:"
);
ListGbpAccountsPagedResponse
response
=
gbpAccountsServiceClient
.
listGbpAccounts
(
request
);
int
count
=
0
;
// Iterates over all the entries in the response.
for
(
GbpAccount
gbpAccount
:
response
.
iterateAll
())
{
System
.
out
.
println
(
gbpAccount
);
count
++
;
}
System
.
out
.
println
(
String
.
format
(
"The following count of elements were returned: %d"
,
count
));
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"An error has occured: "
);
System
.
out
.
println
(
e
);
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Config
config
=
Config
.
load
();
listGbpAccounts
(
config
);
}
}
PHP
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\GbpAccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\GbpAccount;
use Google\Shopping\Merchant\Accounts\V1\ListGbpAccountsRequest;
/**
* This class demonstrates how to get the list of GBP accounts for a given
* Merchant Center account.
*/
class ListGbpAccountsSample
{
/**
* A helper function to create the parent string.
*
* @param string $accountId The account ID.
*
* @return string The parent has the format: `accounts/{account_id}`
*/
private static function getParent(string $accountId): string
{
return sprintf('accounts/%s', $accountId);
}
/**
* Retrieves the list of GBP accounts for a given Merchant Center account.
*
* @param array $config The configuration data for authentication and account ID.
*
* @return void
*/
public static function listGbpAccounts(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.
$gbpAccountsServiceClient = new GbpAccountsServiceClient($options);
// Creates the parent account name to identify the merchant.
$parent = self::getParent($config['accountId']);
// Creates the request to list GBP accounts.
$request = new ListGbpAccountsRequest([
'parent' => $parent
]);
// Calls the API and catches and prints any network failures/errors.
try {
printf("Sending list GBP accounts request:%s", PHP_EOL);
$response = $gbpAccountsServiceClient->listGbpAccounts($request);
$count = 0;
// Iterates over all the GBP accounts in the response and prints them.
foreach ($response->iterateAllElements() as $gbpAccount) {
/** @var GbpAccount $gbpAccount */
print_r($gbpAccount->serializeToJsonString());
$count++;
}
printf(
"The following count of elements were returned: %d%s",
$count,
PHP_EOL
);
} catch (ApiException $e) {
printf("An error has occurred: %s%s", $e->getMessage(), PHP_EOL);
}
}
/**
* Helper to execute the sample.
*
* @return void
*/
public function callSample(): void
{
$config = Config::generateConfig();
self::listGbpAccounts($config);
}
}
// Runs the script.
$sample = new ListGbpAccountsSample();
$sample->callSample();

