建立及管理子帳戶

在 Merchant API 中,進階帳戶可以與其他帳戶建立子帳戶關係。子帳戶可協助管理多個賣家和大規模網域的企業,例如在多個國家/地區經營的零售商。如要瞭解哪些類型的商家符合進階帳戶資格,請參閱「符合進階帳戶設定存取權資格的公司」。

您可以使用 Merchant Accounts API,在進階帳戶下建立新的子帳戶。您必須擁有現有的進階帳戶才能撥打這通電話。您無法使用 Merchant API 將現有的獨立商家帳戶移至帳戶。

如要將 Merchant Center 帳戶轉換成進階帳戶,您必須是帳戶管理員。您也必須確認帳戶沒有任何待處理的問題。如要瞭解如何取得進階帳戶,請參閱「申請進階帳戶設定」。

第三方供應商可以使用 Merchant Accounts API 開發介面,讓商家建立及管理帳戶詳細資料。

建立子帳戶

如要在進階帳戶下建立新的子帳戶,請呼叫 accounts.createAndConfigure

  1. 在「account欄位中提供子帳戶的詳細資料。
  2. users 欄位中指定任何新授權使用者。使用者存取權也會從上層帳戶繼承。
  3. service 欄位中指定 accountAggregation

    以下範例說明如何在帳戶 account/123 下建立子帳戶,該帳戶是子帳戶的匯總器:

    POST https://merchantapi.googleapis.com/accounts/v1beta/accounts:createAndConfigure
    
    {
      "account": {
        "accountName": "merchantStore",
        "adultContent": false,
        "testAccount": false,
        "timeZone": {
          "id": "America/New_York",
        }
        "languageCode": "en-US",
      },
      "service": [
        {
          "accountAggregation": {},
          "provider": "providers/123"
        }
      ]
    }
    

以下範例說明如何使用 CreateAndConfigureAccountRequest 套件建立新的子帳戶。

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.Account;
import com.google.shopping.merchant.accounts.v1beta.AccountAggregation;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1beta.CreateAndConfigureAccountRequest;
import com.google.shopping.merchant.accounts.v1beta.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 MCA 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 MCA 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);
  }
}

擷取子帳戶

如要列出特定多重客戶帳戶的所有子帳戶,請使用 accounts.listSubaccounts 方法。

以下是範例要求:

GET https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}:listSubaccounts

以下是成功呼叫的回應範例:

{
  "accounts": [
    {
      "name": "accounts/{ACCOUNT_ID}",
      "accountId": "{ACCOUNT_ID}",
      "accountName": "{ACCOUNT_NAME}",
      "timeZone": {
        "id": "America/Los_Angeles"
      },
      "languageCode": "en-US"
    },
    {
      "name": "accounts/{ACCOUNT_ID}",
      "accountId": "{ACCOUNT_ID}",
      "accountName": "{ACCOUNT_NAME}",
      "timeZone": {
        "id": "America/Los_Angeles"
      },
      "languageCode": "en-US"
    }
  ]
}

刪除子帳戶

如要刪除子帳戶,請使用 accounts.delete 方法。執行這個方法需要管理員存取權

以下是範例要求:

DELETE https://merchantapi.googleapis.com/accounts/v1beta/accounts/{ACCOUNT_ID}

如果成功,回應主體會是空的 JSON 物件。

接受《服務條款》

子帳戶會繼承上層帳戶簽署的 Merchant Center《服務條款》(TOS)

更新商家資訊

您可以使用 Merchant Accounts API 編輯商家資訊