Merchant API を使用して Merchant Center アカウントを作成し、accountAggregation、accountManagement、comparisonShopping を使用して高度なアカウントにリンクできます。accounts.createAndConfigure メソッドを使用すると、アカウントを作成し、必要に応じてユーザーで構成して、サービスを通じて他のアカウントにリンクできます。
このガイドでは、Merchant API を使用して accountManagement、comparisonShopping、accountAggregation などのサービスを使用してアカウントを作成する方法について説明します。accounts.createAndConfigure を使用する場合は、service フィールドで accountAggregation、accountManagement、comparisonShopping のいずれかを指定して、新しいアカウントをプロバイダにリンクする必要があります。同じリクエストで accountAggregation と comparisonShopping を指定できますが、accountManagement を accountAggregation または comparisonShopping と組み合わせることはできません。accountManagement を指定する場合は、user フィールドまたは users フィールドを使用して、新しいアカウントに少なくとも 1 人のユーザーを追加する必要があります。
前提条件
Merchant API を使用してアカウントを作成する前に、使用するサービスに応じて次の要件を満たしていることを確認してください。
- 管理者権限:
accountManagement、comparisonShopping、accountAggregationを使用して新しいアカウントをリンクする場合は、プロバイダ アカウントの管理者権限が必要です。 - アドバンス アカウント:
accountAggregationを使用する場合、プロバイダ アカウントはアカウント集約用に構成されたアドバンス アカウントである必要があります。サービス プロバイダで、高度なアカウントを設定する必要がある場合は、構成のサポートについてサポートにお問い合わせください。
アカウントを作成する(アカウント管理またはショッピング比較を使用)
新しいアカウントを作成するには、accounts.createAndConfigure を呼び出します。この方法は、販売者がアカウントの完全な制御と所有権を保持しながら、パートナーに特定の権限を付与できるため、販売者のアカウント管理を支援するパートナーにおすすめです。
リクエスト本文:
- 作成するアカウントの詳細を
accountフィールドに入力します。 accountManagementを使用している場合は、アカウントにアクセスできるユーザーをuserフィールドに少なくとも 1 人指定します。serviceフィールドで、このアカウントに提供するサービス(accountManagementなど)を指定し、providerをアカウントのリソース名(providers/{YOUR_ACCOUNT_ID}など)に設定します。productsManagementやcampaignsManagementなどの利用可能なサービスの一覧については、アカウント関係を管理するをご覧ください。
アカウントと商品の管理用に merchantStore という名前のアカウントを作成し、アカウント {YOUR_ACCOUNT_ID} にリンクするリクエストの例を次に示します。
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}"
}
]
}
呼び出しが成功すると、新しいアカウントが作成され、指定されたサービスのユーザーのアカウントにリンクされます。作成時に accountManagement、accountAggregation、または comparisonShopping サービスを指定すると、自動的に承認され、リンク状態は ESTABLISHED になります。他のサービスリンクは、作成されたアカウントによって承認されるまで PENDING 状態になることがあります。レスポンスの本文には、新しく作成された Account リソースが含まれます。
このようなアカウントを作成したら、利用規約に同意する、ビジネス情報を設定する、ウェブサイトを確認するなどの手順を行って、アカウントをオンボーディングする必要があります。
アカウント作成時のメール確認を抑制する
accounts.createAndConfigure でアカウントを作成するときに、user フィールドを使用して追加された新しいユーザーの確認メールを抑制するには、そのユーザーのリクエストで verificationMailSettings.verificationMailMode を SUPPRESS_VERIFICATION_MAIL に設定します。これは、users.verifySelf メソッドを使用して、作成直後に販売者に代わってユーザーを確認する場合に便利です。デフォルトでは、verificationMailMode は SEND_VERIFICATION_MAIL で、アカウントの作成時に追加された新しいユーザーに確認メールが送信されます。
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}"
}
]
}
verificationMailMode を SUPPRESS_VERIFICATION_MAIL に設定した場合は、作成時に追加されたユーザーごとに users.verifySelf を呼び出して、確認を完了する必要があります。この呼び出しは、検証対象のユーザー(userId で指定されたユーザー)として認証される必要があります(ユーザーの OAuth トークンを使用するなど)。
アカウントの作成時にエイリアスを指定する
CreateAndConfigureAccountRequest のプロバイダのコンテキストで、setAlias フィールドを使用してアカウントのエイリアスを指定できます。エイリアスは、システム内のアカウントを識別するために使用できます。サービス プロバイダは、エイリアスを使用して GET /accounts/v1/accounts/{provider}~{alias} でアカウントを取得できます。エイリアスはプロバイダごとに一意である必要があり、リクエストの service フィールドで同じプロバイダのサービスを指定する必要があります。エイリアスの要件の詳細については、アカウントの関係を管理するをご覧ください。
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"
}
]
}
推奨されるオンボーディング フロー
販売者に代わってアカウントを作成するパートナーの場合は、次のフローをおすすめします。
- アカウントを作成: パートナー認証情報を使用して
accounts.createAndConfigureを呼び出し、新しいアカウントを作成します。serviceを設定して、プロバイダ ID へのaccountManagementリンクを含めます。userフィールドを使用して販売者をユーザーとして追加し、verificationMailSettings.verificationMailModeをSUPPRESS_VERIFICATION_MAILに設定します。
- ユーザーを確認する: 販売者からの認証情報(OAuth トークンなどを使用)を使用して、
users.verifySelfを呼び出し、ユーザーの状態をPENDINGからVERIFIEDに変更します。 - ビジネスの国を設定する: 販売者の認証情報を使用して、
accounts.updateBusinessInfoを使用してaddress.regionCodeを更新し、ビジネスの国を設定します。これは、利用規約に同意する前に必要です。 - 利用規約に同意する: 販売者の認証情報を使用して、利用規約に同意します。
このフローにより、販売者は Google から招待メールを受け取ることなく、プラットフォーム内でシームレスにオンボーディングできます。
クライアント アカウントを作成する(アカウントの集約を使用)
クライアント アカウントは、accountAggregation サービスを使用して上級アカウントにリンクされた個別の Merchant Center アカウントです。設定、ウェブサイト、データフィードを個別に維持しながら、一元管理できます。Merchant Accounts サブ API を使用して、新しいクライアント アカウントを作成できます。
クライアント アカウントを作成するには、まず高度なアカウント設定を行う必要があります。Merchant Center アカウントをアドバンス アカウントに変換するには、アカウント管理者である必要があります。また、アカウントに未解決の問題がないことも条件となります。
新しいクライアント アカウントを作成するには、accounts.createAndConfigure を呼び出します。リクエスト本文:
- 作成するアカウントの詳細を
accountフィールドに入力します。 - 必要に応じて、[
user] フィールドで新しい承認済みユーザーを指定します。アカウントのユーザー アクセス権も、親の上級アカウントから継承されます。 serviceフィールドでaccountAggregationを指定し、providerをアドバンス アカウントのリソース名(providers/{ADVANCED_ACCOUNT_ID}など)に設定します。これにより、アドバンス アカウントが新しいアカウントのアグリゲータとして設定されます。
{ADVANCED_ACCOUNT_ID} のアドバンス アカウントにリンクされた「merchantStore」というクライアント アカウントを作成するリクエストの例を次に示します。
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}"
}
]
}
呼び出しが成功すると、新しいクライアント アカウントが作成され、指定されたアドバンス アカウントにリンクされます。レスポンスの本文には、新しく作成された Account リソースが含まれます。
次のサンプルは、accounts.createAndConfigure を使用して新しいクライアント アカウントを作成する方法を示しています。
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 void 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());
} catch (Exception e) {
System.out.println(e);
}
}
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
_ACCOUNT = configuration.Configuration().read_merchant_info()
def get_parent(account_id):
return f"accounts/{account_id}"
def create_sub_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)
# 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)
except RuntimeError as e:
print(e)
if __name__ == "__main__":
create_sub_account()
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}"
}
]
}'
クライアント アカウントを取得する
特定の上級アカウントのすべてのクライアント アカウントを一覧表示するには、accounts.listSubaccounts メソッドを使用します。リクエスト URL の provider フィールドに、詳細設定アカウントの ID を指定します。
リクエストの例を次に示します。
GET https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts
呼び出しが成功した場合のレスポンスの例を次に示します。
{
"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"
}
]
}
次のサンプルは、アドバンス アカウントのすべてのクライアント アカウントを一覧表示する方法を示しています。
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 void 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);
} 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();
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
_ACCOUNT = configuration.Configuration().read_merchant_info()
def get_parent(account_id):
return f"accounts/{account_id}"
def list_sub_accounts():
"""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)
# 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}")
except RuntimeError as e:
print("An error has occured: ")
print(e)
if __name__ == "__main__":
list_sub_accounts()
cURL
curl -X GET \
"https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts" \
-H "Authorization: Bearer <YOUR_ACCESS_TOKEN>"
クライアント アカウントを削除する
クライアント アカウントを管理する必要がなくなった場合は、accounts.delete メソッドを使用して削除できます。
このメソッドを実行するには、削除するアカウントに対する管理者権限が必要です。
リクエストの例を次に示します。
DELETE https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}
成功した場合、レスポンスの本文は空の JSON オブジェクトになり、アカウントが削除されたことを示します。
次のサンプルは、クライアント アカウントを削除する方法を示しています。
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) 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();
// Gets the account ID from the config file.
String accountId = config.getAccountId().toString();
// Creates account name to identify the account.
String name =
AccountName.newBuilder()
.setAccount(accountId)
.build()
.toString();
// Calls the API and catches and prints any network failures/errors.
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.");
} catch (Exception e) {
System.out.println(e);
}
}
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
_ACCOUNT = configuration.Configuration().read_merchant_info()
def get_parent(account_id):
return f"accounts/{account_id}"
def delete_account():
"""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)
# 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)
if __name__ == "__main__":
delete_account()
cURL
curl -X DELETE \
"https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}?force=true" \
-H "Authorization: Bearer <YOUR_ACCESS_TOKEN>"
利用規約に同意する
クライアント アカウントは、親アドバンス アカウントが署名したMerchant Center 利用規約(TOS)を継承します。
ビジネス情報を更新する
Merchant Accounts API を使用して、クライアント アカウントのビジネス情報を編集できます。
- アカウントのビジネス情報を表示するには、
accounts.getBusinessInfoを呼び出します。- アカウントのビジネス情報を編集するには、
accounts.updateBusinessInfoを呼び出します。
- アカウントのビジネス情報を編集するには、