Docs·Notifications
/api/v1/spreelytics/notification-rulesCreate 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,trialorrefund. 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,hostnameortitle(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 readsamount(in the audience's reporting currency),productorcurrency. A goal row takes no filters.operator:is(exact, case-sensitive),isNot,contains,doesNotContain,startsWithorendsWith(these four ignore case),gt,gte,ltorlte(compared as numbers or dates),isNullorisNotNull.value: 1 to 20 strings, any of which may match (withisNot, none of them).gt,gte,ltandltetake exactly one, andisNullandisNotNulltake[].
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
| Prop | In | Type | Notes |
|---|---|---|---|
contactListId | query | string | The audience id, a UUID. With an audience key it must be that key's own audience. |
Request body
| Prop | Type | Notes |
|---|---|---|
name | string | Required. Trimmed, and a blank name answers 400. |
config | NotificationRuleConfig | Required. What the rule watches for, as described above. |
cooldownSeconds? | number | Optional 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? | boolean | Optional. Defaults to true. false saves the rule paused. |
emailEnabled? | boolean | Optional. 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.
| Prop | Type | Notes |
|---|---|---|
id | string | The rule id. |
name | string | The rule's name. Every notification it writes carries it as its title. |
config | NotificationRuleConfig | What it watches for: its type and its events rows, as Create a notification rule describes them. |
cooldownSeconds | number | The snooze in seconds: after the rule writes a notification, it skips every match for this long. 0 notifies on every match. |
enabled | boolean | false while the rule is paused. A paused rule writes nothing. |
emailEnabled | boolean | true when the rule also emails the team. |
createdAt | string | When it was created, in ISO 8601. |
updatedAt | string | When it last changed, in ISO 8601. |
triggeredCount | number | Only when the list was asked for a window: how many notifications the rule wrote in it, previews left out. |
lastTriggeredAt | string | Only 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"
}