Query Expressions

NEON allows you to limit the result of queries based on the Json object's field values. Intervals, wildcards etc are supported, as described below.

This is achieved through the qry query parameter. There are two formats, which work the same way:

// Single qry parameter format
?qry=field1:expression1;field2:expressions2;...

// Split qry_ parameter format
?qry_field1=expression1&qry_field2:expression2

Which fields can be queryed?

The fields that can be used in the query expression are different for each endpoint and depends on the fields in the returned Json objects. For example, when querying the Wallets endpoint:

GET .../wallets/MyWallet/members?qry=

{
    "content": [
        {
            // The Wallet is specified in the endpoint Url
            "walletId": "abc123", // As per thequery endpoint URL
            "walletInfo": {
                "name": "MyWallet",
                "type": "WALLET",
                "state": "PUBLISHED"
            },
            // All Member fields are queryable through the qry parameter through _members.*
            "memberId": "abc12345",
            "memberInfo": {
                "externalId": "7d6c0989-78e6-4f36-b21e-7510c23c0eed",
                "state": "ACTIVE",
                "category": "Guest"
            },
            "balance": 125.0,                  // qry parameter Query Expression
            "unitName": "points",              // Not queryable, as defined in MyWallet
            "created": "2021-06-22T17:05:13Z", // qry parameter Query Expression
            "updated": "2021-06-22T17:12:04Z"  // qry parameter Query Expression
        },
        ...
    },
    "elements": 100,
    "page": 0,
    "pageSize": 100,
    "totalElements": ...,
    "totalPages": ...
}

As you can see, the possible qry fields for Wallets are: balance, created and updated. The queryable fields that can be specified in the qry parameter are listed in the documentation for each endpoint.

In addition, it's always possible to query by all fields in the Members table, by prefixing the field name with _members. The following _members fields can be used:

  • _members.id (or _members.memberId)
  • _members.externalId
  • _members.state
  • _members.category
  • _members.email
  • _members.emailState
  • _members.mobile
  • _members.mobileState
  • _members.optinState
  • _members.created
  • _members.updated

For example, to find all Wallets with a balance of zero, that was created before 2023, and where the Member is Active and has an email address:

GET .../wallets/MyWallet/members?qry=balance:0;created:<2023-01-01;_members.state:ACTIVE;_members.email:*

Or, using the split qry format:

GET .../wallets/MyWallet/members?qry_balance=0&qry_created=<2023-01-01&qry__members.state=ACTIVE&qry__members.email=*

The same fields that can be specified in the qry parameter can normally also be used for sorting, for example:

GET .../wallets/MyWallet/members?sort=balance,_members.id

Querying Json fields

Some transactional data, such as Orders and Surveys contain a Json data field. These Json fields are assumed to hold key value-pair attributes. It is possible to query those values as well by prefixing the json keys with data. Note, that it is not possible to query Json arrays or deeper levels within the json structure.

Example:

GET /surveys/MySurvey/members?qry=data.someQuestion:ABC

To Query a Member's Dimensions, or Dimensions associated with a transaction, you need to use the dimf query parameter instead of the qry parameter. This is described elsewhere.

The Query Expression

The query expression that can be used for each field has the following format:

[!] value-expr [, value-expr [,...] ]

As you can see, it's possible to enter more than one value expression. If more than one, NEON adds them with a logical OR. So for example qry=myField:ABC,DEF means that myField must have either the value ABC or the value DEF.

The optional exclamation mark at the top negates the whole expression. So, qry=myField:!ABC,DEF means the field can have any value EXCEPT ABC or DEF. Note, be careful when using ! for fields that can be empty.

The following value-expressions can be used:

  • Exact value. For example 'UK'. Requires the field value to match exactly (SQL =)
  • List of exact values. For example 'UK,US'. The field Value must have one of those values (SQL IN)
  • Wildcard value. For example 'summer*'. The field value must begin with summer, but can contain any characters afterwards. (SQL LIKE). Note, this is only applicable to character fields
  • Interval. For example 'A-ZZZZ'. The field value must start with a character in the interval. (SQL BETWEEN). Note that the last value of the interval must cover all characters, as in the example above.
  • To say that the field must have a value, specify a single wildcard '*' (SQL NOT NULL)
  • To say that the field must be empty, give the value '.' (SQL NULL)
  • Any of the above can be negated by starting the expression with '!', for example '!summer*' (SQL NOT LIKE)

Here are some examples of Query Expressions, and what they mean:

Sample Query ExpressionExample and meaning
empty stringIgnored (for example 'qry=myField:')
ACTIVEThe field must have the value ACTIVE
ACTIVE,DORMANTThe field must have one of the values ACTIVE,DORMANT
A*The field value must start with 'A'
1..5The field value must be between 1 and 5 (if numeric), or start with the character '1' to '4' (or the exact string '5') if alphanumeric.
* (star)The field must have a value
. (dot)The field mustn't have a value
!*The field mustn't have a value (the same as '.')
A*,D..FZZZZZZZThe field value must start with A OR start with D to F
.,0,400..500For a numeric field, it must either be empty or zero, or in the range between 400 and 500
!ACTIVE,D*The field can have any value except it can't be ACTIVE or start with D

Note that the query value may or may not be case sensitive, depending on if the field is case sensitive or not.

Note, for timestamp fields that you can only search by the full date part, in the format YYYY-MM-DD, or in date-time to seconds, YYYY-MM-DDTHH:MI:SS. If a time part is specified, it has to be based on the UTC timezone.