필터 구문

Merchant API의 일부 list 메서드(예: account.list )의 경우 관심 있는 결과만 가져오도록 필터링을 실행할 수 있습니다. 결과를 필터링하려면 filter 매개변수를 EBNF 문법에 정의된 구문과 함께 사용합니다. 이 페이지에서는 구문을 사용하여 계정을 필터링하는 방법을 설명합니다.

구문

정수가 아닌 모든 값은 큰따옴표 (")로 묶어야 합니다. 특정 필드에서 허용되는 값을 알아보려면 해당 필드의 참조 문서를 확인하세요.

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를 사용하여 동일한 쿼리에서 두 필드를 필터링할 수 있습니다. OR 연산자의 양쪽에 있는 필터 기준을 괄호로 묶습니다. 예를 들어, (accountName = "storeA") OR (accountName = "storeB")입니다.

OR를 사용하여 두 필드만 결합할 수 있습니다. 예를 들어 (accountName = "storeA") OR (accountName = "storeB") OR (accountName = "storeC")는 사용할 수 없습니다.

괄호는 ANDOR 연산자와 함수 호출(예: relationship(...)service(...))에서만 허용됩니다.

accountNameaccountIdAlias와 같은 문자열 필드의 경우 시퀀스를 별표 (*)로 묶어 특정 단어 또는 문자 시퀀스가 포함된 값을 필터링할 수 있습니다. 예를 들어 accountName = "*foo*"는 'storeFoo'와 같이 foo가 포함된 accountName이 있는 모든 계정을 반환합니다.

!=*를 사용하여 특정 시퀀스가 포함되지 않은 값을 필터링할 수 있습니다. 예를 들어 accountName != "*foo*"foo가 포함되지 않은 accountName이 있는 모든 계정을 반환합니다.

추가 공백은 무시됩니다. 예를 들어 foo AND barfoo AND bar와 동일합니다.

다음은 account.list 메서드를 사용하여 계정을 필터링하는 몇 가지 예입니다.

  • 'Store'가 포함된 고급 계정의 모든 하위 계정:
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 메서드를 사용합니다.

자바

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 | accessFilter
    ;

accountNameFilter
    : "accountName" comparator value
    ;

capabilityFilter
    : "capabilities:" capabilityValue
    | "-capabilities:" capabilityValue
    | "NOT capabilities:" capabilityValue
    ;
capabilityValue
    : "CAN_UPLOAD_PRODUCTS"
    ;

accessFilter
    : "access = " accessType
    ;

accessType
    : "DIRECT"
    | "INDIRECT"
    | "ALL"
    ;

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"
    | "WAITING"
    | "ESTABLISHED"
    | "REJECTED"
    ;
serviceType
    : "ACCOUNT_AGGREGATION"
    | "ACCOUNT_MANAGEMENT"
    ;

comparator
    : " = "
    | " != "
    ;