ایجاد حساب ها

شما می‌توانید از Merchant API برای ایجاد حساب‌های مرکز فروش استفاده کنید که می‌توانند با استفاده از accountAggregation ، accountManagement یا comparisonShopping به یک حساب پیشرفته متصل شوند. متد accounts.createAndConfigure به شما امکان می‌دهد یک حساب ایجاد کنید و به صورت اختیاری آن را با کاربران پیکربندی کنید و از طریق سرویس‌ها به حساب‌های دیگر متصل کنید.

این راهنما نحوه استفاده از Merchant API برای ایجاد حساب‌ها با استفاده از سرویس‌هایی مانند accountManagement ، comparisonShopping یا accountAggregation را توضیح می‌دهد. هنگام استفاده از accounts.createAndConfigure ، باید حساب جدید را با مشخص کردن حداقل یکی از accountAggregation ، accountManagement یا comparisonShopping در فیلد service ، به یک ارائه‌دهنده پیوند دهید. می‌توانید accountAggregation و comparisonShopping در یک درخواست مشخص کنید، اما accountManagement نمی‌توان با accountAggregation یا comparisonShopping ترکیب کرد. اگر accountManagement مشخص کنید، باید حداقل یک کاربر را نیز با استفاده از فیلد user یا users به ​​حساب جدید اضافه کنید.

پیش‌نیازها

قبل از اینکه بتوانید با استفاده از Merchant API حساب کاربری ایجاد کنید، بسته به خدماتی که استفاده می‌کنید، مطمئن شوید که شرایط زیر را برآورده می‌کنید:

  • دسترسی مدیر : هنگام پیوند دادن یک حساب جدید با استفاده از accountManagement ، comparisonShopping یا accountAggregation ، باید به حساب ارائه‌دهنده دسترسی مدیر داشته باشید.
  • حساب پیشرفته : اگر از accountAggregation استفاده می‌کنید، حساب ارائه‌دهنده شما باید یک حساب پیشرفته باشد که برای تجمیع حساب پیکربندی شده باشد. اگر ارائه‌دهنده خدمات هستید و نیاز به راه‌اندازی یک حساب پیشرفته دارید، برای کمک در پیکربندی با پشتیبانی تماس بگیرید .

ایجاد حساب کاربری (با استفاده از مدیریت حساب یا خرید مقایسه‌ای)

برای ایجاد یک حساب کاربری جدید، accounts.createAndConfigure را فراخوانی کنید. این رویکرد برای شرکایی که به بازرگانان در مدیریت حساب‌هایشان کمک می‌کنند، توصیه می‌شود، زیرا به بازرگانان اجازه می‌دهد تا کنترل و مالکیت کامل حساب خود را حفظ کنند و در عین حال مجوزهای خاصی را به شرکا اعطا کنند.

در بدنه درخواست:

  1. جزئیات حسابی که می‌خواهید ایجاد کنید را در قسمت account وارد کنید.
  2. اگر از accountManagement استفاده می‌کنید، حداقل یک کاربر را در فیلد user مشخص کنید که به حساب دسترسی داشته باشد.
  3. در فیلد service ، هر سرویسی را که می‌خواهید به این حساب ارائه دهید، مثلاً accountManagement ، مشخص کنید و نام منبع حساب خود را به provider تنظیم کنید (مثلاً providers/ {YOUR_ACCOUNT_ID} ). برای مشاهده فهرستی از سرویس‌های موجود مانند productsManagement یا campaignsManagement به بخش مدیریت روابط حساب مراجعه کنید.

در اینجا یک مثال از درخواست برای ایجاد یک حساب کاربری با نام "merchantStore" و پیوند آن به حساب {YOUR_ACCOUNT_ID} برای مدیریت حساب و محصول آورده شده است:

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

یک فراخوانی موفق، حساب جدید را ایجاد می‌کند و آن را به حساب شما برای سرویس‌های مشخص‌شده پیوند می‌دهد. اگر در حین ایجاد، سرویس‌های accountManagement ، accountAggregation یا comparisonShopping را مشخص کنید، آن‌ها به‌طور خودکار تأیید می‌شوند و وضعیت پیوند ESTABLISHED می‌شود. سایر پیوندهای سرویس ممکن است تا زمان پذیرش توسط حساب ایجادشده در وضعیت PENDING باشند. بدنه پاسخ شامل منبع Account تازه ایجادشده است.

پس از ایجاد چنین حسابی، باید با انجام مراحلی مانند پذیرش شرایط خدمات ، تنظیم اطلاعات کسب و کار و تأیید وب‌سایت ، آن را فعال کنید.

جلوگیری از تایید ایمیل هنگام ایجاد حساب کاربری

هنگام ایجاد یک حساب کاربری با استفاده از accounts.createAndConfigure ، می‌توانید به صورت اختیاری ایمیل‌های تأیید را برای کاربران جدیدی که با استفاده از فیلد user اضافه شده‌اند، با تنظیم verificationMailSettings.verificationMailMode به SUPPRESS_VERIFICATION_MAIL در درخواست برای آن کاربر، غیرفعال کنید. این در صورتی مفید است که قصد دارید کاربران را از طرف فروشنده بلافاصله پس از ایجاد با استفاده از متد users.verifySelf تأیید کنید. به طور پیش‌فرض، verificationMailMode روی SEND_VERIFICATION_MAIL است و ایمیل‌های تأیید برای کاربران جدیدی که هنگام ایجاد حساب اضافه شده‌اند، ارسال می‌شود.

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

اگر verificationMailMode روی SUPPRESS_VERIFICATION_MAIL تنظیم کنید، برای تکمیل تأیید، باید برای هر کاربر اضافه شده در طول ایجاد، users.verifySelf فراخوانی کنید. این فراخوانی باید به عنوان کاربر تأیید شده (کاربری که در userId مشخص شده است) احراز هویت شود، به عنوان مثال با استفاده از یک توکن OAuth از کاربر.

هنگام ایجاد حساب کاربری، یک نام مستعار مشخص کنید

شما می‌توانید با استفاده از فیلد setAlias ، یک نام مستعار برای یک حساب کاربری در چارچوب یک ارائه‌دهنده در CreateAndConfigureAccountRequest تعیین کنید. از این نام مستعار می‌توان برای شناسایی حساب کاربری در سیستم خود استفاده کرد. اگر شما یک ارائه‌دهنده خدمات هستید، می‌توانید از این نام مستعار برای بازیابی حساب کاربری با استفاده از GET /accounts/v1/accounts/{provider}~{alias} استفاده کنید. نام مستعار باید برای یک ارائه‌دهنده خاص منحصر به فرد باشد و شما باید یک سرویس با همان ارائه‌دهنده را در فیلد service درخواست مشخص کنید. برای اطلاعات بیشتر در مورد الزامات نام مستعار، به مدیریت روابط حساب کاربری مراجعه کنید.

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

اگر شما شریکی هستید که از طرف یک تاجر حساب کاربری ایجاد می‌کنید، روند زیر را توصیه می‌کنیم:

  1. ایجاد حساب کاربری : برای ایجاد یک حساب کاربری جدید، accounts.createAndConfigure با اطلاعات کاربری شریک خود فراخوانی کنید.
    • service طوری تنظیم کنید که شامل accountManagement باشد که به شناسه ارائه‌دهنده شما لینک می‌شود.
    • با استفاده از فیلد user ، فروشنده را به عنوان کاربر اضافه کنید و verificationMailSettings.verificationMailMode را روی SUPPRESS_VERIFICATION_MAIL تنظیم کنید.
  2. تأیید کاربر : با استفاده از اعتبارنامه‌های فروشنده (برای مثال، با استفاده از توکن OAuth)، تابع users.verifySelf را فراخوانی کنید تا وضعیت کاربر از PENDING به VERIFIED تغییر یابد.
  3. تنظیم کشور محل کسب و کار : با استفاده از اطلاعات حساب فروشنده، کشور محل کسب و کار را با به‌روزرسانی address.regionCode با استفاده از accounts.updateBusinessInfo تنظیم کنید. این کار قبل از پذیرش شرایط خدمات الزامی است.
  4. پذیرش شرایط خدمات : با استفاده از اعتبارنامه‌های فروشنده، شرایط خدمات را بپذیرید .

این جریان به یک تاجر اجازه می‌دهد تا بدون دریافت ایمیل دعوت از گوگل، به طور یکپارچه در پلتفرم شما ثبت نام کند.

ایجاد حساب کاربری (با استفاده از تجمیع حساب‌ها)

حساب‌های مشتری، حساب‌های مرکز فروشندگان مجزایی هستند که با استفاده از سرویس accountAggregation به حساب پیشرفته شما متصل می‌شوند و امکان مدیریت متمرکز را در عین حفظ تنظیمات، وب‌سایت‌ها و فیدهای داده جداگانه فراهم می‌کنند. می‌توانید از زیر-API حساب‌های فروشندگان برای ایجاد حساب‌های مشتری جدید استفاده کنید.

برای ایجاد حساب‌های کاربری، ابتدا باید یک حساب کاربری پیشرفته راه‌اندازی کنید . برای تبدیل حساب مرکز فروشندگان خود به یک حساب کاربری پیشرفته، باید مدیر حساب باشید و حساب شما نباید هیچ مشکل در حال انتظاری داشته باشد.

برای ایجاد یک حساب کاربری جدید، در بدنه درخواست، تابع accounts.createAndConfigure فراخوانی کنید:

  1. جزئیات حسابی که می‌خواهید ایجاد کنید را در قسمت account وارد کنید.
  2. در صورت تمایل، می‌توانید هر کاربر مجاز جدید را در فیلد user مشخص کنید. دسترسی کاربر برای حساب کاربری نیز از حساب پیشرفته والد به ارث می‌رسد.
  3. در فیلد service ، accountAggregation مشخص کنید و نام منبع حساب پیشرفته خود را به عنوان provider تنظیم کنید (برای مثال، providers/ {ADVANCED_ACCOUNT_ID} ). این کار حساب پیشرفته شما را به عنوان تجمیع‌کننده برای حساب جدید تعیین می‌کند.

در اینجا یک نمونه درخواست برای ایجاد یک حساب کاربری با نام "merchantStore" که به حساب پیشرفته {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}"
    }
  ]
}

یک فراخوانی موفق، حساب کاربری جدید ایجاد کرده و آن را به حساب پیشرفته مشخص شده شما پیوند می‌دهد. بدنه پاسخ شامل منبع Account تازه ایجاد شده خواهد بود.

نمونه‌های زیر نحوه‌ی استفاده از accounts.createAndConfigure برای ایجاد یک حساب کاربری جدید را نشان می‌دهند.

جاوا

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 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 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());
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();

    createSubAccount(config);
  }
}

پی اچ پی

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();

پایتون

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

_ACCOUNT = configuration.Configuration().read_merchant_info()


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


def create_sub_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)

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


if __name__ == "__main__":
  create_sub_account()

حلقه

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

بازیابی حساب‌های مشتریان

برای فهرست کردن تمام حساب‌های کاربری یک حساب پیشرفته‌ی مشخص، از متد accounts.listSubaccounts استفاده کنید. شناسه‌ی حساب پیشرفته‌ی خود را در فیلد provider در URL درخواست وارد کنید.

در اینجا یک نمونه درخواست آمده است:

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

در اینجا نمونه‌ای از پاسخ یک تماس موفق را مشاهده می‌کنید:

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

نمونه‌های زیر نحوه فهرست کردن تمام حساب‌های مشتری حساب پیشرفته شما را نشان می‌دهند.

جاوا

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 void 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);
    } catch (Exception e) {
      System.out.println("An error has occured: ");
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    listSubAccounts(config);
  }
}

پی اچ پی

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();

پایتون

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

_ACCOUNT = configuration.Configuration().read_merchant_info()


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


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

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

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


if __name__ == "__main__":
  list_sub_accounts()

حلقه

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

حذف حساب کاربری مشتری

اگر دیگر نیازی به مدیریت یک حساب کاربری ندارید، می‌توانید آن را با استفاده از متد accounts.delete حذف کنید.

اجرای این روش نیاز به دسترسی ادمین به حساب کاربری که قرار است حذف شود، دارد.

در اینجا یک نمونه درخواست آمده است:

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

در صورت موفقیت، بدنه پاسخ یک شیء JSON خالی است که نشان می‌دهد حساب حذف شده است.

نمونه‌های زیر نحوه حذف یک حساب کاربری مشتری را نشان می‌دهند.

جاوا

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) 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();

    // Gets the account ID from the config file.
    String accountId = config.getAccountId().toString();

    // Creates account name to identify the account.
    String name =
        AccountName.newBuilder()
            .setAccount(accountId)
            .build()
            .toString();

    // Calls the API and catches and prints any network failures/errors.
    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.");
    } catch (Exception e) {
      System.out.println(e);
    }
  }

  public static void main(String[] args) throws Exception {
    Config config = Config.load();
    deleteAccount(config);
  }
}

پی اچ پی

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();

پایتون

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

_ACCOUNT = configuration.Configuration().read_merchant_info()


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


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

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


if __name__ == "__main__":
  delete_account()

حلقه

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

شرایط خدمات را بپذیرید

حساب‌های مشتری ، شرایط خدمات مرکز پذیرندگان (TOS) را که حساب پیشرفته والد امضا کرده است، به ارث می‌برند.

اطلاعات کسب و کار خود را به روز کنید

شما می‌توانید از API حساب‌های تجاری برای ویرایش اطلاعات تجاری حساب‌های مشتری خود استفاده کنید.

  • برای مشاهده اطلاعات تجاری یک حساب، از تابع accounts.getBusinessInfo استفاده کنید.