You can use Merchant API to create Merchant Center accounts, which can be
linked to an [advanced account](https://support.google.com/merchants/answer/188487)
by using `accountAggregation`, `accountManagement` or `comparisonShopping`. The
[`accounts.createAndConfigure`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/createAndConfigure)
method lets you create an account and optionally configure it with users and
link it to other accounts through services.

This guide explains how to use Merchant API to create accounts
using `accountAggregation`, `accountManagement`, or `comparisonShopping`:

- **`accountAggregation`**: Used by marketplaces, multi-brand retailers, international retailers and partners creating sub-accounts under a multi-client advanced account.
- **`accountManagement`**: Used by agencies creating standalone accounts owned by the merchant.
- **`comparisonShopping`**: Used by Comparison Shopping Services (CSSs) creating accounts in EEA and CSS-eligible countries.

When using `accounts.createAndConfigure`, you must link the new account to a
provider by specifying at least one of `accountAggregation`,
`accountManagement`, or `comparisonShopping` in the `service` field. You can
specify `accountAggregation` and `comparisonShopping` in the same request, but
`accountManagement` cannot be combined with either `accountAggregation` or
`comparisonShopping`. If you specify `accountManagement`, add at
least one user to the new account using the `user` or `users` field.

## Prerequisites

Before you can create accounts using Merchant API, ensure you meet the following
requirements depending on the services you use:

- **Administrator access** : You must have administrator access to the provider account when linking a new account using `accountManagement`, `comparisonShopping`, or `accountAggregation`.
- **Advanced account** : If you use `accountAggregation`, your provider account must be an [advanced account](https://support.google.com/merchants/answer/188487) configured for account aggregation. If you are a service provider and need to set up an advanced account, [reach out to support](https://support.google.com/merchants/gethelp) for assistance with configuration.

## Create an account (using account management or comparison shopping)

To create a new account, call
[`accounts.createAndConfigure`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/createAndConfigure).
This is the recommended approach for partners helping merchants manage their
accounts, as it allows merchants to retain full control and ownership of
their account while granting specific permissions to partners.

In the request body:

1. Provide the details of the account you want to create in the [`account`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts#Account) field.
2. In the `accountName` field, don't use repeated and unnecessary punctuation, capitalization, underscores, all capital letters, emoji, or non-alphanumeric symbols like `/` or `_`. Avoid business suffixes (like "Inc." or "GmbH"), promotional text, personal information, or inappropriate language. Use a short, clear, and professional name. For more information, see [adding a business name](https://support.google.com/merchants/answer/12159159).
3. If you are using `accountManagement`, specify at least one user in the [`user`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/createAndConfigure#adduser) field who will have access to the account.
4. In the [`service`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/createAndConfigure#addaccountservice) field, specify any services you want to provide to this account, for example `accountManagement`, and set the `provider` to the resource name of your account (for example, `providers/{YOUR_ACCOUNT_ID}`). For a list of available services such as `productsManagement` or `campaignsManagement` see [Manage account relationships](https://developers.google.com/merchant/api/guides/accounts/relationships).

The following is an example request to create an account named "merchantStore"
and link it to account `{YOUR_ACCOUNT_ID}` for
account and product management:

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

A successful call creates the new account and links it to your account for the
specified services. If you specify `accountManagement`, `accountAggregation`,
or `comparisonShopping` services during creation, they are automatically
approved and the link state is `ESTABLISHED`. Other service links might be in
`PENDING` state until accepted by the created account. The response body
contains the newly created
[`Account`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts#Account) resource.

The following sample demonstrates how to use
[`accounts.createAndConfigure`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/createAndConfigure)
to create and configure an account:

### Java

    import com.google.api.gax.core.FixedCredentialsProvider;
    import com.google.auth.oauth2.GoogleCredentials;
    import com.google.shopping.merchant.accounts.v1.AccessRight;
    import com.google.shopping.merchant.accounts.v1.Account;
    import com.google.shopping.merchant.accounts.v1.AccountManagement;
    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.shopping.merchant.accounts.v1.CreateAndConfigureAccountRequest.AddUser;
    import com.google.shopping.merchant.accounts.v1.ProductsManagement;
    import com.google.shopping.merchant.accounts.v1.User;
    import com.google.type.TimeZone;
    import java.util.List;
    import shopping.merchant.samples.utils.Authenticator;

    /**
     * This class demonstrates how to create a new Merchant Center account and configure it with various
     * services.
     */
    public class CreateAndConfigureAccountSample {

      public static void createAndConfigureAccount(
          long providerId, String newAccountName, String userEmail) 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 account to be created.
          Account account =
              Account.newBuilder()
                  .setAccountName(newAccountName)
                  .setTimeZone(TimeZone.newBuilder().setId("Europe/Zurich").build())
                  .setLanguageCode("en-US")
                  .build();

          // The services to be added to the new account.
          // This sample shows how to configure a new account with account management and
          // product management.
          // For more information about the different services, see:
          // https://developers.google.com/merchant/api/guides/accounts/services
          AddAccountService accountManagementService =
              AddAccountService.newBuilder()
                  .setProvider("accounts/" + providerId)
                  .setExternalAccountId("external_account_id")
                  .setAccountManagement(AccountManagement.newBuilder().build())
                  .build();
          // This part is optional. You can also omit this and link the account later.
          AddAccountService productsManagementService =
              AddAccountService.newBuilder()
                  .setProvider("accounts/" + providerId)
                  .setExternalAccountId("external_account_id")
                  .setProductsManagement(ProductsManagement.newBuilder().build())
                  .build();

          // For sub-account creation, use the AccountAggregation service. For an example on how to do
          // this, see the `CreateSubAccount` sample.

          // The user to be added to the new account.
          // This part is optional.
          AddUser user =
              AddUser.newBuilder()
                  .setUserId(userEmail)
                  .setUser(User.newBuilder().addAccessRights(AccessRight.STANDARD).build())
                  .build();

          CreateAndConfigureAccountRequest request =
              CreateAndConfigureAccountRequest.newBuilder()
                  .setAccount(account)
                  .addAllService(List.of(accountManagementService, productsManagementService))
                  .addUser(user)
                  .build();

          System.out.println("Sending Create and Configure Account request:");
          Account response = accountsServiceClient.createAndConfigureAccount(request);

          System.out.println("Created Account below");
          System.out.println(response);
        } catch (Exception e) {
          System.out.println(e);
        }
      }

      public static void main(String[] args) throws Exception {
        // This is the provider ID of the e-commerce platform.
        long providerId = 123L;
        // This is the name of the new account to be created.
        String newAccountName = "MyNewShop";
        // This is the email of a user to be added to the new account.
        String userEmail = "test-user@gmail.com";
        createAndConfigureAccount(providerId, newAccountName, userEmail);
      }
    }

After creating such an account, you need to onboard it by performing steps such
as
[accepting Terms of Service](https://developers.google.com/merchant/api/guides/accounts/manage-tos-agreements),
[setting up business information](https://support.google.com/merchants/answer/14286818),
and [verifying website](https://support.google.com/merchants/answer/11586344).

### Suppress email verification during account creation

When creating an account with `accounts.createAndConfigure`, you can optionally
suppress verification emails for new users added using the `user` field by
setting `verificationMailSettings.verificationMailMode` to
`SUPPRESS_VERIFICATION_MAIL` in the request for that user. This is useful if you
intend to verify users on behalf of the merchant immediately after creation
using the
[`users.verifySelf`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts.users.me/verifySelf)
method. By default, `verificationMailMode` is `SEND_VERIFICATION_MAIL`, and
verification emails are sent to new users added during account creation.

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

If you set `verificationMailMode` to `SUPPRESS_VERIFICATION_MAIL`, you need to
call `users.verifySelf` for each user added during creation to complete
verification. This call must be authenticated as the user being verified
(the user specified in `userId`), for example using an OAuth token from the
user.

### Specify an alias during account creation

You can specify an alias for an account in the context of a provider in
`CreateAndConfigureAccountRequest` using the `setAlias` field. The alias can be
used to identify the account in your system. If you are a service provider, you
can use the alias to retrieve the account using
`GET /accounts/v1/accounts/{provider}~{alias}`. The alias must be unique for a
given provider, and you must specify a service with the same provider in the
`service` field of the request. For more information on alias requirements,
see [Manage account relationships](https://developers.google.com/merchant/api/guides/accounts/relationships#alias).

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

## Recommended onboarding flow

If you are a partner creating an account on behalf of a merchant, we
recommend the following flow:

1. **Create account** : Call `accounts.createAndConfigure` with your partner credentials to create a new account.
   - Set `service` to include `accountManagement` linking to your provider ID.
   - Add the merchant as a user using the `user` field, and set `verificationMailSettings.verificationMailMode` to `SUPPRESS_VERIFICATION_MAIL`.
2. **Verify user** : With credentials from the merchant (for example, using an OAuth token), call [`users.verifySelf`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts.users.me/verifySelf) to change the user state from `PENDING` to `VERIFIED`.
3. **Set business country** : With merchant credentials, set the business country by updating `address.regionCode` using [`accounts.updateBusinessInfo`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts.businessInfo/updateBusinessInfo). This is required before accepting Terms of Service .
4. **Accept Terms of Service** : With merchant credentials, [accept the Terms of Service](https://developers.google.com/merchant/api/guides/accounts/manage-tos-agreements).

This flow allows a merchant to be seamlessly onboarded within your platform
without receiving invitation emails from Google.

## Create a client account (using account aggregation)

Client accounts are distinct Merchant Center accounts linked to your
advanced account using the `accountAggregation` service, allowing for
centralized management while maintaining separate settings, websites, and data
feeds. You can use the Merchant Accounts sub-API to create new client
accounts.

To create client accounts, you must first have an
[advanced account setup](https://support.google.com/merchants/answer/14089347). You
must be an account administrator to convert your Merchant Center account to
an advanced account, and your account must not have any pending
[issues](https://support.google.com/merchants/answer/12153802#account).

To create a new client account, call
[`accounts.createAndConfigure`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/createAndConfigure).
In the request body:

1. Provide the details of the account you want to create in the [`account`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts#Account) field.
2. In the `accountName` field, don't use repeated and unnecessary punctuation, capitalization, underscores, or non-alphanumeric symbols (like "/" or "_"). Avoid business suffixes (like "Inc." or "GmbH"), promotional text, personal information, or inappropriate language. Use a short, clear, and professional name. For more information, see [adding a business name](https://support.google.com/merchants/answer/12159159).
3. Optionally, specify any new authorized users in the [`user`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/createAndConfigure#adduser) field. User access for the account is also inherited from the parent advanced account.
4. In the [`service`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/createAndConfigure#addaccountservice) field, specify `accountAggregation` and set the `provider` to the resource name of your advanced account (for example, `providers/{ADVANCED_ACCOUNT_ID}`). This establishes your advanced account as the aggregator for the new account.

The following is an example request to create a client account named "merchantStore"
linked to the advanced account
`{ADVANCED_ACCOUNT_ID}`:

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

A successful call creates the new client account and links it to your specified
advanced account. The response body will contain the newly created
[`Account`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts#Account) resource.

The following samples demonstrate how to use the
[`accounts.createAndConfigure`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/createAndConfigure) to create
a new client account.

### 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 Account 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());
          return response;
        }
      }

      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


    def get_parent(account_id):
      return f"accounts/{account_id}"


    def create_sub_account(account_id: str) -> 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_id)

      # 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)
        return response
      except RuntimeError as e:
        print(e)
        raise


    if __name__ == "__main__":
      _account_id = configuration.Configuration().read_merchant_info()
      create_sub_account(_account_id)

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

## Retrieve client accounts

To list all client accounts of a given advanced account, use the
[`accounts.listSubaccounts`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/listSubaccounts)
method. Provide the ID of your advanced account in the `provider` field of the
request URL.

The following is a sample request:

    GET https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts

The following is a sample response from a successful call:

    {
    "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"
        }
      ]
    }

> [!NOTE]
> **Note:** The [`accounts.get`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/get) request, when used to retrieve details about a client account, does not include information about the parent advanced account.

The following samples demonstrate how to list all client accounts of your
advanced account.

### 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 ListSubAccountsPagedResponse 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);
          return response;
        }
      }

      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


    def get_parent(account_id):
      return f"accounts/{account_id}"


    def list_sub_accounts(account_id: str):
      """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_id)

      # 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}")
        return response

      except RuntimeError as e:
        print("An error has occured: ")
        print(e)
        raise


    if __name__ == "__main__":
      _account_id = configuration.Configuration().read_merchant_info()
      list_sub_accounts(_account_id)

### cURL

    curl -X GET \
    "https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts" \
    -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \

## Delete a client account

If you no longer need to manage a client account, you can delete it using the
[`accounts.delete`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts/delete)
method.

Executing this method requires [administrator
access](https://developers.google.com/merchant/api/guides/accounts/control-access) to the account being
deleted.

The following is a sample request:

    DELETE https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}

If successful, the response body is an empty JSON object, indicating the
account has been deleted.

The following samples demonstrate how to delete a client account.

### 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, String accountId) 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 account name to identify the account.
        String name =
            AccountName.newBuilder()
                .setAccount(accountId)
                .build()
                .toString();

        // Calls the API.
        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.");
        }
      }

      public static void deleteAccount(Config config) throws Exception {
        deleteAccount(config, config.getAccountId().toString());
      }

      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


    def get_parent(account_id):
      return f"accounts/{account_id}"


    def delete_account(account_id: str):
      """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_id)

      # 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)
        raise


    if __name__ == "__main__":
      _account_id = configuration.Configuration().read_merchant_info()
      delete_account(_account_id)

### cURL

    curl -X DELETE \
    "https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}?force=true" \
    -H "Authorization: Bearer {YOUR_ACCESS_TOKEN}" \

## Accept the Terms of Service

Client accounts inherit the
[Merchant Center Terms of Service (TOS)](https://support.google.com/merchants/answer/160173)
that the parent advanced account signed.

## Update your business information

You can use the Merchant Accounts API to edit the [business
information](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts.businessInfo) for
your client accounts.

- To view an account's business information, call [`accounts.getBusinessInfo`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts.businessInfo/getBusinessInfo).
- To edit an account's business information, call [`accounts.updateBusinessInfo`](https://developers.google.com/merchant/api/reference/rest/accounts_v1/accounts.businessInfo/updateBusinessInfo).