Skip to main content

Concept

Filters

Filters describe the records you want: by demographic attribute, address, vehicle, business identifier, anything exposed by the data source. They are the same shape on every endpoint that takes one.

Shape of a filter

A filter is a JSON object with a required field and values array, plus optional condition, option, and omit attributes. Endpoints accept a list of filters and combine them with AND by default.

The field name is the key attribute exposed by GET /api/v1/data_sources/:id. Available keys differ by data source. Fetch the data source first if you're unsure what's filterable.

Simplest case · single field
{
  "filters": [
    { "field": "state", "values": ["TX", "OK"] }
  ]
}

Match options

The option attribute controls how each value is compared. Most string fields accept either exact or partial matching; numeric and enum fields ignore option.

optionbehavior
"exact"Record value must equal one of the listed values exactly. The default for most fields.
"like"Record value must contain the listed value as a substring, in order. Use this for partial-match search on freeform text like titles or company names.
null / omittedField-dependent default. Identity fields default to "exact"; freeform text fields default to "like".
Partial match
{
  "filters": [
    { "field": "title", "values": ["director"], "option": "like" }
  ]
}

Negating with omit

Set omit: true to exclude records matching the filter instead of including them. Negation runs against the field independently. Combine multiple negations to peel unwanted records off a broad base.

Texas homeowners, except in Dallas county
{
  "filters": [
    { "field": "state",  "values": ["TX"] },
    { "field": "county", "values": ["Dallas"], "omit": true }
  ]
}

ZIP radius fields (zip_radius, zip4_radius and their secondary_ versions) honor omit and exclude the records inside the radius. They used to ignore it and include those records. One whose values all match nothing excludes nothing. coordinate_radius, rooftop_radius, polygon and map_area still ignore omit and always include the records inside the shape.

Range fields

Some numeric or bucketed fields (age, income, year built) accept inclusive ranges as hyphenated strings. Pass several ranges in the same values array to combine them.

Age 18–21 or 25–30
{
  "filters": [
    { "field": "est_age", "values": ["18-21", "25-30"] }
  ]
}

Date range fields (birth date, purchase date, move date and the like) take two values, from and to, each YYYY-MM-DD. Send "" for an open side. A single string holding both ISO dates is split into the two values; any other shape is rejected with a 422.

Born March to August 1962
{
  "filters": [
    { "field": "birth_date_range", "values": ["1962-03-01", "1962-08-31"] }
  ]
}

AND and named OR groups

By default every filter in the array is AND'd together. To express OR, give two or more filters the same condition string. They become a named group where a record only needs to match one filter in the group. The top-level array remains AND, so groups slot into the larger AND expression as a single OR'd term.

Active investors who are either in NY or zip 91361
{
  "filters": [
    { "field": "active_investor", "values": ["Y"] },
    { "field": "state", "values": ["NY"],     "condition": "group1" },
    { "field": "zip",   "values": ["91361"], "condition": "group1" }
  ]
}

You can stack multiple named groups (group1, group2, …). Each one is an independent OR, and all of them are AND'd with the rest of the array.

Segments within an audience

Named OR groups combine filters inside a segment. An audience can contain several segments, each combined with the ones before it using AND, OR, or AND NOT. Assign a filter to a segment with segment_id, and set each segment's joiner. The first segment has nothing before it, so it must not have one.

Investors in NY, minus anyone in zip 91361
{
  "segment_match_type": "address_zip",
  "segments": [
    { "id": "1", "name": "Investors in NY" },
    { "id": "2", "name": "Exclude 91361", "joiner": "AND NOT" }
  ],
  "filters": [
    { "field": "active_investor", "values": ["Y"],     "segment_id": "1" },
    { "field": "state",           "values": ["NY"],    "segment_id": "1" },
    { "field": "zip",             "values": ["91361"], "segment_id": "2" }
  ]
}

segment_match_type makes a joiner meaningful by naming the key used to match records across segments. Without it there is nothing to intersect or subtract on, so joiners are ignored, segments are unioned, and a record that matches two segments is counted in both.

A filter with no segment_id applies to every segment. When you send more than one segment, each segment receives its own copy of an unassigned filter, so filters read back from the API have explicit ownership.

Segments belong to the audience that owns them. An audience built from segments cannot also join a classic audience group, which is a separate feature for combining whole audiences.

Counting a segmented audience

The count endpoints take filters, not segments. /data/count, /data/query, /count_requests, and /lists evaluate the filter array as one expression, so sending a segmented audience's filters to any of them returns a different number than the audience itself reports. Read the audience to get its count.

Used by