Anda dapat menggunakan Merchant API untuk membuat akun Merchant Center, yang dapat di
tautkan ke akun lanjutan
menggunakan accountAggregation, accountManagement, atau comparisonShopping. Metode
accounts.createAndConfigure
memungkinkan Anda membuat akun dan secara opsional mengonfigurasinya dengan pengguna serta
menautkannya ke akun lain melalui layanan.
Panduan ini menjelaskan cara menggunakan Merchant API untuk membuat akun menggunakan layanan seperti accountManagement, comparisonShopping, atau accountAggregation. Saat menggunakan accounts.createAndConfigure, Anda harus menautkan akun baru ke penyedia dengan menentukan setidaknya salah satu dari accountAggregation, accountManagement, atau comparisonShopping di kolom service.
Anda dapat menentukan accountAggregation dan comparisonShopping dalam permintaan yang sama, tetapi accountManagement tidak dapat digabungkan dengan accountAggregation atau comparisonShopping.
Jika Anda menentukan accountManagement, Anda juga harus menambahkan setidaknya satu pengguna ke
akun baru menggunakan kolom user atau users.
Prasyarat
Sebelum dapat membuat akun menggunakan Merchant API, pastikan Anda memenuhi persyaratan berikut, bergantung pada layanan yang Anda gunakan:
- Akses administrator: Anda harus memiliki akses administrator ke
akun penyedia saat menautkan akun baru menggunakan
accountManagement,comparisonShopping, atauaccountAggregation. - Akun lanjutan: Jika Anda menggunakan
accountAggregation, akun penyedia Anda harus berupa akun lanjutan yang dikonfigurasi untuk agregasi akun. Jika Anda adalah penyedia layanan dan perlu menyiapkan akun lanjutan, hubungi dukungan untuk mendapatkan bantuan terkait konfigurasi.
Membuat akun (menggunakan pengelolaan akun atau perbandingan harga)
Untuk membuat akun baru, panggil
accounts.createAndConfigure.
Ini adalah pendekatan yang direkomendasikan untuk partner yang membantu penjual mengelola akun mereka, karena memungkinkan penjual mempertahankan kontrol dan kepemilikan penuh atas akun mereka sekaligus memberikan izin tertentu kepada partner.
Di isi permintaan:
- Berikan detail akun yang ingin Anda buat di
accountkolom. - Di kolom
accountName, jangan gunakan tanda baca yang berulang dan tidak perlu, huruf besar, garis bawah, semua huruf besar, emoji, atau simbol non-alfanumerik seperti/atau_. Hindari akhiran bisnis (seperti "Inc." atau "GmbH"), teks promosi, informasi pribadi, atau bahasa yang tidak pantas. Gunakan nama yang singkat, jelas, dan profesional. Untuk mengetahui informasi selengkapnya, lihat menambahkan nama bisnis. - Jika Anda menggunakan
accountManagement, tentukan setidaknya satu pengguna di kolomuseryang akan memiliki akses ke akun tersebut. - Di kolom
service, tentukan layanan apa pun yang ingin Anda berikan ke akun ini, misalnyaaccountManagement, dan tetapkanproviderke nama resource akun Anda (misalnya,providers/{YOUR_ACCOUNT_ID}). Untuk mengetahui daftar layanan yang tersedia sepertiproductsManagementataucampaignsManagement, lihat Mengelola hubungan akun.
Berikut adalah contoh permintaan untuk membuat akun bernama "merchantStore" dan menautkannya ke akun {YOUR_ACCOUNT_ID} untuk pengelolaan akun dan produk:
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}"
}
]
}
Panggilan yang berhasil akan membuat akun baru dan menautkannya ke akun Anda untuk layanan yang ditentukan. Jika Anda menentukan layanan accountManagement, accountAggregation, atau comparisonShopping selama pembuatan, layanan tersebut akan otomatis disetujui dan status tautan adalah ESTABLISHED. Tautan layanan lainnya mungkin dalam status PENDING hingga diterima oleh akun yang dibuat. Isi respons
berisi resource
Account yang baru dibuat.
Setelah membuat akun tersebut, Anda harus mengaktifkannya dengan melakukan langkah-langkah seperti menyetujui Persyaratan Layanan, menyiapkan informasi bisnis, dan memverifikasi situs.
Menonaktifkan verifikasi email selama pembuatan akun
Saat membuat akun dengan accounts.createAndConfigure, Anda dapat secara opsional menonaktifkan email verifikasi untuk pengguna baru yang ditambahkan menggunakan kolom user dengan menetapkan verificationMailSettings.verificationMailMode ke SUPPRESS_VERIFICATION_MAIL dalam permintaan untuk pengguna tersebut. Hal ini berguna jika Anda
ingin memverifikasi pengguna atas nama penjual segera setelah pembuatan
menggunakan metode
users.verifySelf. Secara default, verificationMailMode adalah SEND_VERIFICATION_MAIL, dan email verifikasi akan dikirim ke pengguna baru yang ditambahkan selama pembuatan akun.
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}"
}
]
}
Jika Anda menetapkan verificationMailMode ke SUPPRESS_VERIFICATION_MAIL, Anda harus memanggil users.verifySelf untuk setiap pengguna yang ditambahkan selama pembuatan untuk menyelesaikan verifikasi. Panggilan ini harus diautentikasi sebagai pengguna yang diverifikasi (pengguna yang ditentukan di userId), misalnya menggunakan token OAuth dari pengguna.
Menentukan alias selama pembuatan akun
Anda dapat menentukan alias untuk akun dalam konteks penyedia di CreateAndConfigureAccountRequest menggunakan kolom setAlias. Alias dapat digunakan untuk mengidentifikasi akun di sistem Anda. Jika Anda adalah penyedia layanan, Anda dapat menggunakan alias untuk mengambil akun menggunakan GET /accounts/v1/accounts/{provider}~{alias}. Alias harus unik untuk penyedia tertentu, dan Anda harus menentukan layanan dengan penyedia yang sama di kolom service permintaan. Untuk mengetahui informasi selengkapnya tentang persyaratan alias,
lihat Mengelola hubungan akun.
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"
}
]
}
Alur orientasi yang direkomendasikan
Jika Anda adalah partner yang membuat akun atas nama penjual, sebaiknya ikuti alur berikut:
- Buat akun: Panggil
accounts.createAndConfiguredengan kredensial partner Anda untuk membuat akun baru.- Tetapkan
serviceuntuk menyertakanaccountManagementyang ditautkan ke ID penyedia Anda. - Tambahkan penjual sebagai pengguna menggunakan kolom
user, dan tetapkanverificationMailSettings.verificationMailModekeSUPPRESS_VERIFICATION_MAIL.
- Tetapkan
- Verifikasi pengguna: Dengan kredensial dari penjual (misalnya, menggunakan
token OAuth), panggil
users.verifySelfuntuk mengubah status pengguna dariPENDINGmenjadiVERIFIED. - Tetapkan negara bisnis: Dengan kredensial penjual, tetapkan negara
bisnis dengan memperbarui
address.regionCodemenggunakanaccounts.updateBusinessInfo. Hal ini diperlukan sebelum menyetujui Persyaratan Layanan. - Setujui Persyaratan Layanan: Dengan kredensial penjual, setujui Persyaratan Layanan.
Alur ini memungkinkan penjual diaktifkan dengan lancar dalam platform Anda tanpa menerima email undangan dari Google.
Membuat akun klien (menggunakan agregasi akun)
Akun klien adalah akun Merchant Center terpisah yang ditautkan ke akun lanjutan Anda menggunakan layanan accountAggregation, sehingga memungkinkan pengelolaan terpusat sekaligus mempertahankan setelan, situs, dan feed data yang terpisah.
Anda dapat menggunakan sub-API Akun Merchant Center untuk membuat akun klien baru.
Untuk membuat akun klien, Anda harus menyiapkan akun lanjutan terlebih dahulu. Anda harus menjadi administrator akun untuk mengonversi akun Merchant Center menjadi akun lanjutan, dan akun Anda tidak boleh memiliki masalah tertunda.
Untuk membuat akun klien baru, panggil
accounts.createAndConfigure.
Di isi permintaan:
- Berikan detail akun yang ingin Anda buat di
accountkolom. - Di kolom
accountName, jangan gunakan tanda baca, huruf besar, garis bawah, atau simbol non-alfanumerik yang berulang dan tidak perlu (seperti "/" atau "_"). Hindari akhiran bisnis (seperti "Inc." atau "GmbH"), teks promosi, informasi pribadi, atau bahasa yang tidak pantas. Gunakan nama yang singkat, jelas, dan profesional. Untuk mengetahui informasi selengkapnya, lihat menambahkan nama bisnis. - Secara opsional, tentukan pengguna baru yang diberi otorisasi di kolom
user. Akses pengguna untuk akun juga diwarisi dari akun lanjutan induk. - Di
servicekolom, tentukanaccountAggregationdan tetapkanproviderke nama resource akun lanjutan Anda (misalnya,providers/{ADVANCED_ACCOUNT_ID}). Hal ini menetapkan akun lanjutan Anda sebagai agregator untuk akun baru.
Berikut adalah contoh permintaan untuk membuat akun klien bernama "merchantStore" yang ditautkan ke akun lanjutan {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}"
}
]
}
Panggilan yang berhasil akan membuat akun klien baru dan menautkannya ke akun lanjutan yang Anda tentukan. Isi respons akan berisi resource yang baru dibuat
Account.
Contoh berikut menunjukkan cara menggunakan
accounts.createAndConfigure untuk membuat
akun klien baru.
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}"
}
]
}'
Mengambil akun klien
Untuk mencantumkan semua akun klien dari akun lanjutan tertentu, gunakan
accounts.listSubaccounts
metode. Berikan ID akun lanjutan Anda di kolom provider URL permintaan.
Berikut adalah contoh permintaan:
GET https://merchantapi.googleapis.com/accounts/v1/accounts/{ADVANCED_ACCOUNT_ID}:listSubaccounts
Berikut adalah contoh respons dari panggilan yang berhasil:
{
"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"
}
]
}
Contoh berikut menunjukkan cara mencantumkan semua akun klien dari akun lanjutan Anda.
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}" \
Menghapus akun klien
Jika tidak lagi perlu mengelola akun klien, Anda dapat menghapusnya menggunakan metode
accounts.delete.
Untuk menjalankan metode ini, Anda memerlukan administrator akses ke akun yang akan dihapus.
Berikut adalah contoh permintaan:
DELETE https://merchantapi.googleapis.com/accounts/v1/accounts/{SUB_ACCOUNT_ID}
Jika berhasil, isi respons akan berupa objek JSON kosong, yang menunjukkan bahwa akun telah dihapus.
Contoh berikut menunjukkan cara menghapus akun klien.
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}" \
Menyetujui Persyaratan Layanan
Akun klien mewarisi Persyaratan Layanan (TOS) Merchant Center yang ditandatangani oleh akun lanjutan induk.
Memperbarui informasi bisnis Anda
Anda dapat menggunakan sub-API Akun untuk mengedit informasi bisnis untuk akun klien Anda.
- Untuk melihat informasi bisnis akun, panggil
accounts.getBusinessInfo. - Untuk mengedit informasi bisnis akun, panggil
accounts.updateBusinessInfo.