Mit der Merchant API können Sie Merchant Center-Konten erstellen, die mit accountAggregation, accountManagement oder comparisonShopping mit einem erweiterten Konto verknüpft werden können. Mit der Methode accounts.createAndConfigure können Sie ein Konto erstellen und optional mit Nutzern konfigurieren und über Dienste mit anderen Konten verknüpfen.
In diesem Leitfaden wird erläutert, wie Sie mit der Merchant API Konten mit accountAggregation, accountManagement oder comparisonShopping erstellen:
accountAggregation: Wird von Marktplätzen, Mehrmarkenhändlern, internationalen Einzelhändlern und Partnern verwendet, die Unterkonten unter einem erweiterten Konto erstellen.accountManagement: Wird von Agenturen verwendet, die eigenständige Konten im Besitz des Händlers erstellen.comparisonShopping: Wird von Preisvergleichsportalen verwendet, die Konten im EWR und in Ländern erstellen, in denen Preisvergleichsportale verfügbar sind.
Wenn Sie accounts.createAndConfigure verwenden, müssen Sie das neue Konto mit einem Anbieter verknüpfen. Geben Sie dazu im Feld service mindestens einen der folgenden Werte an: accountAggregation, accountManagement oder comparisonShopping. Sie können accountAggregation und comparisonShopping in derselben Anfrage angeben, aber accountManagement kann nicht mit accountAggregation oder comparisonShopping kombiniert werden. Wenn Sie accountManagement angeben, fügen Sie dem neuen Konto mindestens einen Nutzer über das Feld user oder users hinzu.
Vorbereitung
Bevor Sie Konten mit der Merchant API erstellen können, müssen Sie je nach den von Ihnen verwendeten Diensten die folgenden Anforderungen erfüllen:
- Administratorzugriff: Sie benötigen Administratorzugriff auf das Konto des Anbieters, wenn Sie ein neues Konto mit
accountManagement,comparisonShoppingoderaccountAggregationverknüpfen. - Erweitertes Konto: Wenn Sie
accountAggregationverwenden, muss Ihr Anbieterkonto ein erweitertes Konto sein, das für die Kontozusammenführung konfiguriert ist. Wenn Sie ein Dienstleister sind und ein erweitertes Konto einrichten müssen, wenden Sie sich an den Support, um Hilfe bei der Konfiguration zu erhalten.
Konto erstellen (über die Kontoverwaltung oder den Preisvergleich)
Rufen Sie accounts.createAndConfigure auf, um ein neues Konto zu erstellen.
Dies ist die empfohlene Vorgehensweise für Partner, die Händler bei der Verwaltung ihrer Konten unterstützen, da Händler so die volle Kontrolle und Eigentumsrechte über ihr Konto behalten und Partnern gleichzeitig bestimmte Berechtigungen gewähren können.
Im Anfragetext:
- Geben Sie die Details des Kontos, das Sie erstellen möchten, im Feld
accountan. - Verwenden Sie im Feld
accountNamekeine wiederholten und unnötigen Satzzeichen, Großschreibung, Unterstriche, Großbuchstaben, Emojis oder nicht alphanumerischen Symbole wie/oder_. Vermeiden Sie Zusätze wie „Inc.“ oder „GmbH“, Werbetext, personenbezogene Daten oder unangemessene Sprache. Verwenden Sie einen kurzen, klaren und professionellen Namen. Weitere Informationen zum Hinzufügen eines Unternehmensnamens - Wenn Sie
accountManagementverwenden, geben Sie im Feldusermindestens einen Nutzer an, der Zugriff auf das Konto hat. - Geben Sie im Feld
servicealle Dienste an, die Sie für dieses Konto bereitstellen möchten, z. B.accountManagement, und legen Sie fürproviderden Ressourcennamen Ihres Kontos fest (z. B.providers/{YOUR_ACCOUNT_ID}). Eine Liste der verfügbaren Dienste wieproductsManagementodercampaignsManagementfinden Sie unter Kontobeziehungen verwalten.
Im folgenden Beispiel wird ein Konto mit dem Namen „merchantStore“ erstellt und mit dem Konto {YOUR_ACCOUNT_ID} für die Konto- und Produktverwaltung verknüpft:
POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
"account": {
"accountName": "merchantStore",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"user": [
{
"userId": "test@example.com",
"user": {
"accessRights": ["ADMIN"]
}
}
],
"service": [
{
"accountManagement": {},
"provider": "providers/{YOUR_ACCOUNT_ID}"
},
{
"productsManagement": {},
"provider": "providers/{YOUR_ACCOUNT_ID}"
}
]
}
Bei einem erfolgreichen Aufruf wird das neue Konto erstellt und für die angegebenen Dienste mit Ihrem Konto verknüpft. Wenn Sie beim Erstellen die Dienste accountManagement, accountAggregation oder comparisonShopping angeben, werden sie automatisch genehmigt und der Verknüpfungsstatus ist ESTABLISHED. Andere Dienstverknüpfungen befinden sich möglicherweise im Status PENDING, bis sie vom erstellten Konto akzeptiert werden. Der Antworttext enthält die neu erstellte Account-Ressource.
Im folgenden Beispiel wird gezeigt, wie Sie mit accounts.createAndConfigure ein Konto erstellen und konfigurieren:
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.AccessRight;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountManagement;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddAccountService;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddUser;
import com.google.shopping.merchant.accounts.v1.ProductsManagement;
import com.google.shopping.merchant.accounts.v1.User;
import com.google.type.TimeZone;
import java.util.List;
import shopping.merchant.samples.utils.Authenticator;
/**
* This class demonstrates how to create a new Merchant Center account and configure it with various
* services.
*/
public class CreateAndConfigureAccountSample {
public static void createAndConfigureAccount(
long providerId, String newAccountName, String userEmail) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Calls the API and catches and prints any network failures/errors.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
// The account to be created.
Account account =
Account.newBuilder()
.setAccountName(newAccountName)
.setTimeZone(TimeZone.newBuilder().setId("Europe/Zurich").build())
.setLanguageCode("en-US")
.build();
// The services to be added to the new account.
// This sample shows how to configure a new account with account management and
// product management.
// For more information about the different services, see:
// https://developers.google.com/merchant/api/guides/accounts/services
AddAccountService accountManagementService =
AddAccountService.newBuilder()
.setProvider("accounts/" + providerId)
.setExternalAccountId("external_account_id")
.setAccountManagement(AccountManagement.newBuilder().build())
.build();
// This part is optional. You can also omit this and link the account later.
AddAccountService productsManagementService =
AddAccountService.newBuilder()
.setProvider("accounts/" + providerId)
.setExternalAccountId("external_account_id")
.setProductsManagement(ProductsManagement.newBuilder().build())
.build();
// For sub-account creation, use the AccountAggregation service. For an example on how to do
// this, see the `CreateSubAccount` sample.
// The user to be added to the new account.
// This part is optional.
AddUser user =
AddUser.newBuilder()
.setUserId(userEmail)
.setUser(User.newBuilder().addAccessRights(AccessRight.STANDARD).build())
.build();
CreateAndConfigureAccountRequest request =
CreateAndConfigureAccountRequest.newBuilder()
.setAccount(account)
.addAllService(List.of(accountManagementService, productsManagementService))
.addUser(user)
.build();
System.out.println("Sending Create and Configure Account request:");
Account response = accountsServiceClient.createAndConfigureAccount(request);
System.out.println("Created Account below");
System.out.println(response);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
// This is the provider ID of the e-commerce platform.
long providerId = 123L;
// This is the name of the new account to be created.
String newAccountName = "MyNewShop";
// This is the email of a user to be added to the new account.
String userEmail = "test-user@gmail.com";
createAndConfigureAccount(providerId, newAccountName, userEmail);
}
}
Nachdem Sie ein solches Konto erstellt haben, müssen Sie es einrichten. Dazu gehören Schritte wie das Akzeptieren der Nutzungsbedingungen , das Einrichten von Informationen zum Unternehmen und das Bestätigen der Website.
E‑Mail-Bestätigung bei der Kontoerstellung unterdrücken
Wenn Sie ein Konto mit accounts.createAndConfigure erstellen, können Sie optional Bestätigungs-E‑Mails für neue Nutzer, die über das Feld user hinzugefügt wurden, unterdrücken. Setzen Sie dazu in der Anfrage für diesen Nutzer verificationMailSettings.verificationMailMode auf SUPPRESS_VERIFICATION_MAIL. Das ist nützlich, wenn Sie Nutzer im Namen des Händlers sofort nach der Erstellung mit der Methode users.verifySelf bestätigen möchten. Standardmäßig ist verificationMailMode auf SEND_VERIFICATION_MAIL festgelegt und Bestätigungs-E‑Mails werden an neue Nutzer gesendet, die während der Kontoerstellung hinzugefügt wurden.
POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
"account": {
"accountName": "merchantStore",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"user": [
{
"userId": "test@example.com",
"user": {
"accessRights": ["ADMIN"]
},
"verificationMailSettings": {
"verificationMailMode": "SUPPRESS_VERIFICATION_MAIL"
}
}
],
"service": [
{
"accountManagement": {},
"provider": "providers/{YOUR_ACCOUNT_ID}"
}
]
}
Wenn Sie verificationMailMode auf SUPPRESS_VERIFICATION_MAIL setzen, müssen Sie für jeden Nutzer, der während der Erstellung hinzugefügt wurde, users.verifySelf aufrufen, um die Bestätigung abzuschließen. Dieser Aufruf muss als der zu bestätigende Nutzer (der in userId angegebene Nutzer) authentifiziert werden, z. B. mit einem OAuth-Token des Nutzers.
Alias bei der Kontoerstellung angeben
Sie können einen Alias für ein Konto im Kontext eines Anbieters in CreateAndConfigureAccountRequest mit dem Feld setAlias angeben. Mit dem Alias kann das Konto in Ihrem System identifiziert werden. Wenn Sie ein Dienstanbieter sind, können Sie den Alias verwenden, um das Konto mit GET /accounts/v1/accounts/{provider}~{alias} abzurufen. Der Alias muss für einen bestimmten Anbieter eindeutig sein. Außerdem müssen Sie im Feld service der Anfrage einen Dienst mit demselben Anbieter angeben. Weitere Informationen zu den Anforderungen für Aliase finden Sie unter Kontobeziehungen verwalten.
POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
"account": {
"accountName": "merchantStore",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"service": [
{
"accountManagement": {},
"provider": "providers/{YOUR_ACCOUNT_ID}"
}
],
"setAlias": [
{
"provider": "providers/{YOUR_ACCOUNT_ID}",
"accountIdAlias": "my-merchant-alias"
}
]
}
Empfohlener Onboarding-Ablauf
Wenn Sie als Partner ein Konto im Namen eines Händlers erstellen, empfehlen wir den folgenden Ablauf:
- Konto erstellen: Rufen Sie
accounts.createAndConfiguremit Ihren Partneranmeldedaten auf, um ein neues Konto zu erstellen.- Legen Sie
serviceso fest, dassaccountManagementmit Ihrer Anbieter-ID verknüpft wird. - Fügen Sie den Händler mit dem Feld
userals Nutzer hinzu und setzen SieverificationMailSettings.verificationMailModeaufSUPPRESS_VERIFICATION_MAIL.
- Legen Sie
- Nutzer bestätigen: Rufen Sie mit den Anmeldedaten des Händlers (z. B. mit einem OAuth-Token)
users.verifySelfauf, um den Nutzerstatus vonPENDINGinVERIFIEDzu ändern. - Land des Unternehmens festlegen: Legen Sie mit den Händleranmeldedaten das Land des Unternehmens fest, indem Sie
address.regionCodemitaccounts.updateBusinessInfoaktualisieren. Dies ist erforderlich, bevor Sie die Nutzungsbedingungen akzeptieren können . - Nutzungsbedingungen akzeptieren : Akzeptieren Sie die Nutzungsbedingungen mit den Anmeldedaten des Händlers.
Mit diesem Ablauf kann ein Händler nahtlos auf Ihrer Plattform eingebunden werden, ohne E‑Mail-Einladungen von Google zu erhalten.
Kundenkonto erstellen (mit Kontoaggregation)
Kundenkonten sind separate Merchant Center-Konten, die über den Dienst accountAggregation mit Ihrem erweiterten Konto verknüpft sind. So können Sie sie zentral verwalten, während Einstellungen, Websites und Datenfeeds separat bleiben. Mit der Merchant Accounts Sub-API können Sie neue Kundenkonten erstellen.
Wenn Sie Kundenkonten erstellen möchten, müssen Sie zuerst eine erweiterte Kontoeinrichtung haben. Sie müssen Kontoadministrator sein, um Ihr Merchant Center-Konto in ein erweitertes Konto umzuwandeln. Außerdem dürfen für Ihr Konto keine ausstehenden Probleme vorliegen.
Wenn Sie ein neues Kundenkonto erstellen möchten, rufen Sie accounts.createAndConfigure auf.
Im Anfragetext:
- Geben Sie die Details des Kontos, das Sie erstellen möchten, im Feld
accountan. - Verwenden Sie im Feld
accountNamekeine wiederholten und unnötigen Satzzeichen, Großschreibung, Unterstriche oder nicht alphanumerischen Symbole (wie „/“ oder „_“). Vermeiden Sie Zusätze wie „Inc.“ oder „GmbH“, Werbetext, personenbezogene Daten oder unangemessene Sprache. Verwenden Sie einen kurzen, klaren und professionellen Namen. Weitere Informationen zum Hinzufügen eines Unternehmensnamens - Geben Sie optional im Feld
userneue autorisierte Nutzer an. Der Nutzerzugriff für das Konto wird ebenfalls vom übergeordneten erweiterten Konto übernommen. - Geben Sie im Feld
serviceden WertaccountAggregationan und legen Sie fürproviderden Ressourcennamen Ihres erweiterten Kontos fest (z. B.providers/{ADVANCED_ACCOUNT_ID}). Dadurch wird Ihr erweitertes Konto als Aggregator für das neue Konto festgelegt.
Im folgenden Beispiel wird ein Kundenkonto mit dem Namen „merchantStore“ erstellt, das mit dem erweiterten Konto {ADVANCED_ACCOUNT_ID} verknüpft ist:
POST https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure
{
"account": {
"accountName": "merchantStore",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"service": [
{
"accountAggregation": {},
"provider": "providers/{ADVANCED_ACCOUNT_ID}"
}
]
}
Bei einem erfolgreichen Aufruf wird das neue Kundenkonto erstellt und mit dem angegebenen erweiterten Konto verknüpft. Der Antworttext enthält die neu erstellte Account-Ressource.
In den folgenden Beispielen wird gezeigt, wie Sie mit accounts.createAndConfigure ein neues Kundenkonto erstellen.
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountAggregation;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest;
import com.google.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddAccountService;
import com.google.type.TimeZone;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to create a sub-account under an advanced account. */
public class CreateSubAccountSample {
private static String getParent(String accountId) {
return String.format("accounts/%s", accountId);
}
public static Account createSubAccount(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.
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent/provider to identify the advanced account into which to insert the subaccount.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
CreateAndConfigureAccountRequest request =
CreateAndConfigureAccountRequest.newBuilder()
.setAccount(
Account.newBuilder()
.setAccountName("Demo Business")
.setAdultContent(false)
.setTimeZone(TimeZone.newBuilder().setId("America/New_York").build())
.setLanguageCode("en-US")
.build())
.addService(
AddAccountService.newBuilder()
.setProvider(parent)
.setAccountAggregation(AccountAggregation.getDefaultInstance())
.build())
.build();
System.out.println("Sending Create SubAccount request");
Account response = accountsServiceClient.createAndConfigureAccount(request);
System.out.println("Inserted Account Name below");
// Format: `accounts/{account}`
System.out.println(response.getName());
return response;
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
createSubAccount(config);
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Account;
use Google\Shopping\Merchant\Accounts\V1\AccountAggregation;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\CreateAndConfigureAccountRequest;
use Google\Shopping\Merchant\Accounts\V1\CreateAndConfigureAccountRequest\AddAccountService;
use Google\Type\TimeZone;
/**
* This class demonstrates how to create a sub-account under an MCA account.
*/
class CreateSubAccount
{
private static function getParent(string $accountId): string
{
return sprintf("accounts/%s", $accountId);
}
public static function createSubAccount(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.
$accountsServiceClient = new AccountsServiceClient($options);
// Creates parent/provider to identify the MCA account into which to insert the subaccount.
$parent = self::getParent($config['accountId']);
// Calls the API and catches and prints any network failures/errors.
try {
$request = new CreateAndConfigureAccountRequest([
'account' => (new Account([
'account_name' => 'Demo Business',
'adult_content' => false,
'time_zone' => (new TimeZone(['id' => 'America/New_York'])),
'language_code' => 'en-US',
])),
'service' => [
(new AddAccountService([
'provider' => $parent,
'account_aggregation' => new AccountAggregation,
])),
],
]);
print "Sending Create SubAccount request\n";
$response = $accountsServiceClient->createAndConfigureAccount($request);
print "Inserted Account Name below\n";
// Format: `accounts/{account}
print $response->getName() . PHP_EOL;
} catch (ApiException $e) {
print $e->getMessage();
}
}
public function callSample(): void
{
$config = Config::generateConfig();
self::createSubAccount($config);
}
}
$sample = new CreateSubAccount();
$sample->callSample();
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import Account
from google.shopping.merchant_accounts_v1 import AccountAggregation
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import CreateAndConfigureAccountRequest
def get_parent(account_id):
return f"accounts/{account_id}"
def create_sub_account(account_id: str) -> Account:
"""Creates a sub-account under an advanced account."""
# Get OAuth credentials.
credentials = generate_user_credentials.main()
# Create a client.
client = AccountsServiceClient(credentials=credentials)
# Get the parent advanced account ID.
parent = get_parent(account_id)
# Create the request.
request = CreateAndConfigureAccountRequest(
account=Account(
account_name="Demo Business",
adult_content=False,
time_zone={"id": "America/New_York"},
language_code="en-US",
),
service=[
CreateAndConfigureAccountRequest.AddAccountService(
provider=parent,
account_aggregation=AccountAggregation(),
)
],
)
# Make the request and print the response.
try:
print("Sending Create SubAccount request")
response = client.create_and_configure_account(request=request)
print("Inserted Account Name below")
print(response.name)
return response
except RuntimeError as e:
print(e)
raise
if __name__ == "__main__":
_account_id = configuration.Configuration().read_merchant_info()
create_sub_account(_account_id)
cURL
curl -X POST \
"https://merchantapi.googleapis.com/accounts/v1/accounts:createAndConfigure" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"account": {
"accountName": "Demo Business",
"adultContent": false,
"timeZone": {
"id": "America/New_York"
},
"languageCode": "en-US"
},
"service": [
{
"accountAggregation": {},
"provider": "providers/{ADVANCED_ACCOUNT_ID}"
}
]
}'
Kundenkonten abrufen
Mit der Methode accounts.listSubaccounts können Sie alle Kundenkonten eines bestimmten erweiterten Kontos auflisten. Geben Sie die ID Ihres erweiterten Kontos im Feld provider der Anfrage-URL an.
Hier ist eine Beispielanfrage:
GET https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts
Hier ist eine Beispielantwort für einen erfolgreichen Aufruf:
{
"accounts": [
{
"name": "accounts/<var class=\"readonly\">{SUB_ACCOUNT_ID_1}</var>",
"accountId": "<var class=\"readonly\">{SUB_ACCOUNT_ID_1}</var>",
"accountName": "<var class=\"readonly\">{SUB_ACCOUNT_NAME_1}</var>",
"timeZone": {
"id": "America/Los_Angeles"
},
"languageCode": "en-US"
},
{
"name": "accounts/<var class=\"readonly\">{SUB_ACCOUNT_ID_2}</var>",
"accountId": "<var class=\"readonly\">{SUB_ACCOUNT_ID_2}</var>",
"accountName": "<var class=\"readonly\">{SUB_ACCOUNT_NAME_2}</var>",
"timeZone": {
"id": "America/Los_Angeles"
},
"languageCode": "en-US"
}
]
}
In den folgenden Beispielen wird gezeigt, wie Sie alle Kundenkonten Ihres erweiterten Kontos auflisten.
Java
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1.Account;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceClient.ListSubAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.ListSubAccountsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to list all the subaccounts of an advanced account. */
public class ListSubAccountsSample {
private static String getParent(String accountId) {
return String.format("accounts/%s", accountId);
}
public static ListSubAccountsPagedResponse listSubAccounts(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.
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates parent/provider to identify the advanced account from which to list all sub-accounts.
String parent = getParent(config.getAccountId().toString());
// Calls the API and catches and prints any network failures/errors.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
// The parent has the format: accounts/{account}
ListSubAccountsRequest request =
ListSubAccountsRequest.newBuilder().setProvider(parent).build();
System.out.println("Sending list subaccounts request:");
ListSubAccountsPagedResponse response = accountsServiceClient.listSubAccounts(request);
int count = 0;
// Iterates over all rows in all pages and prints the datasource in each row.
// Automatically uses the `nextPageToken` if returned to fetch all pages of data.
for (Account account : response.iterateAll()) {
System.out.println(account);
count++;
}
System.out.print("The following count of accounts were returned: ");
System.out.println(count);
return response;
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
listSubAccounts(config);
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\ListSubAccountsRequest;
/**
* This class demonstrates how to list all the subaccounts of an advanced account.
*/
class ListSubAccounts
{
private static function getParent(string $accountId): string
{
return sprintf("accounts/%s", $accountId);
}
public static function listSubAccounts(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.
$accountsServiceClient = new AccountsServiceClient($options);
// Creates parent/provider to identify the advanced account from which
//to list all accounts.
$parent = self::getParent($config['accountId']);
// Calls the API and catches and prints any network failures/errors.
try {
// The parent has the format: accounts/{account}
$request = new ListSubAccountsRequest(['provider' => $parent]);
print "Sending list subaccounts request:\n";
$response = $accountsServiceClient->listSubAccounts($request);
$count = 0;
// Iterates over all rows in all pages and prints the datasource in each row.
// Automatically uses the `nextPageToken` if returned to fetch all pages of data.
foreach ($response->iterateAllElements() as $account) {
print_r($account);
$count++;
}
print "The following count of accounts were returned: ";
print $count . PHP_EOL;
} catch (ApiException $e) {
print "An error has occured: \n";
print $e->getMessage();
}
}
public function callSample(): void
{
$config = Config::generateConfig();
self::listSubAccounts($config);
}
}
$sample = new ListSubAccounts();
$sample->callSample();
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import ListSubAccountsRequest
def get_parent(account_id):
return f"accounts/{account_id}"
def list_sub_accounts(account_id: str):
"""Lists all the subaccounts of an advanced account."""
# Get OAuth credentials.
credentials = generate_user_credentials.main()
# Create a client.
client = AccountsServiceClient(credentials=credentials)
# Get the parent advanced account ID.
parent = get_parent(account_id)
# Create the request.
request = ListSubAccountsRequest(provider=parent)
# Make the request and print the response.
try:
print("Sending list subaccounts request:")
response = client.list_sub_accounts(request=request)
count = 0
for account in response:
print(account)
count += 1
print(f"The following count of accounts were returned: {count}")
return response
except RuntimeError as e:
print("An error has occured: ")
print(e)
raise
if __name__ == "__main__":
_account_id = configuration.Configuration().read_merchant_info()
list_sub_accounts(_account_id)
cURL
curl -X GET \
"https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
Kundenkonto löschen
Wenn Sie ein Kundenkonto nicht mehr verwalten müssen, können Sie es mit der Methode accounts.delete löschen.
Für die Ausführung dieser Methode ist Administratorzugriff auf das zu löschende Konto erforderlich.
Hier ist eine Beispielanfrage:
DELETE https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}
Wenn der Vorgang erfolgreich abgeschlossen wurde, ist der Antworttext ein leeres JSON-Objekt, das angibt, dass das Konto gelöscht wurde.
In den folgenden Beispielen wird gezeigt, wie Sie ein Kundenkonto löschen.
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.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.DeleteAccountRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to delete a given Merchant Center account. */
public class DeleteAccountSample {
// This method can delete a standalone, advanced account or sub-account. If you delete an advanced
// account,
// all sub-accounts will also be deleted.
// Admin user access is required to execute this method.
public static void deleteAccount(Config config, String accountId) throws Exception {
// Obtains OAuth token based on the user's configuration.
GoogleCredentials credential = new Authenticator().authenticate();
// Creates service settings using the credentials retrieved above.
AccountsServiceSettings accountsServiceSettings =
AccountsServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(credential))
.build();
// Creates account name to identify the account.
String name =
AccountName.newBuilder()
.setAccount(accountId)
.build()
.toString();
// Calls the API.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
DeleteAccountRequest request =
DeleteAccountRequest.newBuilder()
.setName(name)
// Optional. If set to true, the account will be deleted even if it has offers or
// provides services to other accounts. Defaults to 'false'.
.setForce(true)
.build();
System.out.println("Sending Delete Account request");
accountsServiceClient.deleteAccount(request); // No response returned on success.
System.out.println("Delete successful.");
}
}
public static void deleteAccount(Config config) throws Exception {
deleteAccount(config, config.getAccountId().toString());
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
deleteAccount(config);
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\DeleteAccountRequest;
/**
* This class demonstrates how to delete a given Merchant Center account.
*/
class DeleteAccount
{
private static function getParent(string $accountId): string
{
return sprintf("accounts/%s", $accountId);
}
// This method can delete a standalone, advanced account or sub-account.
// If you delete an advanced account, all sub-accounts will also be deleted.
// Admin user access is required to execute this method.
public static function deleteAccount(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.
$accountsServiceClient = new AccountsServiceClient($options);
// Gets the account ID from the config file.
$accountId = $config['accountId'];
// Creates account name to identify the account.
$name = self::getParent($accountId);
// Calls the API and catches and prints any network failures/errors.
try {
$request = new DeleteAccountRequest([
'name' => $name,
// Optional. If set to true, the account will be deleted even if it has offers or
// provides services to other accounts. Defaults to 'false'.
'force' => true,
]);
print "Sending Delete Account request\n";
$accountsServiceClient->deleteAccount($request); // No response returned on success.
print "Delete successful.\n";
} catch (ApiException $e) {
print $e->getMessage();
}
}
public function callSample(): void
{
$config = Config::generateConfig();
self::deleteAccount($config);
}
}
$sample = new DeleteAccount();
$sample->callSample();
Python
from examples.authentication import configuration
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import DeleteAccountRequest
def get_parent(account_id):
return f"accounts/{account_id}"
def delete_account(account_id: str):
"""Deletes a given Merchant Center account."""
# Get OAuth credentials.
credentials = generate_user_credentials.main()
# Create a client.
client = AccountsServiceClient(credentials=credentials)
# Create the account name.
name = get_parent(account_id)
# Create the request.
request = DeleteAccountRequest(name=name, force=True)
# Make the request and print the response.
try:
print("Sending Delete Account request")
client.delete_account(request=request)
print("Delete successful.")
except RuntimeError as e:
print(e)
raise
if __name__ == "__main__":
_account_id = configuration.Configuration().read_merchant_info()
delete_account(_account_id)
cURL
curl -X DELETE \
"https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}?force=true" \
-H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \
Nutzungsbedingungen akzeptieren
Kundenkonten übernehmen die Merchant Center-Nutzungsbedingungen, die für das übergeordnete erweiterte Konto unterzeichnet wurden.
Informationen zum Unternehmen aktualisieren
Mit der Merchant Accounts API können Sie die Unternehmensinformationen für Ihre Kundenkonten bearbeiten.
- Wenn Sie die Informationen zum Unternehmen eines Kontos aufrufen möchten, rufen Sie
accounts.getBusinessInfoauf. - Wenn Sie die Informationen zum Unternehmen eines Kontos bearbeiten möchten, rufen Sie
accounts.updateBusinessInfoauf.