Merchant API का इस्तेमाल करके, Merchant Center खाते बनाए जा सकते हैं. इन्हें accountAggregation, accountManagement या comparisonShopping का इस्तेमाल करके, किसी ऐडवांस खाते से लिंक किया जा सकता है. accounts.createAndConfigure तरीके का इस्तेमाल करके, खाता बनाया जा सकता है. साथ ही, उपयोगकर्ताओं के साथ इसे कॉन्फ़िगर किया जा सकता है और सेवाओं के ज़रिए इसे अन्य खातों से लिंक किया जा सकता है. हालांकि, ऐसा करना ज़रूरी नहीं है.
इस गाइड में, accountAggregation, accountManagement या comparisonShopping का इस्तेमाल करके खाते बनाने के लिए, Merchant API को इस्तेमाल करने का तरीका बताया गया है:
accountAggregation: इसका इस्तेमाल मार्केटप्लेस, कई ब्रैंड के खुदरा दुकानदार, अंतरराष्ट्रीय खुदरा दुकानदार, और पार्टनर करते हैं. ये एक से ज़्यादा क्लाइंट वाले ऐडवांस खाते के तहत उप-खाते बनाते हैं.accountManagement: इसका इस्तेमाल ऐसी एजेंसियां करती हैं जो कारोबारी या कंपनी के मालिकाना हक वाले स्टैंडअलोन खाते बनाती हैं.comparisonShopping: इसका इस्तेमाल, ईईए और सीएसएस की सुविधा वाले देशों में खाते बनाने वाली कंपैरिज़न शॉपिंग सर्विस (सीएसएस) करती हैं.
accounts.createAndConfigure का इस्तेमाल करते समय, आपको नए खाते को किसी प्रोवाइडर से लिंक करना होगा. इसके लिए, service फ़ील्ड में accountAggregation, accountManagement या comparisonShopping में से कम से कम एक वैल्यू डालें. एक ही अनुरोध में accountAggregation और comparisonShopping को तय किया जा सकता है. हालांकि, accountManagement को accountAggregation या comparisonShopping के साथ नहीं जोड़ा जा सकता. अगर आपने accountManagement की वैल्यू दी है, तो user या users फ़ील्ड का इस्तेमाल करके, नए खाते में कम से कम एक उपयोगकर्ता जोड़ें.
ज़रूरी शर्तें
Merchant API का इस्तेमाल करके खाते बनाने से पहले, पक्का करें कि आपने इस्तेमाल की जाने वाली सेवाओं के हिसाब से, ये ज़रूरी शर्तें पूरी की हों:
- एडमिन ऐक्सेस:
accountManagement,comparisonShoppingयाaccountAggregationका इस्तेमाल करके नया खाता लिंक करते समय, आपके पास सेवा देने वाली कंपनी के खाते का एडमिन ऐक्सेस होना चाहिए. - ऐडवांस खाता: अगर
accountAggregationका इस्तेमाल किया जाता है, तो आपके प्रोवाइडर का खाता, ऐडवांस खाता होना चाहिए. साथ ही, इसे खाते को एग्रीगेट करने के लिए कॉन्फ़िगर किया गया हो. अगर आप सेवा देने वाली कंपनी हैं और आपको ऐडवांस खाता सेट अप करना है, तो कॉन्फ़िगरेशन में मदद पाने के लिए सहायता टीम से संपर्क करें.
खाता बनाना (खाता मैनेजमेंट या कंपैरिज़न शॉपिंग का इस्तेमाल करके)
नया खाता बनाने के लिए,
accounts.createAndConfigure पर कॉल करें.
यह तरीका उन पार्टनर के लिए सुझाया जाता है जो कारोबारियों या कंपनियों को उनके खाते मैनेज करने में मदद करते हैं. इससे कारोबारियों या कंपनियों को अपने खाते पर पूरा कंट्रोल और मालिकाना हक बनाए रखने में मदद मिलती है. साथ ही, वे पार्टनर को कुछ खास अनुमतियां दे पाते हैं.
अनुरोध के मुख्य हिस्से में:
accountफ़ील्ड में, उस खाते की जानकारी दें जिसे आपको बनाना है.accountNameफ़ील्ड में, विराम चिह्न, कैपिटल लेटर (अंग्रेज़ी के बड़े अक्षरों) के इस्तेमाल, अंडरस्कोर, अंग्रेज़ी के बड़े अक्षरों, इमोजी या/या_जैसे गैर-ऐल्फ़ान्यूमेरिक सिंबल को दोहराने और उनके ग़ैर-ज़रूरी इस्तेमाल से बचें. कारोबार के सफ़िक्स (जैसे, "Inc." या "GmbH"), प्रमोशन वाला टेक्स्ट, निजी जानकारी या आपत्तिजनक भाषा का इस्तेमाल करने से बचें. छोटे, साफ़, और पेशेवर नाम का इस्तेमाल करें. ज़्यादा जानकारी के लिए, कारोबार का नाम जोड़ना लेख पढ़ें.- अगर
accountManagementका इस्तेमाल किया जा रहा है, तोuserफ़ील्ड में कम से कम एक ऐसे उपयोगकर्ता की जानकारी दें जिसके पास खाते का ऐक्सेस होगा. 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
का इस्तेमाल करने का तरीका बताया गया है:
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);
}
}
ऐसा खाता बनाने के बाद, आपको उसे इस्तेमाल करने के लिए कुछ ज़रूरी काम करने होंगे. जैसे, सेवा की शर्तें स्वीकार करना , कारोबार की जानकारी सेट अप करना, और वेबसाइट की पुष्टि करना.
खाता बनाते समय, ईमेल पते की पुष्टि करने की प्रोसेस को रोकना
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 टोकन का इस्तेमाल करके.
खाता बनाते समय कोई दूसरा नाम तय करना
CreateAndConfigureAccountRequest में, setAlias फ़ील्ड का इस्तेमाल करके, किसी सेवा देने वाली कंपनी के लिए, खाते का कोई दूसरा नाम तय किया जा सकता है. उपनाम का इस्तेमाल, आपके सिस्टम में खाते की पहचान करने के लिए किया जा सकता है. अगर आप सेवा देने वाले व्यक्ति या कंपनी हैं, तो 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"
}
]
}
शामिल होने के लिए सुझाई गई प्रोसेस
अगर आप किसी कारोबारी या कंपनी की ओर से खाता बनाने वाले पार्टनर हैं, तो हमारा सुझाव है कि आप यह तरीका अपनाएं:
- खाता बनाना: नया खाता बनाने के लिए, अपने पार्टनर क्रेडेंशियल के साथ
accounts.createAndConfigureको कॉल करें.serviceको सेट करें, ताकिaccountManagementको आपके प्रोवाइडर आईडी से लिंक किया जा सके.userफ़ील्ड का इस्तेमाल करके, कारोबारी या कंपनी को उपयोगकर्ता के तौर पर जोड़ें. साथ ही,verificationMailSettings.verificationMailModeकोSUPPRESS_VERIFICATION_MAILपर सेट करें.
- उपयोगकर्ता की पुष्टि करना: कारोबारी या कंपनी से मिले क्रेडेंशियल (उदाहरण के लिए, OAuth टोकन का इस्तेमाल करके) की मदद से,
users.verifySelfको कॉल करें, ताकि उपयोगकर्ता की स्थिति कोPENDINGसे बदलकरVERIFIEDकिया जा सके. - कारोबार का देश सेट करें: कारोबारी या कंपनी के क्रेडेंशियल का इस्तेमाल करके, कारोबार का देश सेट करें. इसके लिए,
accounts.updateBusinessInfoका इस्तेमाल करकेaddress.regionCodeको अपडेट करें. सेवा की शर्तें स्वीकार करने से पहले, यह ज़रूरी है . - सेवा की शर्तें स्वीकार करें : कारोबारी या कंपनी के क्रेडेंशियल का इस्तेमाल करके, सेवा की शर्तें स्वीकार करें .
इस फ़्लो की मदद से, किसी कारोबारी या कंपनी को आपके प्लैटफ़ॉर्म पर आसानी से शामिल किया जा सकता है. इसके लिए, Google से न्योते के ईमेल पाने की ज़रूरत नहीं होती.
क्लाइंट खाता बनाना (खाते को एग्रीगेट करने की सुविधा का इस्तेमाल करके)
क्लाइंट खाते, आपके ऐडवांस खाते से लिंक किए गए अलग-अलग Merchant Center खाते होते हैं. इन्हें accountAggregation सेवा का इस्तेमाल करके लिंक किया जाता है. इससे आपको अलग-अलग सेटिंग, वेबसाइटों, और डेटा फ़ीड को बनाए रखते हुए, उन्हें एक ही जगह से मैनेज करने की सुविधा मिलती है. नए क्लाइंट खाते बनाने के लिए, Merchant Accounts sub-API का इस्तेमाल किया जा सकता है.
क्लाइंट खाते बनाने के लिए, आपके पास पहले से ऐडवांस खाते का सेटअप होना चाहिए. अपने Merchant Center खाते को ऐडवांस खाते में बदलने के लिए, यह ज़रूरी है कि आप खाते के एडमिन हों. साथ ही, आपके खाते में कोई समस्या बाकी न हो.
नया क्लाइंट खाता बनाने के लिए,
accounts.createAndConfigure को कॉल करें.
अनुरोध के मुख्य हिस्से में:
accountफ़ील्ड में, उस खाते की जानकारी दें जिसे आपको बनाना है.accountNameफ़ील्ड में, विराम चिह्न, कैपिटल लेटर (अंग्रेज़ी के बड़े अक्षरों) के इस्तेमाल, अंडरस्कोर या गैर-ऐल्फ़ान्यूमेरिक सिंबल (जैसे, "/" या "_") को दोहराने और उनके ग़ैर-ज़रूरी इस्तेमाल से बचें. कारोबार के सफ़िक्स (जैसे, "Inc." या "GmbH"), प्रमोशन वाला टेक्स्ट, निजी जानकारी या आपत्तिजनक भाषा का इस्तेमाल करने से बचें. छोटा, साफ़, और पेशेवर नाम इस्तेमाल करें. ज़्यादा जानकारी के लिए, कारोबार का नाम जोड़ना लेख पढ़ें.- इसके अलावा,
userफ़ील्ड में, अनुमति वाले किसी नए उपयोगकर्ता की जानकारी दें. खाते के लिए उपयोगकर्ता ऐक्सेस, पैरंट ऐडवांस खाते से भी इनहेरिट किया जाता है. serviceफ़ील्ड में,accountAggregationडालें औरproviderको अपने ऐडवांस खाते के संसाधन के नाम पर सेट करें. उदाहरण के लिए,providers/{ADVANCED_ACCOUNT_ID}. इससे आपका ऐडवांस खाता, नए खाते के लिए एग्रीगेटर के तौर पर सेट हो जाता है.
यहां ऐडवांस खाते {ADVANCED_ACCOUNT_ID} से लिंक किया गया "merchantStore" नाम का क्लाइंट खाता बनाने के लिए, अनुरोध का एक उदाहरण दिया गया है:
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 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}"
}
]
}'
क्लाइंट खातों की जानकारी पाना
किसी ऐडवांस खाते के सभी क्लाइंट खातों की सूची देखने के लिए, 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 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}" \
क्लाइंट खाता मिटाना
अगर आपको अब किसी क्लाइंट खाते को मैनेज करने की ज़रूरत नहीं है, तो उसे मिटाया जा सकता है. इसके लिए,
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, 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}" \
सेवा की शर्तें स्वीकार करें
क्लाइंट खातों पर, Merchant Center की सेवा की शर्तें (टीओएस) लागू होती हैं. ये शर्तें, पैरंट ऐडवांस खाते के लिए स्वीकार की गई शर्तों के मुताबिक होती हैं.
अपने कारोबार की जानकारी अपडेट करना
Merchant Accounts API का इस्तेमाल करके, अपने क्लाइंट खातों के लिए कारोबार की जानकारी में बदलाव किया जा सकता है.
- किसी खाते के कारोबार की जानकारी देखने के लिए,
accounts.getBusinessInfoपर कॉल करें. - किसी खाते में मौजूद कारोबार की जानकारी में बदलाव करने के लिए,
accounts.updateBusinessInfoपर कॉल करें.