Merchant API テスト アカウント機能は、本番環境にデプロイする前に統合を徹底的にテストするための安全で隔離されたスペースを提供します。サンドボックス テスト アカウントを使用すると、本番環境データに影響を与えたり、リアルタイム オペレーションを中断したり、Merchant Center のポリシーに誤って違反したりすることなく、API 呼び出しを試したり、コードを検証したり、開発サイクルの早い段階で潜在的な問題を特定したりできます。
前提条件
テスト アカウントを作成して使用する前に、次の要件を満たしていることを確認してください。
- Merchant Center アカウント: Merchant Center アカウントが必要です。
- Merchant API へのアクセス: Merchant API の登録ユーザーである必要があります。
テスト アカウントのメリット
テスト アカウントを使用すると、主に次のようなメリットがあります。
- 簡単な設定: テスト アカウントの設定は複雑なプロセスではなく、機能と統合のテストをすぐに開始できます。
- データの完全性と安全性: 本番環境のデータは保護されたままになり、本番環境アカウントでのポリシー違反のリスクがなくなります。
- テストの効率性: テスト目的で並行して本番環境アカウントを維持する負担を負うことなく、さまざまなシナリオとエッジケースをテストできます。
- 即時提案の検証: テスト アカウントのホームページの所有権主張と検証が自動的に免除されるため、提案の挿入をすばやくテストできます。テスト アカウントでは、特典はデフォルトで承認されます。
- リアルなシミュレーション: 環境は、商品のアップロードや広告在庫管理などの重要な機能について、本番環境の動作を反映しているため、テスト結果の信頼性が確保されます。
- API の移行をスムーズに: テスト アカウントを使用すると、Content API から Merchant API への移行や、ある API バージョンから別の API バージョンへの移行を、並行して検証できるため、自信を持ってスムーズに移行できます。
テスト アカウントの作成方法
テスト アカウントは、Merchant API の特定のカスタム メソッドを使用して作成されます。
accounts.createTestAccount メソッドを使用します。
POST https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}:createTestAccount
Content-Type: application/json
Authorization: Bearer {ACCESS_TOKEN}"
{
"account_name": "{TEST_ACCOUNT_NAME}",
"time_zone": {
"id": "America/Los_Angeles"
},
"language_code": "en-US"
}
以下を置き換えます。
ACCOUNT_ID: Merchant Center ID。ACCESS_TOKEN: API 呼び出しを行うための認証トークンTEST_ACCOUNT_NAME: テスト アカウントの名前。テストに使用されることを示す意味のある名前を使用することをおすすめします。たとえば、テスト アカウント名にtestという単語を含めます。
テスト アカウントを作成する際は、次のフィールドが必須です。
time_zone: アカウントのレポートと表示のタイムゾーン。language_code: アカウントの BCP-47 言語コード(en-USなど)。
呼び出しが成功すると、新しいテスト アカウントの一意の accountId とリソース名を含む Account リソースが返されます。
{
"name": "accounts/{TEST_ACCOUNT_ID}",
"accountId": "{TEST_ACCOUNT_ID}",
"accountName": "{TEST_ACCOUNT_NAME}",
"adultContent": false,
"testAccount": true,
"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.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.CreateTestAccountRequest;
import com.google.type.TimeZone;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/**
* This class demonstrates how to create a new Merchant Center test account.
*
* <p>For more information refer to:
* https://developers.google.com/merchant/api/guides/accounts/test-accounts
*/
public class CreateTestAccountSample {
// Method to create a test account.
public static void createTestAccount(Config config, String newAccountName) 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 test account to be created.
Account account =
Account.newBuilder()
.setAccountName(newAccountName)
.setTimeZone(TimeZone.newBuilder().setId("Europe/Zurich"))
.setLanguageCode("en-US")
.build();
// Creates parent to identify where to insert the account.
String parent = String.format("accounts/%s", config.getAccountId());
// Create the request message.
CreateTestAccountRequest request =
CreateTestAccountRequest.newBuilder().setParent(parent).setAccount(account).build();
System.out.println("Sending Create Test Account request:");
Account response = accountsServiceClient.createTestAccount(request);
System.out.println("Created Test Account below:");
System.out.println(response);
} catch (Exception e) {
System.err.println("Error during test account creation:");
e.printStackTrace();
}
}
// Main method to run the sample.
public static void main(String[] args) throws Exception {
Config config = Config.load();
// This is the name of the new test account to be created.
String newAccountName = "MyNewTestShop";
createTestAccount(config, newAccountName);
}
}
cURL
curl -X POST \
"https://merchantapi.googleapis.com/accounts/v1/accounts/{ACCOUNT_ID}/:createTestAccount" \
-H "Authorization: Bearer {ACCESS_TOKEN}" \
-H "Content-Type: application/json" \
-d '{
"account_name": "{TEST_ACCOUNT_NAME}",
"time_zone": {
"id": "America/Los_Angeles"
},
"language_code": "en-US"
}'
高度なテスト アカウントとサブアカウント
accounts.createTestAccount メソッドは常にスタンドアロンのテスト アカウントを作成します。テスト用にアドバンス アカウントの階層を設定するには:
accounts.createTestAccountを使用してスタンドアロンのテスト アカウントを作成します。- アドバンス アカウントのセットアップに変換するのヘルプセンター記事のガイダンスに沿って、その単体のテスト アカウントを Merchant Center のアドバンス アカウントに変換します。
accounts.createAndConfigureを呼び出し、高度なテスト アカウントをaccountAggregationプロバイダとして指定して、高度なテスト アカウントの下に追加のテスト サブアカウントを作成します。テスト プロバイダ アカウントで作成されたサブアカウントは、すべて自動的にテスト アカウント(testAccount: true)として作成されます。
制限事項
テスト アカウントは機能の検証を目的としており、次のような制限があります。
- テスト アカウントの数: 1 つの Google アカウントにつき最大 5 個のテスト アカウントを作成できます。テスト アカウントは、Google アカウントあたりの Merchant Center アカウントのデフォルトの上限にカウントされます。
- Merchant API の割り当てとの統合: API 割り当ての観点から見ると、Merchant API はテスト アカウントを本番環境アカウントとして扱います。テスト アカウントには、本番環境アカウントと同じ割り当てが適用されます。テスト アカウントの割り当てを増やすことはできません。
- アカウントの変換とアドバンス アカウント: 通常(本番環境)アカウント(スタンドアロン アカウントとアドバンス アカウントのどちらも)をテスト アカウントに変換したり、テスト アカウントを本番環境アカウントに変換したりすることはできません。また、
accounts.createTestAccountを使用して高度なテスト アカウントを直接作成することはできません。まず、スタンドアロンのテスト アカウントを作成し、アドバンス アカウントに変換します。 - 一般公開なし: テストアカウントに送信されたデータが、検索広告やショッピング広告などの Google プラットフォームで公開されることはありません。
- 制限付きエンドポイント: 次のような特定の機能を使用する場合、テスト アカウントは使用できません。
- リンクの制限: テスト アカウントを他の Google 広告アカウントや Google ビジネス プロフィール アカウントにリンクすることはできません。
- テスト アカウントの登録なし: テスト アカウントの登録はできません。
ベスト プラクティス
テスト アカウントを使用する際は、次のベスト プラクティスに沿って行うことをおすすめします。
- サンドボックス優先の開発: 新しい統合機能を本番環境に適用する前に、必ずテスト アカウントで検証してください。
- 自動統合テスト: テスト アカウントを、自動回帰テストを実行するための安定した環境として使用します。
- テスト アカウントの名前付け:
account_nameを使用して、各テスト アカウントの目的(「移行テスト」や「統合テスト アカウント」など)を示します。