Sintassi filtro

Questa pagina spiega la sintassi da utilizzare per filtrare gli account.

Sintassi

Tutti i valori diversi dagli interi devono essere racchiusi tra virgolette doppie ("). Per sapere quali valori accetta un campo specifico, consulta la documentazione di riferimento relativa al campo.

Puoi utilizzare AND per filtrare in base a più campi nella stessa query. Puoi anche utilizzare AND per combinare più filtri relationship(...) e service(...). Ecco un esempio che combina più filtri relationship(...) e service(...):

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

Questo esempio restituisce i seguenti account:

  • Tutti gli account con una relazione di gestione dell'account con un altro account e un'ulteriore relazione in attesa di accettazione.

  • Tutti gli account con il nome visualizzato "store" che hanno relazioni con altri account.

Non puoi utilizzare AND per filtrare in base a più valori nello stesso campo. Ad esempio, non puoi utilizzare accountName = "*A*" AND accountName = "*B*".

Puoi utilizzare OR per filtrare in base a due campi nella stessa query. Racchiudi i criteri di filtro su ciascun lato dell'operatore OR tra parentesi. Ad esempio (accountName = "storeA") OR (accountName = "storeB").

Puoi utilizzare OR solo per combinare due campi. Ad esempio, non puoi utilizzare (accountName = "storeA") OR (accountName = "storeB") OR (accountName = "storeC").

Le parentesi non sono consentite, ad eccezione degli operatori AND e OR e delle chiamate di funzione, come relationship(...) e service(...).

Per i campi di stringa come accountName e accountIdAlias, puoi filtrare in base ai valori che contengono una determinata parola o sequenza di caratteri racchiudendo la sequenza tra asterischi (*). Ad esempio, accountName = "*foo*" restituisce tutti gli account con un accountName contenente foo, ad esempio "storeFoo".

Puoi filtrare in base ai valori che non contengono una determinata sequenza utilizzando != e *. Ad esempio, accountName != "*foo*" restituisce tutti gli account con un accountName che non contiene foo.

Gli spazi bianchi aggiuntivi vengono ignorati. Ad esempio, foo AND bar è uguale a foo AND bar.

Ecco alcuni esempi di filtri degli account utilizzando il metodo account.list:

"* Tutti i subaccount AMC contenenti "Negozio"

accountName = "*store*" AND relationship(service(type = "ACCOUNT_AGGREGATION"))
  • Tutti gli account gestiti dal provider 123456
relationship(service(type = "ACCOUNT_MANAGEMENT") AND providerId = 123456)
  • Tutti gli account che hanno inviato un invito al fornitore 123456 o che devono accettare un invito da questo fornitore
relationship(service(handshakeState = "PENDING" AND type ="ACCOUNT_MANAGEMENT")
AND providerId = 123456)

Per filtrare gli account a cui può accedere l'utente che effettua la richiesta, utilizza il metodo google.shopping.merchant.accounts.v1beta.ListAccountsRequest, come mostrato nell'esempio seguente.

Java

import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.shopping.merchant.accounts.v1beta.Account;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceClient;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceClient.ListAccountsPagedResponse;
import com.google.shopping.merchant.accounts.v1beta.AccountsServiceSettings;
import com.google.shopping.merchant.accounts.v1beta.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);
  }
}

Specifica

I filtri seguono un sottoinsieme della specifica del filtro AIP e della relativa grammatica EBNF formale:

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