Segments.
Save a live filter on a contact book and read who matches it. Every request needs an API key in the Authorization header; the reference overview covers keys, errors and rate limits.
List segments
GET/v1/contactBooks/{contactBookId}/segmentsFull access key
List a contact book's segments, oldest first. Each carries its live count and any problems that make it match nothing.
| Field | Type | About |
|---|---|---|
contactBookIdrequired | string |
curl -X GET "https://app.usenotix.dev/api/v1/contactBooks/<contactBookId>/segments" \
-H "Authorization: Bearer $NOTIX_API_KEY"
import { Notix } from "notix-js";
const notix = new Notix(process.env.NOTIX_API_KEY);
const { data, error } = await notix.segments.list("cb_123");
data?.data.forEach((segment) => console.log(segment.name, segment.count));
from notix import Notix
notix = Notix() # reads NOTIX_API_KEY
segments, _ = notix.segments.list("cb_123")
for segment in segments["data"]:
print(segment["name"], segment["count"])
use Notix\Notix;
$notix = new Notix(getenv('NOTIX_API_KEY'));
$segments = $notix->segments->list('cb_123');
foreach ($segments['data'] as $segment) {
echo $segment['name'], ' ', $segment['count'], PHP_EOL;
}
Responses
200The contact book's segments, oldest first, each with its live count.
| Field | Type | About |
|---|---|---|
datarequired | object[] | |
data[].idrequired | string | |
data[].contactBookIdrequired | string | |
data[].namerequired | string | |
data[].descriptionrequired | string | Can be null. |
data[].definitionrequired | object | |
data[].definition.versionrequired | number | One of |
data[].definition.matchrequired | string | One of |
data[].definition.conditionsrequired | object[] | |
data[].countrequired | integer | Contacts that match right now. 0 while the segment has problems. |
data[].problemsrequired | string[] | Why the segment matches nothing, such as a property removed from the contact book. |
data[].createdAtrequired | string | |
data[].updatedAtrequired | string |
404No contact book with this id for the calling team.
Create a segment
POST/v1/contactBooks/{contactBookId}/segmentsFull access key
Create a live filter on a contact book. A segment is evaluated whenever it is used, so contacts join and leave it as their details and behaviour change.
Definition
match is all or any, and conditions holds up to 20 conditions, counting those inside groups. A condition can be a group with its own match; groups do not nest.
| type | Operators | Fields |
|---|---|---|
email | equals, not_equals, contains, ends_with | value |
first_name, last_name | equals, not_equals, contains, is_set, is_empty | value, except for is_set and is_empty |
subscribed | is | value: true or false |
added | before, after, in_last_days | value: a date, or a number of days |
property | equals, not_equals, contains, is_set, is_empty, gt, gte, lt, lte | key (a variable on the book) and value |
email_activity | in_last_days, ever, never | event: received, opened or clicked; optional campaignId; days for in_last_days |
email_problem | ever, never | event: bounced or complained |
journey | is_in, completed, exited, not_in | journeyId |
Text comparisons ignore case. A contact book holds at most 100 segments.
{
"name": "Engaged Pro users",
"definition": {
"version": 1,
"match": "all",
"conditions": [
{ "type": "property", "key": "plan", "op": "equals", "value": "Pro" },
{
"type": "group",
"match": "any",
"conditions": [
{ "type": "email_activity", "event": "opened", "op": "in_last_days", "days": 30 },
{ "type": "email_activity", "event": "clicked", "op": "in_last_days", "days": 30 }
]
}
]
}
}
| Field | Type | About |
|---|---|---|
contactBookIdrequired | string |
| Field | Type | About |
|---|---|---|
namerequired | string | At most 80 characters. |
description | string | At most 280 characters. Can be null. |
definitionrequired | object | |
definition.versionrequired | number | One of |
definition.matchrequired | string | One of |
definition.conditionsrequired | object[] |
curl -X POST "https://app.usenotix.dev/api/v1/contactBooks/<contactBookId>/segments" \
-H "Authorization: Bearer $NOTIX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Engaged Pro users",
"definition": {
"version": 1,
"match": "all",
"conditions": [
{
"type": "property",
"key": "plan",
"op": "equals",
"value": "Pro"
},
{
"type": "email_activity",
"event": "opened",
"op": "in_last_days",
"days": 30
}
]
}
}'
import { Notix } from "notix-js";
const notix = new Notix(process.env.NOTIX_API_KEY);
const { data, error } = await notix.segments.create("cb_123", {
name: "Engaged Pro users",
definition: {
version: 1,
match: "all",
conditions: [
{ type: "property", key: "plan", op: "equals", value: "Pro" },
{ type: "email_activity", event: "opened", op: "in_last_days", days: 30 },
],
},
});
from notix import Notix
notix = Notix() # reads NOTIX_API_KEY
segment, _ = notix.segments.create(
"cb_123",
{
"name": "Engaged Pro users",
"definition": {
"version": 1,
"match": "all",
"conditions": [
{"type": "property", "key": "plan", "op": "equals", "value": "Pro"},
{"type": "email_activity", "event": "opened", "op": "in_last_days", "days": 30},
],
},
},
)
use Notix\Notix;
$notix = new Notix(getenv('NOTIX_API_KEY'));
$segment = $notix->segments->create('cb_123', [
'name' => 'Engaged Pro users',
'definition' => [
'version' => 1,
'match' => 'all',
'conditions' => [
['type' => 'property', 'key' => 'plan', 'op' => 'equals', 'value' => 'Pro'],
['type' => 'email_activity', 'event' => 'opened', 'op' => 'in_last_days', 'days' => 30],
],
],
]);
Responses
201The segment was created.
| Field | Type | About |
|---|---|---|
idrequired | string | |
contactBookIdrequired | string | |
namerequired | string | |
descriptionrequired | string | Can be null. |
definitionrequired | object | |
definition.versionrequired | number | One of |
definition.matchrequired | string | One of |
definition.conditionsrequired | object[] | |
countrequired | integer | Contacts that match right now. 0 while the segment has problems. |
problemsrequired | string[] | Why the segment matches nothing, such as a property removed from the contact book. |
createdAtrequired | string | |
updatedAtrequired | string |
400The definition is not valid, names something the book or team does not have, or the book already has 100 segments.
404No contact book with this id for the calling team.
409A segment with this name already exists in the contact book.
Get a segment
GET/v1/contactBooks/{contactBookId}/segments/{segmentId}Full access key
Retrieve one segment with its definition, live count and problems.
| Field | Type | About |
|---|---|---|
contactBookIdrequired | string | |
segmentIdrequired | string |
curl -X GET "https://app.usenotix.dev/api/v1/contactBooks/<contactBookId>/segments/<segmentId>" \
-H "Authorization: Bearer $NOTIX_API_KEY"
import { Notix } from "notix-js";
const notix = new Notix(process.env.NOTIX_API_KEY);
const { data, error } = await notix.segments.get("cb_123", "seg_123");
from notix import Notix
notix = Notix() # reads NOTIX_API_KEY
segment, _ = notix.segments.get("cb_123", "seg_123")
use Notix\Notix;
$notix = new Notix(getenv('NOTIX_API_KEY'));
$segment = $notix->segments->get('cb_123', 'seg_123');
Responses
200The segment with its live count.
| Field | Type | About |
|---|---|---|
idrequired | string | |
contactBookIdrequired | string | |
namerequired | string | |
descriptionrequired | string | Can be null. |
definitionrequired | object | |
definition.versionrequired | number | One of |
definition.matchrequired | string | One of |
definition.conditionsrequired | object[] | |
countrequired | integer | Contacts that match right now. 0 while the segment has problems. |
problemsrequired | string[] | Why the segment matches nothing, such as a property removed from the contact book. |
createdAtrequired | string | |
updatedAtrequired | string |
404No segment with this id in the contact book for the calling team.
Update a segment
PATCH/v1/contactBooks/{contactBookId}/segments/{segmentId}Full access key
Change a segment's name, description or definition. A segment that a scheduled or running campaign, or an active journey, uses can be renamed but not redefined.
| Field | Type | About |
|---|---|---|
contactBookIdrequired | string | |
segmentIdrequired | string |
| Field | Type | About |
|---|---|---|
name | string | At most 80 characters. |
description | string | At most 280 characters. Can be null. |
definition | object | |
definition.versionrequired | number | One of |
definition.matchrequired | string | One of |
definition.conditionsrequired | object[] |
curl -X PATCH "https://app.usenotix.dev/api/v1/contactBooks/<contactBookId>/segments/<segmentId>" \
-H "Authorization: Bearer $NOTIX_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Engaged Pro users (30 days)"
}'
import { Notix } from "notix-js";
const notix = new Notix(process.env.NOTIX_API_KEY);
const { data, error } = await notix.segments.update("cb_123", "seg_123", { name: "Engaged Pro and Team users" });
from notix import Notix
notix = Notix() # reads NOTIX_API_KEY
segment, _ = notix.segments.update("cb_123", "seg_123", {"name": "Engaged Pro and Team users"})
use Notix\Notix;
$notix = new Notix(getenv('NOTIX_API_KEY'));
$segment = $notix->segments->update('cb_123', 'seg_123', ['name' => 'Engaged Pro and Team users']);
Responses
200The segment after the change.
| Field | Type | About |
|---|---|---|
idrequired | string | |
contactBookIdrequired | string | |
namerequired | string | |
descriptionrequired | string | Can be null. |
definitionrequired | object | |
definition.versionrequired | number | One of |
definition.matchrequired | string | One of |
definition.conditionsrequired | object[] | |
countrequired | integer | Contacts that match right now. 0 while the segment has problems. |
problemsrequired | string[] | Why the segment matches nothing, such as a property removed from the contact book. |
createdAtrequired | string | |
updatedAtrequired | string |
400The definition is not valid, or a live campaign or journey uses the segment and the definition changed.
404No segment with this id in the contact book for the calling team.
409Another segment in the contact book already has this name.
Delete a segment
DELETE/v1/contactBooks/{contactBookId}/segments/{segmentId}Full access key
Delete a segment. Refused with 400 while a scheduled or running campaign, or an active journey, uses it.
| Field | Type | About |
|---|---|---|
contactBookIdrequired | string | |
segmentIdrequired | string |
curl -X DELETE "https://app.usenotix.dev/api/v1/contactBooks/<contactBookId>/segments/<segmentId>" \
-H "Authorization: Bearer $NOTIX_API_KEY"
import { Notix } from "notix-js";
const notix = new Notix(process.env.NOTIX_API_KEY);
const { data, error } = await notix.segments.delete("cb_123", "seg_123");
from notix import Notix
notix = Notix() # reads NOTIX_API_KEY
result, _ = notix.segments.delete("cb_123", "seg_123")
use Notix\Notix;
$notix = new Notix(getenv('NOTIX_API_KEY'));
$notix->segments->delete('cb_123', 'seg_123');
Responses
200The segment was deleted.
| Field | Type | About |
|---|---|---|
idrequired | string | |
deletedrequired | boolean | One of |
400A scheduled or running campaign, or an active journey, uses the segment.
404No segment with this id in the contact book for the calling team.
List a segment's contacts
GET/v1/contactBooks/{contactBookId}/segments/{segmentId}/contactsFull access key
Page through the contacts that match a segment right now, ordered by id. Pass nextCursor back as cursor for the next page; limit is 1 to 100 (50 by default).
| Field | Type | About |
|---|---|---|
contactBookIdrequired | string | |
segmentIdrequired | string |
| Field | Type | About |
|---|---|---|
cursor | string | |
limit | integer | Contacts per page, 1 to 100. Defaults to 50. Default |
curl -X GET "https://app.usenotix.dev/api/v1/contactBooks/<contactBookId>/segments/<segmentId>/contacts" \
-H "Authorization: Bearer $NOTIX_API_KEY"
import { Notix } from "notix-js";
const notix = new Notix(process.env.NOTIX_API_KEY);
let cursor: string | undefined;
do {
const { data } = await notix.segments.contacts("cb_123", "seg_123", { cursor, limit: 100 });
data?.data.forEach((contact) => console.log(contact.email));
cursor = data?.nextCursor ?? undefined;
} while (cursor);
from notix import Notix
notix = Notix() # reads NOTIX_API_KEY
cursor = None
while True:
page, _ = notix.segments.contacts("cb_123", "seg_123", cursor=cursor, limit=100)
for contact in page["data"]:
print(contact["email"])
cursor = page["nextCursor"]
if cursor is None:
break
use Notix\Notix;
$notix = new Notix(getenv('NOTIX_API_KEY'));
$cursor = null;
do {
$page = $notix->segments->contacts('cb_123', 'seg_123', array_filter(['cursor' => $cursor, 'limit' => 100]));
foreach ($page['data'] as $contact) {
echo $contact['email'], PHP_EOL;
}
$cursor = $page['nextCursor'];
} while ($cursor !== null);
Responses
200A page of matching contacts ordered by id, with the cursor for the next page and the total.
| Field | Type | About |
|---|---|---|
datarequired | object[] | |
data[].idrequired | string | |
data[].emailrequired | string | |
data[].firstNamerequired | string | Can be null. |
data[].lastNamerequired | string | Can be null. |
data[].subscribedrequired | boolean | |
data[].propertiesrequired | map of any | |
data[].createdAtrequired | string | |
data[].updatedAtrequired | string | |
nextCursorrequired | string | Can be null. |
totalrequired | integer |