يمكنك استخدام Merchant API لإنشاء حسابات على Merchant Center، والتي يمكن ربطها بحساب بامتيازات متقدّمة باستخدام 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.
هذا هو النهج المقترَح للشركاء الذين يساعدون التجّار في إدارة حساباتهم، لأنّه يسمح للتجّار بالاحتفاظ بالتحكّم الكامل في حساباتهم وملكيّتها مع منح أذونات محدّدة للشركاء.
في نص الطلب:
- قدِّم تفاصيل الحساب الذي تريد إنشاءه في الحقل
account. - في الحقل
accountName، لا تستخدم علامات الترقيم أو الأحرف اللاتينية الكبيرة أو الشرطات السفلية أو كل الأحرف اللاتينية الكبيرة أو الرموز التعبيرية أو الرموز غير الأبجدية الرقمية، مثل/أو_، بشكل متكرّر وإذا كانت غير ضرورية. تجنَّب استخدام لاحقات المؤسسة (مثل "ذ.م.م" أو "ش.ذ.م.م") أو النصوص الترويجية أو المعلومات الشخصية أو اللغة غير الملائمة. استخدِم اسمًا قصيرًا وواضحًا واحترافيًا. لمزيد من المعلومات، يُرجى الاطّلاع على إضافة اسم مؤسسة. - إذا كنت تستخدم
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، يمكنك اختياريًا إيقاف رسائل إثبات الملكية الإلكترونية للمستخدمين الجدد الذين تمت إضافتهم باستخدام الحقل 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. - ضبط بلد المؤسسة: باستخدام بيانات اعتماد التاجر، اضبط بلد
المؤسسة من خلال تعديل
address.regionCodeباستخدامaccounts.updateBusinessInfo. هذه الخطوة مطلوبة قبل قبول بنود الخدمة . - قبول بنود الخدمة : باستخدام بيانات اعتماد التاجر، اقبل بنود الخدمة .
يسمح هذا السير بإعداد التاجر بسلاسة على منصّتك بدون تلقّي رسائل إلكترونية للدعوة من Google.
إنشاء حساب عميل (باستخدام تجميع الحسابات)
حسابات العملاء هي حسابات منفصلة على Merchant Center مرتبطة بحسابك بامتيازات متقدّمة باستخدام خدمة accountAggregation، ما يسمح بالإدارة المركزية مع الحفاظ على إعدادات ومواقع إلكترونية وخلاصات بيانات منفصلة. يمكنك استخدام واجهة برمجة التطبيقات الفرعية "حسابات التجّار" لإنشاء حسابات عملاء جديدة.
لإنشاء حسابات عملاء، يجب أولاً إعداد حساب بامتيازات متقدّمة . يجب أن تكون مشرف حساب لتحويل حسابك على Merchant Center إلى حساب بامتيازات متقدّمة، ويجب ألا يتضمّن حسابك أي مشاكل معلّقة.
لإنشاء حساب عميل جديد، اتّصِل بـ
accounts.createAndConfigure.
في نص الطلب:
- قدِّم تفاصيل الحساب الذي تريد إنشاءه في الحقل
account. - في الحقل
accountName، لا تستخدم علامات الترقيم أو الأحرف اللاتينية الكبيرة أو الشرطات السفلية أو الرموز غير الأبجدية الرقمية (مثل "/" أو "_") بشكل متكرّر وإذا كانت غير ضرورية. تجنَّب استخدام لاحقات المؤسسة (مثل "ذ.م.م" أو "ش.ذ.م.م") أو النصوص الترويجية أو المعلومات الشخصية أو اللغة غير الملائمة. استخدِم اسمًا قصيرًا وواضحًا واحترافيًا. لمزيد من المعلومات، يُرجى الاطّلاع على إضافة اسم مؤسسة. - يمكنك اختياريًا تحديد أي مستخدمين جدد مخوّلين في الـ
userحقل. يتم أيضًا اكتساب إذن وصول المستخدم إلى الحساب من الحساب الرئيسي بامتيازات متقدّمة. - في الحقل
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);
}
}
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 من عنوان 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);
}
}
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 فارغًا، ما يشير إلى أنّه تم حذف الحساب.
توضّح النماذج التالية كيفية حذف حساب عميل.
جافا
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 (TOS) التي وقّعها الحساب المتقدّم الرئيسي.
تعديل معلومات مؤسستك
يمكنك استخدام Merchant Accounts API لتعديل معلومات المؤسسة لـ حسابات عملائك.
- لعرض معلومات المؤسسة لحساب، اتّصِل بـ
accounts.getBusinessInfo. - لتعديل معلومات المؤسسة لحساب، اتّصِل بـ
accounts.updateBusinessInfo.