Filtering

Flexera One APIs that return collections/lists of records often support filtering. Filtering allows API clients to, in their request, describe which records from the collection they are interested in, so the API can return only those records.

Clients use the filter query parameter to provide a filter expression which the API evaluates against each record of the complete collection to decide if it will be included in the filtered response to the client.

The filter expression should always be URL-encoded. Examples provided below are un-encoded for clarity.

Filter Operators

The following table describes all valid operators that may be used in filter expressions. Each API documents the subset of operators that is valid when using that API.

Operator Type Operator Description Example
Comparison eq Equal name eq 'SAP'
ne Not equal name ne 'SAP'
co Contains name co 'SAP'
gt Greater than price gt 20
ge Greater than or equal price ge 10
lt Less than price lt 20
le Less than or equal price le 100
Logical and Logical and price le 200 and price gt 3.5
or Logical or price le 3.5 or price gt 200
not Logical negation not price le 3.5
Grouping ( ) Precedence grouping (priority eq 1 or city eq 'Redmond') and price gt 100

Some important points about building filter expressions:

  • Operators should always be lower-cased (eq instead of EQ)
  • Operands are case-sensitive, unless otherwise stated by API-specific documentation
  • Literal values should always be the right operand (name eq 'SAP' instead of 'SAP' eq name)
  • For co operator, the entire operator value must be a substring of the attribute value for a match

Precedence

Operator precedence determines the order in which operators are interpreted when an expression contains multiple operators. Operators are listed by category in order of precedence from highest to lowest. Operators in the same category have equal precedence, and are evaluated left-to-right.

Category Operator Description
Grouping ( ) Precedence grouping
Unary not Logical Negation
Relational gt Greater Than
ge Greater than or Equal
lt Less Than
le Less than or Equal
Equality eq Equal
ne Not Equal
co Contains
Conditional AND and Logical And
Conditional OR or Logical Or

Example

The following example retrieves a collection of customers with a name attribute containing the string blue.

curl -i https://api.flexera.com/msp/v1/orgs/123/customers \
  -H "Authorization: Bearer <accessToken>" \
  --get --data-urlencode "filter=(name co 'blue')"

Note the filter expression (name co 'blue') is URL-encoded by cURL's --data-urlencode option, and --get ensures the request is an HTTP GET request.