accounts.list
तरीके से, आपको Account
संसाधनों की सूची मिलती है. इन संसाधनों को, पुष्टि किया गया उपयोगकर्ता ऐक्सेस कर सकता है. filter
क्वेरी पैरामीटर का इस्तेमाल करके, अलग-अलग शर्तों के आधार पर नतीजों को सीमित किया जा सकता है. जैसे:
- खाते की प्रॉपर्टी
- अन्य खातों के साथ संबंध (जैसे, बेहतर खाता स्ट्रक्चर में सेवा देने वाली कंपनियां)
- खातों से जुड़ी सेवाएं
इससे एक से ज़्यादा खातों को मैनेज करने या कारोबार के ऐसे खास खाते ढूंढने में मदद मिल सकती है जो कुछ शर्तों को पूरा करते हैं.
account
लेवल पर फ़िल्टर करने के लिए, इन फ़ील्ड का इस्तेमाल किया जा सकता है:
access
: इससे यह फ़िल्टर किया जाता है कि उपयोगकर्ता के पासaccount
को ऐक्सेस करने का किस तरह का अधिकार है. इस फ़िल्टर में, ये वैल्यू इस्तेमाल की जा सकती हैं:DIRECT
: सिर्फ़ उन खातों को दिखाता है जिन्हें उपयोगकर्ता सीधे तौर पर ऐक्सेस कर सकता है.INDIRECT
: इससे सिर्फ़ वे खाते दिखते हैं जिनका ऐक्सेस उपयोगकर्ता के पास सीधे तौर पर नहीं है.ALL
: यह उन सभी खातों की जानकारी दिखाता है जिनका ऐक्सेस उपयोगकर्ता के पास है. इनमें डायरेक्ट और इनडायरेक्ट, दोनों तरह के खाते शामिल हैं. अगर फ़िल्टर के बारे में नहीं बताया गया है, तो यह डिफ़ॉल्ट व्यवहार है.
capabilities
:capabilities
रिसॉर्स केcapabilities
के हिसाब से फ़िल्टर करता है (ध्यान दें कि यह फ़ील्ड, रिसॉर्स पर उपलब्ध नहीं है).account
सिर्फ़CAN_UPLOAD_PRODUCTS
सुविधा काम करती है. इस फ़ील्ड में, नेगेशन का इस्तेमाल किया जा सकता है. साथ ही, इसमें कलेक्शन सिंटैक्स का इस्तेमाल किया जाता है.relationship(...)
: इस फ़िल्टर की मदद से, यह देखा जा सकता है कि खाते का किसी दूसरे खाते से किस तरह का संबंध है. एक अनुरोध में, कईrelationship(...)
फ़िल्टर शामिल किए जा सकते हैं.accountName
: यहaccountName
संसाधन केaccount
के हिसाब से फ़िल्टर करता है.
फ़िल्टर के सिंटैक्स के बारे में ज़्यादा जानकारी के लिए, फ़िल्टर का सिंटैक्स गाइड देखें.
उदाहरण
यहां दिए गए उदाहरणों में, सबसे सामान्य क्वेरी बनाने का तरीका बताया गया है. यहां दिए गए सभी उदाहरणों में, accounts.list
तरीके का इस्तेमाल किया गया है. ज़्यादा जानकारी के लिए, accounts.list
रेफ़रंस दस्तावेज़ देखें.
सेवा देने वाली किसी कंपनी के उप-खाते ढूंढना
accounts.listSubaccounts
तरीके से, उप-खातों को सीधे तौर पर लिस्ट किया जा सकता है. यहां दिए गए सेक्शन में बताई गई फ़िल्टर करने की सुविधाओं का भी इस्तेमाल किया जा सकता है. अगर आपके पास किसी ऐडवांस खाते को मैनेज करने का ऐक्सेस है, तो providerId
पर फ़िल्टर करके, उसके सभी उप-खातों की सूची बनाई जा सकती है. PROVIDER_ID
को अपने बेहतर खाते के आईडी से बदलें.
उदाहरण के लिए, अगर सेवा देने वाली कंपनी का आईडी 123
है, तो relationship(providerId=123)
का इस्तेमाल करें.
इससे अपने खातों के स्ट्रक्चर को मैनेज करने में मदद मिलती है.
GET https://merchantapi.googleapis.com/accounts/v1/accounts?filter=relationship(providerId%20%3D%20PROVIDER_ID)
अनुरोध पूरा होने पर, 200 स्टेटस कोड मिलता है. साथ ही, जवाब के मुख्य भाग में मिलते-जुलते उप-खातों की सूची दिखती है:
{
"accounts": [
{
"name": "accounts/77777",
"accountId": "77777",
"accountName": "SubAccount A of Provider",
"adultContent": false,
"languageCode": "fr",
"timeZone": {
"id": "Europe/Paris"
}
},
{
"name": "accounts/88888",
"accountId": "88888",
"accountName": "SubAccount B of Provider",
"adultContent": false,
"languageCode": "de",
"timeZone": {
"id": "Europe/Berlin"
}
}
],
"nextPageToken": "XYZ123abcDEF..."
}
उन खातों को ढूंढें जो प्रॉडक्ट अपलोड नहीं कर सकते
ज़्यादा सटीक खोज के लिए, फ़िल्टर करने की कई शर्तों को एक साथ इस्तेमाल किया जा सकता है.
accountName=*store* AND -capabilities:CAN_UPLOAD_PRODUCTS
फ़िल्टर, उन सभी खातों को ढूंढता है जिनके नाम में "स्टोर" है. साथ ही, उन्हें सीधे तौर पर प्रॉडक्ट अपलोड करने के लिए कॉन्फ़िगर नहीं किया गया है. capabilities
से पहले मौजूद -
, निगेशन ऑपरेटर के तौर पर काम करता है. इसका इस्तेमाल सिर्फ़ ऐडवांस खातों को वापस पाने के लिए किया जा सकता है.
GET https://merchantapi.googleapis.com/accounts/v1/accounts?filter=accountName%20%3D%20%22*store*%22%20AND%20-capabilities%3ACAN_UPLOAD_PRODUCTS
अनुरोध पूरा होने पर, 200 स्टेटस कोड और जवाब की बॉडी मिलती है. इसमें मिलते-जुलते खातों की सूची होती है:
{
"accounts": [
{
"name": "accounts/54321",
"accountId": "54321",
"accountName": "Partner Store - US",
"adultContent": false,
"languageCode": "en",
"timeZone": {
"id": "America/New_York"
}
},
{
"name": "accounts/98765",
"accountId": "98765",
"accountName": "Auxiliary Brand Store",
"adultContent": false,
"languageCode": "fr",
"timeZone": {
"id": "Europe/Paris"
}
}
],
"nextPageToken": "CDEfghIJKlmnOPQ..."
}
नाम के हिसाब से खाते ढूंढना
उन खातों को खोजा जा सकता है जिनके डिसप्ले नेम, किसी खास पैटर्न से मेल खाते हों.
उदाहरण के लिए, accountName=*store*
से उन सभी खातों का पता चलेगा जिनके नाम में "स्टोर" शब्द शामिल है.
इससे किसी खास कारोबार के खातों को तुरंत ढूंढने में मदद मिलती है.
GET https://merchantapi.googleapis.com/accounts/v1/accounts?filter=accountName%20%3D%20%22*store*%22
अनुरोध पूरा होने पर, 200 स्टेटस कोड और जवाब की बॉडी मिलती है. इसमें मिलते-जुलते खातों की सूची होती है:
{
"accounts": [
{
"name": "accounts/12345",
"accountId": "12345",
"accountName": "My Awesome Store",
"adultContent": false,
"languageCode": "en",
"timeZone": {
"id": "America/Los_Angeles"
}
},
{
"name": "accounts/67890",
"accountId": "67890",
"accountName": "Another Store Online",
"adultContent": false,
"languageCode": "en",
"timeZone": {
"id": "Europe/London"
}
}
],
"nextPageToken": "ABSdefGHIjklMNO..."
}
किसी सेवा के लिए, सेवा देने वाली कंपनी से लिंक किए गए खाते ढूंढना
आपको ऐसे खाते मिल सकते हैं जिनका सेवा देने वाली किसी कंपनी के साथ कारोबारी संबंध है.
उदाहरण के लिए, खाता एग्रीगेशन के लिए, PROVIDER_ID
प्रोवाइडर के तहत एग्रीगेट किए गए सभी खातों को ढूंढने के लिए, relationship(providerId=PROVIDER_ID) AND
service(type="ACCOUNT_AGGREGATION")
फ़िल्टर का इस्तेमाल करें.
GET https://merchantapi.googleapis.com/accounts/v1/accounts?filter=relationship(providerId%20%3D%20PROVIDER_ID%20AND%20service(type%20%3D%20%22ACCOUNT_AGGREGATION%22))
अनुरोध पूरा होने पर, 200 स्टेटस कोड और जवाब की बॉडी मिलती है. इसमें मिलते-जुलते खातों की सूची होती है:
{
"accounts": [
{
"name": "accounts/54321",
"accountId": "54321",
"accountName": "Aggregated Account X",
"adultContent": false,
"languageCode": "en",
"timeZone": {
"id": "America/New_York"
}
}
]
}
सेवा से जुड़े संबंध की मंज़ूरी की स्थिति के आधार पर खाते ढूंढना
किसी सेवा देने वाली कंपनी के साथ खाते के संबंध की स्थिति के आधार पर, खातों को फ़िल्टर किया जा सकता है. उदाहरण के लिए, उन सभी खातों को ढूंढने के लिए जिन्होंने (handshakeState = "PENDING")
किसी खास प्रोवाइडर PROVIDER_ID
से मिले खाते को लिंक करने के अनुरोध (handshakeState = "PENDING")
को स्वीकार नहीं किया है.
उदाहरण के लिए, उन खातों को ढूंढने के लिए जहां सेवा देने वाली कंपनी का आईडी 123
है, सेवा का टाइप ACCOUNT_MANAGEMENT
है, और स्थिति PENDING
है, relationship(service(handshakeState = "PENDING" AND type =
"ACCOUNT_MANAGEMENT") AND providerId = 123)
का इस्तेमाल करें.
GET https://merchantapi.googleapis.com/accounts/v1/accounts?filter=relationship(service(handshakeState%20%3D%20%22PENDING%22%20AND%20type%20%3D%20%22ACCOUNT_MANAGEMENT%22)%20AND%20providerId%20%3D%20PROVIDER_ID)
अनुरोध पूरा होने पर, 200 स्टेटस कोड और जवाब की बॉडी मिलती है. इसमें मिलते-जुलते खातों की सूची होती है:
{
"accounts": [
{
"name": "accounts/98765",
"accountId": "98765",
"accountName": "Managed Account Y",
"adultContent": false,
"languageCode": "es",
"timeZone": {
"id": "Europe/Madrid"
}
}
]
}
क्लाइंट लाइब्रेरी का इस्तेमाल करके खातों को फ़िल्टर करना
यहां दिए गए उदाहरणों में, क्लाइंट लाइब्रेरी का इस्तेमाल करके, खातों को फ़िल्टर करने का तरीका बताया गया है. खातों को फ़िल्टर करने के लिए, एक साथ कई शर्तों का इस्तेमाल किया जा सकता है. जैसे, खाते का नाम और किसी सेवा देने वाली कंपनी के साथ संबंध. इन उदाहरणों में accounts.list
तरीके का इस्तेमाल किया गया है. ज़्यादा जानकारी के लिए,
accounts.list
रेफ़रंस दस्तावेज़ देखें.
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.ListAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1.ListAccountsRequest;
import shopping.merchant.samples.utils.Authenticator;
import shopping.merchant.samples.utils.Config;
/** This class demonstrates how to filter the accounts the user making the request has access to. */
public class FilterAccountsSample {
public static void filterAccounts(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();
// Calls the API and catches and prints any network failures/errors.
try (AccountsServiceClient accountsServiceClient =
AccountsServiceClient.create(accountsServiceSettings)) {
// Filter for accounts with display names containing "store" and a provider with the ID "123":
String filter = "accountName = \"*store*\" AND relationship(providerId = 123)";
// Filter for all subaccounts of account "123":
// String filter2 = "relationship(providerId = 123 AND service(type =
// \"ACCOUNT_AGGREGATION\"))";
// String filter3 = "relationship(service(handshakeState = \"APPROVED\" AND type =
// \"ACCOUNT_MANAGEMENT\") AND providerId = 123)";
ListAccountsRequest request = ListAccountsRequest.newBuilder().setFilter(filter).build();
System.out.println("Sending list accounts request with filter:");
ListAccountsPagedResponse response = accountsServiceClient.listAccounts(request);
int count = 0;
// Iterates over all rows in all pages and prints the sub-account
// in each row.
// `response.iterateAll()` automatically uses the `nextPageToken` and recalls the
// request to fetch all pages of data.
for (Account account : response.iterateAll()) {
System.out.println(account);
count++;
}
System.out.print("The following count of elements were returned: ");
System.out.println(count);
} catch (Exception e) {
System.out.println(e);
}
}
public static void main(String[] args) throws Exception {
Config config = Config.load();
filterAccounts(config);
}
}
PHP
use Google\ApiCore\ApiException;
use Google\Shopping\Merchant\Accounts\V1\Client\AccountsServiceClient;
use Google\Shopping\Merchant\Accounts\V1\ListAccountsRequest;
/**
* This class demonstrates how to filter the accounts the user making the request has access to.
*/
class FilterAccounts
{
public static function filterAccounts(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);
// Calls the API and catches and prints any network failures/errors.
try {
// Filter for accounts with display names containing "store" and a provider with the ID "123":
$filter = "accountName = \"*store*\" AND relationship(providerId = 123)";
// Filter for all subaccounts of account "123":
// $filter = "relationship(providerId = 123 AND service(type = \"ACCOUNT_AGGREGATION\"))";
// $filter = "relationship(service(handshakeState = \"APPROVED\" AND type =
// \"ACCOUNT_MANAGEMENT\") AND providerId = 123)";
$request = new ListAccountsRequest(['filter' => $filter]);
print "Sending list accounts request with filter:\n";
$response = $accountsServiceClient->listAccounts($request);
$count = 0;
// Iterates over all rows in all pages and prints the sub-account
// in each row.
// `response.iterateAll()` automatically uses the `nextPageToken` and recalls the
// request to fetch all pages of data.
foreach ($response->iterateAllElements() as $account) {
print_r($account);
$count++;
}
print "The following count of elements were returned: ";
print $count . PHP_EOL;
} catch (ApiException $e) {
print $e->getMessage();
}
}
public function callSample(): void
{
$config = Config::generateConfig();
self::filterAccounts($config);
}
}
$sample = new FilterAccounts();
$sample->callSample();
Python
from examples.authentication import generate_user_credentials
from google.shopping.merchant_accounts_v1 import AccountsServiceClient
from google.shopping.merchant_accounts_v1 import ListAccountsRequest
def filter_accounts():
"""Filters the accounts the user making the request has access to."""
# Get OAuth credentials.
credentials = generate_user_credentials.main()
# Create a client.
client = AccountsServiceClient(credentials=credentials)
# Create the filter string.
filter_string = 'accountName = "*store*" AND relationship(providerId = 123)'
# Create the request.
request = ListAccountsRequest(filter=filter_string)
# Make the request and print the response.
try:
print("Sending list accounts request with filter:")
response = client.list_accounts(request=request)
count = 0
for account in response:
print(account)
count += 1
print(f"The following count of elements were returned: {count}")
except RuntimeError as e:
print(e)
if __name__ == "__main__":
filter_accounts()
AppsScript
/**
* Filters and lists accounts for which the logged-in user has access to
*/
function filterAccounts() {
// IMPORTANT:
// Enable the Merchant API Accounts sub-API Advanced Service and call it
// "MerchantApiAccounts"
// Create the filter string.
// Documentation can be found at
// https://developers.google.com/merchant/api/guides/accounts/filter-syntax
const filter = 'accountName = "*store*" AND relationship(providerId = 123)';
try {
console.log('Sending filter Accounts request');
let pageToken;
let pageSize = 500;
// Call the Accounts.list API method with a filter. Use the pageToken to iterate through
// all pages of results.
do {
response =
MerchantApiAccounts.Accounts.list({pageSize, pageToken, filter});
for (const account of response.accounts) {
console.log(account);
}
pageToken = response.nextPageToken;
} while (pageToken); // Exits when there is no next page token.
} catch (e) {
console.log('ERROR!');
console.log(e);
}
}
cURL
curl --location 'https://merchantapi.googleapis.com/accounts/v1/accounts?filter=accountName%20%3D%20%22*store*%22%20AND%20relationship(providerId%20%3D%20PROVIDER_ID)' \
--header 'Authorization: Bearer <API_TOKEN>'