HomeGuidesAPI Reference
ChangelogHelp CenterCommunityContact Us
Guides
These docs are for v2023-02-22. Click to read the latest docs for v2024-10-15.

Filtering

Learn how to use our JSON:API filtering syntax.

Filter syntax

Our JSON:API general filtering syntax and its supported operations can be used across our new APIs. Please note that support for given operators and fields is highly specific to each endpoint. You can refer to the filter query parameter in the API reference documentation for which operators are supported for each field.

The filtering syntax for Klaviyo’s new APIs uses the ?filter query parameter for all endpoints that support filter operations. The following filter syntax can be used for more complex filtering operations across all endpoints:

URL encoding

Filter expressions can contain non-URL-safe characters. We recommend that you always URI-encode the value of the filter query parameter to ensure your filter expression functions properly. See the MDN docs on encodeURIComponent for more details.

Filter operations

Below are the filter operations supported by the standard filter syntax. You can refer to the filter query parameter in the API reference documentation for which operators are supported for each field.

  • equals
    • Example: ?filter=equals(last_name,"Smith")
    • Supported field types: string, boolean, number, datetime, array
  • less-than
    • Example: ?filter=less-than(value,25)
    • Supported field types: number, datetime
  • less-or-equal
    • Example: ?filter=less-or-equal(datetime,2001-01-01T11:00:00Z)
    • Supported field types: number, datetime
  • greater-than
    • Example: ?filter=greater-than(datetime,2022-04-01T11:30:00Z)
    • Supported field types: number, datetime
  • greater-or-equal
    • Example: ?filter=greater-or-equal(percentage,33.33)
    • Supported field types: number, datetime
  • contains
    • Example: ?filter=contains(description,"cooking")
    • Supported field types: string, array
  • ends-with
    • Example: ?filter=ends-with(description,"End")
    • Supported field types: string
  • starts-with
    • Example: ?filter=starts-with(description,"Start")
    • Supported field types: string
  • any
    • Example: ?filter=any(chapter,["Intro","Summary","Conclusion"])
    • Supported field types: string, number, datetime, boolean
  • and
    • Example: ?filter=and(equals(first_name,"Jane"),equals(email,"[email protected]"))
    • Accepts other operator functions as arguments, and cannot accept nested functions beyond 1 level deep

📘

Klaviyo’s APIs also interpret comma-separated filter expressions as an alias for an and wrapper function.
For example: filter=and(equals(field1,"foo"),equals(field2,"bar"))
can be simplified to
filter=equals(field1,"foo"),equals(field2,"bar")

This can be particularly helpful for filtering on a date range. For example, pulling all events for a specific metric for a specific time range would look like the below, swapping out your own metric_id and datetime values:

filter=equals(metric_id,"UxxK4u"),greater-or-equal(datetime,2023-02-07),less-than(datetime,2023-02-15)

Comparison literals

  • string: Arguments representing string literals are expressed with quotation marks (we will accept either single quoted or double-quoted strings). Single or double-quoted characters within strings (quoted with like quote characters) MUST be escaped with a single backslash (i.e. ‘Tony\’s ball’)
    Comparisons to all string literals are case-sensitive, unless otherwise noted in endpoint specific documentation
  • boolean: Booleans are expressed as unquoted true and false literal values
  • number: Numbers are expressed as standard integer or float representations
  • datetime: Datetimes are expressed as unquoted ISO-8601 RFC-3339 formatted strings. For example, 2012-04-21T11:30:00-04:00
  • array: Array literals are expressed using square brackets ([ ])