Merchant API のテスト アカウント

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"
}'

制限事項

テスト アカウントは機能検証を目的として設計されており、特定の制限があります。

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

ベスト プラクティス

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

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