Docs·Notifications

POST/api/v1/spreelytics/notification-rules

Create a notification rule

Creates a notification rule and returns it. Rules are checked as events arrive, so a new rule starts matching within a minute. It never looks back at events from before it existed.

config holds a type and 1 to 10 events rows, read by type:

  • events: fires when any one of the rows' events arrives. A row names an event from the event catalog, page views included, or * for any event.
  • funnel: fires when one visit does the rows' events in order, with anything else allowed between them. It is checked when the visit ends, and needs at least 2 rows.
  • revenue: fires when a payment arrives from a connected payment provider or the revenue API. A row names its kind: sale, renewal, trial or refund. Imported payments never fire.
  • goal: fires when a visit completes one of the rows' saved goals, named by goal id, at most once per visit.

A row can carry up to 5 filters, all of which must match. Each is { "name", "operator", "value" }:

  • name: path, hostname or title (these three only match page views and scrolls), country, region, city, timezone, browser, browser_version, os, os_version, device, or a property of the event. A revenue row reads amount (in the audience's reporting currency), product or currency. A goal row takes no filters.
  • operator: is (exact, case-sensitive), isNot, contains, doesNotContain, startsWith or endsWith (these four ignore case), gt, gte, lt or lte (compared as numbers or dates), isNull or isNotNull.
  • value: 1 to 20 strings, any of which may match (with isNot, none of them). gt, gte, lt and lte take exactly one, and isNull and isNotNull take [].

A rule that emails the team on each sale of 500 or more, then stays quiet for an hour:

{
  "name": "Big sale",
  "config": {
    "type": "revenue",
    "events": [{ "name": "sale", "filters": [{ "name": "amount", "operator": "gte", "value": ["500"] }] }]
  },
  "cooldownSeconds": 3600,
  "emailEnabled": true
}

A config the rule could not evaluate answers 400, naming what is wrong. Needs the Editor or Admin role in the workspace that owns the audience. A Viewer gets 403.

Keys: an account key. Getting started explains both kinds.

Parameters

PropInTypeNotes
contactListIdquerystringThe audience id, a UUID. With an audience key it must be that key's own audience.

Request body

PropTypeNotes
namestringRequired. Trimmed, and a blank name answers 400.
configNotificationRuleConfigRequired. What the rule watches for, as described above.
cooldownSeconds?numberOptional snooze, a whole number of seconds from 0 to 86400 (a day). Defaults to 0, which notifies on every match. The app offers 0, 60, 900, 3600 and 86400.
enabled?booleanOptional. Defaults to true. false saves the rule paused.
emailEnabled?booleanOptional. Defaults to false. true also emails everyone on the team who has notification emails on, at most 50 notifications a day for this rule, counted from midnight UTC.

Response

Answers 201.

PropTypeNotes
idstringThe rule id.
namestringThe rule's name. Every notification it writes carries it as its title.
configNotificationRuleConfigWhat it watches for: its type and its events rows, as Create a notification rule describes them.
cooldownSecondsnumberThe snooze in seconds: after the rule writes a notification, it skips every match for this long. 0 notifies on every match.
enabledbooleanfalse while the rule is paused. A paused rule writes nothing.
emailEnabledbooleantrue when the rule also emails the team.
createdAtstringWhen it was created, in ISO 8601.
updatedAtstringWhen it last changed, in ISO 8601.
triggeredCountnumberOnly when the list was asked for a window: how many notifications the rule wrote in it, previews left out.
lastTriggeredAtstringOnly alongside triggeredCount: when the rule last wrote a notification, at any time, or null if it never has.

Request

curl -X POST 'https://app.spreelytics.com/api/v1/spreelytics/notification-rules?contactListId=…' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{ … }'
const res = await fetch('https://app.spreelytics.com/api/v1/spreelytics/notification-rules', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ /* see Request body above */ }),
});
const data = await res.json();
import requests

res = requests.post(
    "https://app.spreelytics.com/api/v1/spreelytics/notification-rules",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={},  # see Request body above
)
data = res.json()

Response

{
  "id": "string",
  "name": "string",
  "config": {
    "type": "events",
    "events": [
      {
        "name": "string",
        "filters": [
          null
        ]
      }
    ]
  },
  "cooldownSeconds": 0,
  "enabled": true,
  "emailEnabled": true,
  "createdAt": "string",
  "updatedAt": "string",
  "triggeredCount": 0,
  "lastTriggeredAt": "string"
}

See your own numbers today.

Free up to 100k events a month · no credit card

Contact

Tell us what you need.

A real person reads these. We usually reply within one working day.

Or email us directly at contact@spreelytics.com.