# Filters

## Simple filters

On `GET /master/{kind}`:

- `search=…` — free text.
- `f_<column>=<value>` — one column equals a value, e.g. `f_country=Germany`.
  Repeat for more columns (all must match).
- `list_id=…` with `membership=in_list` or `not_in_list`.

```bash
curl -s "$CRM/master/people?f_country=Germany&f_seniority=Director" -H "Authorization: Bearer $KEY"
```

## The `filter` parameter

For anything more, `filter` takes a group of conditions as **compact JSON,
base64url-encoded** (no padding).

A condition: `{"f": "<field>", "o": "<operator>", "v": "<value>"}` — add
`"w"` for the upper bound of `between` / `date_between`, or `"s": [..]` for
the many-value operators.

A group: `{"c": "A", "g": [ …conditions or groups… ]}` — `"A"` = all must
match, `"O"` = any. Add `"n": 1` to negate the group.

**Operators**

| Field kind | Operators |
|---|---|
| Text, select | `eq` `neq` `contains` `not_contains` `starts_with` `ends_with` `in` `not_in` `contains_any` `contains_all` `contains_none` `is_empty` `is_not_empty` |
| Number | `eq` `neq` `gt` `gte` `lt` `lte` `between` `is_empty` `is_not_empty` |
| Date | `date_on` `date_before` `date_after` `date_between` `last_n_days` `next_n_days` `is_empty` `is_not_empty` |
| Yes / no | `is_true` `is_false` |
| Multi-select | `has_any` `has_all` `has_none` |

`f` is a column slug. On records of a **custom** type (`GET /entities`) these also work: `__status`,
`__follow_up`, `__last_activity`, `__activity_type`, `__activity_count`,
`__open_tasks`, `__created_at`, `__updated_at`.

**Example** — people in Germany *or* France who have an email address:

```bash
FILTER=$(node -e 'console.log(Buffer.from(JSON.stringify(
  {c:"A",g:[{c:"O",g:[{f:"country",o:"eq",v:"Germany"},{f:"country",o:"eq",v:"France"}]},
            {f:"email",o:"is_not_empty"}]})).toString("base64url"))')
curl -s "$CRM/master/people?filter=$FILTER" -H "Authorization: Bearer $KEY"
```

A filter that cannot be read is ignored (you get everything), so check the
`total` of the answer when you first build one.
