フィルタの構文

このページでは、アカウントをフィルタするために使用する必要がある構文について説明します。

構文

整数以外の値はすべて二重引用符(")で囲む必要があります。特定のフィールドで指定できる値については、そのフィールドのリファレンス ドキュメントをご覧ください。

AND を使用すると、同じクエリで複数のフィールドをフィルタできます。また、AND を使用して、複数の relationship(...) フィルタと service(...) フィルタを組み合わせることもできます。複数の relationship(...) フィルタと service(...) フィルタを組み合わせた例を次に示します。

(relationship(service(type = "ACCOUNT_MANAGEMENT") AND service(handshakeState = "PENDING"))) OR (accountName = "store" AND relationship(...))

この例では、次のアカウントが返されます。

  • 別のアカウントとのアカウント管理関係があり、承認待ちの追加の関係があるすべてのアカウント。

  • 表示名が "store" で、他のアカウントとの関係があるすべてのアカウント。

AND を使用して、同じフィールド内の複数の値をフィルタすることはできません。たとえば、accountName = "*A*" AND accountName = "*B*" は使用できません。

OR を使用すると、同じクエリで 2 つのフィールドをフィルタできます。OR 演算子の両側のフィルタ条件をかっこで囲みます。例: (accountName = "storeA") OR (accountName = "storeB")

OR を使用して 2 つのフィールドを結合することしかできません。たとえば、(accountName = "storeA") OR (accountName = "storeB") OR (accountName = "storeC") は使用できません。

AND 演算子と OR 演算子、および relationship(...)service(...) などの関数呼び出し以外では、かっこは使用できません。

accountNameaccountIdAlias などの文字列フィールドでは、特定の単語や文字のシーケンスを含む値をフィルタできます。シーケンスをアスタリスク(*)で囲みます。たとえば、accountName = "*foo*" は、foo(「storeFoo」など)を含む accountName を持つすべてのアカウントを返します。

!=* を使用すると、特定のシーケンスを含まない値をフィルタできます。たとえば、accountName != "*foo*" は、foo を含まない accountName を持つすべてのアカウントを返します。

余分な空白は無視されます。たとえば、foo AND barfoo AND bar と同じです。

account.list メソッドを使用してアカウントをフィルタリングする例をいくつか示します。

「* 「Store」を含むすべての MCA サブアカウント

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);
  }
}

仕様

フィルタは、AIP フィルタ仕様のサブセットと、その形式の EBNF 文法に従います。

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
    : " = " | " != "
    ;