इस पेज पर, खातों को फ़िल्टर करने के लिए इस्तेमाल किए जाने वाले सिंटैक्स के बारे में बताया गया है.
सिंटैक्स
पूर्णांक के अलावा, सभी वैल्यू को डबल कोट (") में रखना ज़रूरी है. किसी फ़ील्ड में कौनसी वैल्यू डाली जा सकती हैं, यह जानने के लिए उस फ़ील्ड का रेफ़रंस दस्तावेज़ देखें.
एक ही क्वेरी में कई फ़ील्ड को फ़िल्टर करने के लिए, AND
का इस्तेमाल किया जा सकता है. एक से ज़्यादा relationship(...)
और service(...)
फ़िल्टर को एक साथ इस्तेमाल करने के लिए, AND
का इस्तेमाल किया जा सकता है.
यहां एक उदाहरण दिया गया है, जिसमें कई relationship(...)
और service(...)
फ़िल्टर को एक साथ इस्तेमाल किया गया है:
(relationship(service(type = "ACCOUNT_MANAGEMENT") AND service(handshakeState = "PENDING"))) OR (accountName = "store" AND relationship(...))
इस उदाहरण में, ये खाते दिखाए गए हैं:
ऐसे सभी खाते जिनका किसी दूसरे खाते के साथ खाता मैनेजमेंट का संबंध है. साथ ही, किसी दूसरे खाते के साथ संबंध है, लेकिन उसे स्वीकार नहीं किया गया है.
"store"
डिसप्ले नेम वाले सभी खाते, जिनका संबंध अन्य खातों से है.
AND
का इस्तेमाल करके, एक ही फ़ील्ड में मौजूद कई वैल्यू को फ़िल्टर नहीं किया जा सकता. उदाहरण के लिए, accountName = "*A*" AND accountName = "*B*"
का इस्तेमाल नहीं किया जा सकता.
एक ही क्वेरी में दो फ़ील्ड के लिए फ़िल्टर करने के लिए, OR
का इस्तेमाल किया जा सकता है. OR
ऑपरेटर के दोनों ओर, फ़िल्टर की शर्तों को ब्रैकेट में रखें. उदाहरण के लिए,
(accountName = "storeA") OR (accountName = "storeB")
.
दो फ़ील्ड को जोड़ने के लिए, सिर्फ़ OR
का इस्तेमाल किया जा सकता है. उदाहरण के लिए, (accountName = "storeA") OR (accountName = "storeB") OR (accountName =
"storeC")
का इस्तेमाल नहीं किया जा सकता.
ब्रैकेट का इस्तेमाल सिर्फ़ AND
और OR
ऑपरेटर के साथ किया जा सकता है. इसके अलावा, इनका इस्तेमाल फ़ंक्शन इनवोकेशन में किया जा सकता है. जैसे, relationship(...)
और service(...)
.
accountName
और accountIdAlias
जैसे स्ट्रिंग फ़ील्ड के लिए, उन वैल्यू को फ़िल्टर किया जा सकता है जिनमें कोई खास शब्द या वर्णों का क्रम शामिल हो. इसके लिए, वर्णों के क्रम को तारांक (*
) में शामिल करें. उदाहरण के लिए, accountName = "*foo*"
उन सभी खातों को दिखाता है जिनके accountName
में foo
शामिल है, जैसे कि "storeFoo".
!=
और *
का इस्तेमाल करके, उन वैल्यू को फ़िल्टर किया जा सकता है जिनमें कोई खास क्रम शामिल नहीं है. उदाहरण के लिए, accountName != "*foo*"
उन सभी खातों को दिखाता है जिनमें accountName
मौजूद है, लेकिन foo
मौजूद नहीं है.
ज़्यादा खाली जगहों को अनदेखा कर दिया जाता है. उदाहरण के लिए, foo AND bar
और foo
AND bar
एक ही हैं.
account.list तरीके का इस्तेमाल करके खातों को फ़िल्टर करने के कुछ उदाहरण यहां दिए गए हैं:
"* एमसीए के वे सभी उप-खाते जिनमें "स्टोर" शामिल है
accountName = "*store*" AND relationship(service(type = "ACCOUNT_AGGREGATION"))
- वे सभी खाते जिन्हें 123456 आईडी वाला सेवा देने वाला व्यक्ति मैनेज करता है
relationship(service(type = "ACCOUNT_MANAGEMENT") AND providerId = 123456)
- वे सभी खाते जिन्होंने सेवा देने वाली कंपनी 123456 को न्योता भेजा है या जिन्हें इस कंपनी से न्योता स्वीकार करना है
relationship(service(handshakeState = "PENDING" AND type ="ACCOUNT_MANAGEMENT")
AND providerId = 123456)
अनुरोध करने वाले उपयोगकर्ता के पास जिन खातों का ऐक्सेस है उन्हें फ़िल्टर करने के लिए, google.shopping.merchant.accounts.v1.ListAccountsRequest
तरीके का इस्तेमाल करें. इसका उदाहरण यहां दिया गया है.
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);
}
}
खास जानकारी
फ़िल्टर, एआईपी फ़िल्टर के सबसेट के साथ काम करते हैं. साथ ही, इसके फ़ॉर्मल ईबीएनएफ़ व्याकरण के साथ भी काम करते हैं:
filter
: accountFilterDisj
| accountFilterConj
accountFilterDisj
: "(" accountFilterConj " OR " accountFilterConj ")"
;
accountFilterConj
: accountFilter {" AND " accountFilter}
;
accountFilter
: accountNameFilter | capabilityFilter | relationshipFn
;
accountNameFilter
: "accountName" comparator value
;
capabilityFilter
: "capabilities:" capabilityValue
| "-capabilities:" capabilityValue
| "NOT capabilities:" capabilityValue
;
capabilityValue
: "CAN_UPLOAD_PRODUCTS"
;
relationshipFn
: "relationship(" relationshipConj ")"
;
relationshipConj
: relationshipFilter {" AND " relationshipFilter}
;
relationshipFilter
: "providerId = " numValue
| "accountIdAlias" comparator value
| serviceFn
;
serviceFn
: "service(" serviceConj ")"
;
serviceConj
: serviceFilter {" AND " serviceFilter}
;
serviceFilter
: "externalAccountId" comparator value
| "handshakeState = " handshakeState
| "type = " serviceType
;
handshakeState
: "PENDING"
| "APPROVED"
| "REJECTED"
;
serviceType
: "ACCOUNT_AGGREGATION"
| "ACCOUNT_MANAGEMENT"
;
comparator
: " = " | " != "
;