Skip to main content
POST
Create an aggregate
An aggregate counts the events you send with Dispatch events. It keeps one counter for each value of its key, over a sliding window. A rule reads the counter of the evaluated identifier as aggregate.custom.<name>. This aggregate counts the confirmed fraud reports for each phone number over the last 14 days:
A rule with the expression aggregate.custom.fraud_reports > 3 then triggers for a phone number with more than 3 such events in the last 14 days.

What you can count

An event has one target. An aggregate therefore reads either the email address or the phone number fields, not both. A COUNT_DISTINCT counter keeps at most 10,000 values. Past this, the values seen least recently are dropped, so the count stops at 10,000.

Limits

You can have at most 20 aggregates. One more answers 409 with aggregate_limit_reached: delete one first. Your aggregates also share a limit on how many counters they hold: see Limits. Only the description can change after creation. Choose the key, the window and the filter with care: to change them, you create a new aggregate, which starts from zero. A new aggregate does not count past events: it counts the events you send after it is created. Until a full window has passed since it counted its first event, a rule reading it reports NOT_EVALUATED. For a 14d window, this is 14 days after the first counted event. An aggregate that has not counted an event yet, for example because no event matched its filter, stays NOT_EVALUATED. See Aggregates.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json
name
string
required

The name a rule reads the aggregate by, as aggregate.custom.<name>. It starts with a lowercase letter and contains only lowercase letters, digits and underscores. It must be unique among your aggregates.

Maximum string length: 64
Pattern: ^[a-z][a-z0-9_]*$
Example:

"fraud_reports"

measure
enum<string>
required

What the aggregate counts for each value of key.

  • COUNT - The number of matching events.
  • COUNT_DISTINCT - The number of different values of distinct in the matching events. A counter keeps at most 10,000 values: past this, the values seen least recently are dropped, so the count stops at 10,000.
Available options:
COUNT,
COUNT_DISTINCT
Example:

"COUNT"

key
enum<string>[]
required

The event values that select a counter: there is one counter for each combination of their values. At least one, and each one only once.

  • target.phone_number - The phone number of the event target.
  • target.email_address - The email address of the event target.
  • target.phone_prefix_7 and target.phone_prefix_9 - The first 6 or 8 digits of the phone number of the event target: its first 7 or 9 characters, without the leading +. For +33612345678, they are 336123 and 33612345.

An event has one target, so key and distinct together read either the email address or the phone number fields, not both. An event that has no value for one of them is not counted.

Available options:
target.phone_number,
target.email_address,
target.phone_prefix_7,
target.phone_prefix_9
Example:
window
enum<string>
required

How far back the aggregate counts. The window slides, so an event stops being counted when it is older than the window.

Available options:
10m,
1h,
3h,
24h,
14d
Example:

"14d"

source
object
required

What feeds the aggregate.

description
string

A free-text explanation of the aggregate, for the people who maintain it. Optional. Omitting it on an update clears it. It is the only field you can change after creation.

Maximum string length: 1024
Example:

"Confirmed fraud reports per phone number."

distinct
enum<string>

The event value a COUNT_DISTINCT aggregate counts the different values of. Required for COUNT_DISTINCT, refused for COUNT. It takes the same values as key.

Available options:
target.phone_number,
target.email_address,
target.phone_prefix_7,
target.phone_prefix_9
Example:

"target.phone_number"

Response

Created

id
string
required

The aggregate identifier.

Example:

"agg_01jc0t6fwwfgfsq1md24mhyztj"

name
string
required
Example:

"fraud_reports"

description
string
required
Example:

"Confirmed fraud reports per phone number."

type
enum<string>
required

Always CUSTOM. An aggregate you define is your own, and only your rules can read it.

Available options:
CUSTOM
measure
enum<string>
required
Available options:
COUNT,
COUNT_DISTINCT
key
string[]
required
Example:
window
enum<string>
required
Available options:
10m,
1h,
3h,
24h,
14d
Example:

"14d"

source
object
required
distinct
string

Only on a COUNT_DISTINCT aggregate.

Example:

"target.phone_number"