Create a segment
Create a live filter on a contact book.
https://app.usenotix.dev/api/v1/contactBooks/{contactBookId}/segmentsNeeds a full access key. Sending access keys cannot call this. Key permissions lists the extra rules some calls have.
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 }
]
}
]
}
}
Path parameters
Body parameters
At most 80 characters.
At most 280 characters. Can be null.
One of 1.
One of all, any.
Headers
Bearer followed by your API key.
Errors
The definition is not valid, names something the book or team does not have, or the book already has 100 segments.
No contact book with this id for the calling team.
A segment with this name already exists in the contact book.
Every error has the same shape. See all error codes.
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],
],
],
]);
{
"id": "cm1x8f3k20001qz7v5b9d2e4a",
"contactBookId": "cm1x8f3k20001qz7v5b9d2e4a",
"name": "Acme",
"description": "string",
"definition": {
"version": 1,
"match": "all",
"conditions": [
{
"type": null,
"match": null,
"conditions": null
}
]
},
"count": 1,
"problems": [
"string"
],
"createdAt": "string",
"updatedAt": "string"
}