Merchant API のテスト アカウント

Merchant API テスト アカウント機能は、統合を本番環境にデプロイする前に、安全で隔離されたスペースで徹底的にテストできるようにします。サンドボックス化されたテスト アカウントを使用すると、本番環境データに影響を与えたり、リアルタイム オペレーションを中断したり、Merchant Center ポリシーに誤って違反したりすることなく、API 呼び出しをテストし、コードを検証して、開発サイクルの早い段階で潜在的な問題を特定できます。

前提条件

テストアカウントを作成して使用する前に、次の要件を満たしていることを確認してください。

  • Merchant Center アカウント: Merchant Center アカウントが必要です。
  • Merchant API へのアクセス: Merchant API の確認済みユーザーである必要があります。

テスト アカウントのメリット

テスト アカウントを使用すると、主に次のようなメリットがあります。

  • 簡単な設定: テスト アカウントの設定は複雑なプロセスではないため、機能や統合のテストをすぐに開始できます。
  • データの完全性と安全性: 本番環境データは保護されたままであり、本番環境アカウントでのポリシー違反のリスクが排除されます。
  • テストの効率化: テスト目的で並列の本番環境アカウントを維持する負担をかけることなく、さまざまなシナリオやエッジケースをテストできます。
  • オファーの即時検証: テスト アカウントのホームページの申請と検証の自動免除を利用して、オファーの挿入を迅速にテストします。テスト アカウントの場合、オファーはデフォルトで承認されます。
  • 現実的なシミュレーション: この環境は、商品のアップロードや広告在庫管理などの重要な機能の本番環境の動作をミラーリングし、テスト結果の信頼性を確保します。
  • API 移行の円滑化: テスト アカウントを使用すると、Content API から Merchant 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 メソッドは、常にスタンドアロンのテストアカウントを作成します。テスト用にアドバンス アカウントの階層を設定するには:

  1. accounts.createTestAccount を使用してスタンドアロンのテスト アカウントを作成します。
  2. ヘルプセンターの記事「アドバンス アカウント設定に変換する」のガイダンスに沿って、Merchant Center でその単体のテスト用アカウントをアドバンス アカウントに変換します。
  3. accounts.createAndConfigure を呼び出し、高度なテスト アカウントを accountAggregation プロバイダとして指定して、高度なテスト アカウントの下に追加のテスト サブアカウントを作成します。テスト プロバイダ アカウントで作成されたサブアカウントは、自動的にテスト アカウント(testAccount: true)として作成されます。

制限事項

テスト アカウントは機能検証用に設計されており、次のような制限があります。

  • テストアカウントの数: Google アカウントごとに最大 5 つのテストアカウントを作成できます。テスト アカウントは、Google アカウントあたりの Merchant Center アカウントのデフォルトの上限にカウントされます。
  • Merchant API の割り当てとの統合: API の割り当ての観点から、Merchant API はテスト アカウントを本番環境アカウントとして扱います。テスト アカウントには、本番環境アカウントと同じ割り当てが適用されます。テスト アカウントの割り当てを増やすことはできません。
  • アカウントの変換とアドバンス アカウント: 通常の(ライブ)アカウント(スタンドアロン アカウントまたはアドバンス アカウント)をテストアカウントに変換したり、テストアカウントをライブアカウントに変換したりすることはできません。また、accounts.createTestAccount を使用して高度なテスト アカウントを直接作成することはできません。まず、スタンドアロンのテスト アカウントを作成し、それをアドバンス アカウントに変換します。
  • 一般公開されない: テスト アカウントに送信されたデータは、Google 検索やショッピング広告などの Google プラットフォームで公開されることはありません。
  • 制限付きエンドポイント: 次のような特定の機能を使用する場合は、テスト アカウントを使用できません。
  • リンクの制限: テストアカウントを他の Google 広告アカウントや Google ビジネス プロフィール アカウントにリンクすることはできません。
  • テスト アカウントの登録は不可: テスト アカウントの登録はできません。

ベスト プラクティス

テストアカウントを使用する際は、次のベスト プラクティスに沿って行うことをおすすめします。

  • サンドボックス ファーストの開発: 新しい統合機能は、本番環境に適用する前に、必ずテスト アカウントで検証してください。
  • 自動統合テスト: テスト アカウントを、自動回帰テストを実行するための安定した環境として使用します。
  • テスト アカウントの命名: account_name を使用して、各テスト アカウントの目的(「移行テスト」や「統合テスト アカウント」など)を示します。