खाते बनाएं

Merchant Center खाते बनाने के लिए, Merchant API का इस्तेमाल किया जा सकता है. इन खातों को ऐडवांस खाते से लिंक किया जा सकता है. इसके लिए, accountAggregation, accountManagement या comparisonShopping का इस्तेमाल किया जा सकता है. The accounts.createAndConfigure तरीके से, खाता बनाया जा सकता है. साथ ही, इस तरीके का इस्तेमाल करके, खाते को उपयोगकर्ताओं के साथ कॉन्फ़िगर किया जा सकता है और सेवाओं के ज़रिए इसे अन्य खातों से लिंक किया जा सकता है.

इस गाइड में, Merchant API का इस्तेमाल करके खाते बनाने का तरीका बताया गया है. इसके लिए, accountManagement, comparisonShopping या accountAggregation जैसी सेवाओं का इस्तेमाल किया जा सकता है. accounts.createAndConfigure का इस्तेमाल करते समय, नए खाते को किसी सेवा देने वाली कंपनी से लिंक करना ज़रूरी है. इसके लिए, service फ़ील्ड में, accountAggregation, accountManagement या comparisonShopping में से कम से कम एक सेवा की जानकारी दें. एक ही अनुरोध में, accountAggregation और comparisonShopping की जानकारी दी जा सकती है. हालांकि, accountManagement को accountAggregation या comparisonShopping के साथ इस्तेमाल नहीं किया जा सकता. अगर accountManagement की जानकारी दी जाती है, तो नए खाते में कम से कम एक उपयोगकर्ता को user या users फ़ील्ड का इस्तेमाल करके जोड़ना ज़रूरी है.

ज़रूरी शर्तें

Merchant API का इस्तेमाल करके खाते बनाने से पहले, पक्का करें कि आपने इस्तेमाल की जा रही सेवाओं के हिसाब से, ये ज़रूरी शर्तें पूरी कर ली हों:

  • एडमिन का ऐक्सेस: सेवा देने वाली कंपनी के खाते का एडमिन ऐक्सेस आपके पास तब होना चाहिए, जब आप accountManagement, comparisonShopping या accountAggregation का इस्तेमाल करके कोई नया खाता लिंक कर रहे हों.
  • ऐडवांस खाता: अगर accountAggregation का इस्तेमाल किया जाता है, तो सेवा देने वाली कंपनी का खाता ऐडवांस खाता होना चाहिए. साथ ही, इसे खाता एग्रीगेशन के लिए कॉन्फ़िगर किया गया हो. अगर आप सेवा देने वाली कंपनी हैं और आपको ऐडवांस खाता सेट अप करना है, कॉन्फ़िगरेशन में मदद पाने के लिए, सहायता टीम से संपर्क करें.

खाता बनाना (खाता मैनेजमेंट या तुलना वाली शॉपिंग का इस्तेमाल करके)

नया खाता बनाने के लिए, कॉल करें accounts.createAndConfigure. हमारा सुझाव है कि पार्टनर, व्यापारियों के खातों को मैनेज करने में मदद करने के लिए, इस तरीके का इस्तेमाल करें. ऐसा इसलिए, क्योंकि इससे व्यापारियों को अपने खाते पर पूरा कंट्रोल और मालिकाना हक बनाए रखने में मदद मिलती है. साथ ही, पार्टनर को खास अनुमतियां दी जा सकती हैं.

अनुरोध के मुख्य हिस्से में:

  1. account फ़ील्ड में, उस खाते की जानकारी दें जिसे आपको बनाना है.
  2. accountName फ़ील्ड में, बार-बार इस्तेमाल किए गए और गैर-ज़रूरी विराम चिह्न, कैपिटल लेटर, अंडरस्कोर, सभी कैपिटल लेटर, इमोजी या गैर-अल्फ़ान्यूमेरिक सिंबल (जैसे, / या _) का इस्तेमाल न करें. कारोबार के सफ़िक्स (जैसे, "Inc." या "GmbH"), प्रमोशन से जुड़े टेक्स्ट, निजी जानकारी या आपत्तिजनक भाषा का इस्तेमाल न करें. छोटा, साफ़, और पेशेवर नाम इस्तेमाल करें. ज़्यादा जानकारी के लिए, कारोबार का नाम जोड़ना देखें.
  3. अगर accountManagement का इस्तेमाल किया जा रहा है, तो user फ़ील्ड में कम से कम एक ऐसे उपयोगकर्ता की जानकारी दें जिसके पास खाते का ऐक्सेस होगा.
  4. 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. सेवा की शर्तें स्वीकार करना: व्यापारी के क्रेडेंशियल के साथ, सेवा की शर्तें स्वीकार करें.

इस फ़्लो की मदद से, व्यापारी को आपके प्लैटफ़ॉर्म पर आसानी से ऑनबोर्ड किया जा सकता है. साथ ही, उसे Google से न्योते वाले ईमेल नहीं मिलेंगे.

क्लाइंट खाता बनाना (खाता एग्रीगेशन का इस्तेमाल करके)

क्लाइंट खाते, अलग-अलग Merchant Center खाते होते हैं. इन्हें accountAggregation सेवा का इस्तेमाल करके, आपके ऐडवांस खाते से लिंक किया जाता है. इससे, इन खातों को एक जगह से मैनेज किया जा सकता है. साथ ही, इनकी अलग-अलग सेटिंग, वेबसाइटें, और डेटा फ़ीड बनाए रखे जा सकते हैं. नए क्लाइंट खाते बनाने के लिए, Merchant Center खातों के सब-एपीआई का इस्तेमाल किया जा सकता है.

क्लाइंट खाते बनाने के लिए, आपके पास पहले से ही एक ऐडवांस खाता सेट अप होना चाहिए. अपने Merchant Center खाते को ऐडवांस खाते में बदलने के लिए, आपको खाते का एडमिन होना चाहिए. साथ ही, आपके खाते में कोई भी समस्या पेंडिंग नहीं होनी चाहिए.

नया क्लाइंट खाता बनाने के लिए, कॉल करें accounts.createAndConfigure. अनुरोध के मुख्य हिस्से में:

  1. account फ़ील्ड में, उस खाते की जानकारी दें जिसे आपको बनाना है.
  2. accountName फ़ील्ड में, बार-बार इस्तेमाल किए गए और गैर-ज़रूरी विराम चिह्न, कैपिटल लेटर, अंडरस्कोर या गैर-अल्फ़ान्यूमेरिक सिंबल (जैसे, "/" या "_") का इस्तेमाल न करें. कारोबार के सफ़िक्स (जैसे, "Inc." या "GmbH"), प्रमोशन से जुड़े टेक्स्ट, निजी जानकारी या आपत्तिजनक भाषा का इस्तेमाल न करें. छोटा, साफ़, और पेशेवर नाम इस्तेमाल करें. ज़्यादा जानकारी के लिए, कारोबार का नाम जोड़ना देखें.
  3. ज़रूरी नहीं: user फ़ील्ड में, अनुमति वाले नए उपयोगकर्ताओं की जानकारी दें. खाते के लिए उपयोगकर्ता का ऐक्सेस, पैरंट ऐडवांस खाते से भी इनहेरिट किया जाता है.
  4. 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 का इस्तेमाल कैसे किया जा सकता है.

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

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

_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

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 फ़ील्ड में, अपने ऐडवांस खाते का आईडी डालें.

अनुरोध का एक उदाहरण यहां दिया गया है:

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

यहां दिए गए उदाहरणों से पता चलता है कि अपने ऐडवांस खाते के सभी क्लाइंट खातों की सूची कैसे पाई जा सकती है.

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

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

_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

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 ऑब्जेक्ट दिखेगा. इससे पता चलता है कि खाता मिटा दिया गया है.

यहां दिए गए उदाहरणों से पता चलता है कि क्लाइंट खाता कैसे मिटाया जा सकता है.

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

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

_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

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

सेवा की शर्तें स्वीकार करना

क्लाइंट खाते, Merchant Center की सेवा की शर्तों (टीओएस) को इनहेरिट करते हैं. इन शर्तों पर, पैरंट ऐडवांस खाते ने हस्ताक्षर किए होते हैं.

अपने कारोबार की जानकारी अपडेट करना

अपने क्लाइंट खातों के लिए, कारोबार की जानकारी में बदलाव करने के लिए, खातों के सब-एपीआई का इस्तेमाल किया जा सकता है.

  • किसी खाते की कारोबार की जानकारी देखने के लिए, कॉल करें accounts.getBusinessInfo.
  • किसी खाते की कारोबार की जानकारी में बदलाव करने के लिए, accounts.updateBusinessInfo को कॉल करें.