curl --request POST \
--url https://galinum.com/api/v1/segments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"key": "<string>",
"name": "<string>",
"expression": {
"version": 1,
"root": {
"kind": "all",
"children": [
{
"kind": "field",
"field": {
"kind": "trait",
"key": "plan"
},
"op": "eq",
"value": "free"
},
{
"kind": "not",
"child": {
"kind": "event",
"event": "used_csv_export"
}
}
]
}
},
"description": "<string>",
"reason": "<string>",
"agentRunId": "<string>",
"idempotencyKey": "<string>"
}
'import requests
url = "https://galinum.com/api/v1/segments"
payload = {
"key": "<string>",
"name": "<string>",
"expression": {
"version": 1,
"root": {
"kind": "all",
"children": [
{
"kind": "field",
"field": {
"kind": "trait",
"key": "plan"
},
"op": "eq",
"value": "free"
},
{
"kind": "not",
"child": {
"kind": "event",
"event": "used_csv_export"
}
}
]
}
},
"description": "<string>",
"reason": "<string>",
"agentRunId": "<string>",
"idempotencyKey": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
key: '<string>',
name: '<string>',
expression: {
version: 1,
root: {
kind: 'all',
children: [
{kind: 'field', field: {kind: 'trait', key: 'plan'}, op: 'eq', value: 'free'},
{kind: 'not', child: {kind: 'event', event: 'used_csv_export'}}
]
}
},
description: '<string>',
reason: '<string>',
agentRunId: '<string>',
idempotencyKey: '<string>'
})
};
fetch('https://galinum.com/api/v1/segments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://galinum.com/api/v1/segments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'key' => '<string>',
'name' => '<string>',
'expression' => [
'version' => 1,
'root' => [
'kind' => 'all',
'children' => [
[
'kind' => 'field',
'field' => [
'kind' => 'trait',
'key' => 'plan'
],
'op' => 'eq',
'value' => 'free'
],
[
'kind' => 'not',
'child' => [
'kind' => 'event',
'event' => 'used_csv_export'
]
]
]
]
],
'description' => '<string>',
'reason' => '<string>',
'agentRunId' => '<string>',
'idempotencyKey' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://galinum.com/api/v1/segments"
payload := strings.NewReader("{\n \"key\": \"<string>\",\n \"name\": \"<string>\",\n \"expression\": {\n \"version\": 1,\n \"root\": {\n \"kind\": \"all\",\n \"children\": [\n {\n \"kind\": \"field\",\n \"field\": {\n \"kind\": \"trait\",\n \"key\": \"plan\"\n },\n \"op\": \"eq\",\n \"value\": \"free\"\n },\n {\n \"kind\": \"not\",\n \"child\": {\n \"kind\": \"event\",\n \"event\": \"used_csv_export\"\n }\n }\n ]\n }\n },\n \"description\": \"<string>\",\n \"reason\": \"<string>\",\n \"agentRunId\": \"<string>\",\n \"idempotencyKey\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://galinum.com/api/v1/segments")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"key\": \"<string>\",\n \"name\": \"<string>\",\n \"expression\": {\n \"version\": 1,\n \"root\": {\n \"kind\": \"all\",\n \"children\": [\n {\n \"kind\": \"field\",\n \"field\": {\n \"kind\": \"trait\",\n \"key\": \"plan\"\n },\n \"op\": \"eq\",\n \"value\": \"free\"\n },\n {\n \"kind\": \"not\",\n \"child\": {\n \"kind\": \"event\",\n \"event\": \"used_csv_export\"\n }\n }\n ]\n }\n },\n \"description\": \"<string>\",\n \"reason\": \"<string>\",\n \"agentRunId\": \"<string>\",\n \"idempotencyKey\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://galinum.com/api/v1/segments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"key\": \"<string>\",\n \"name\": \"<string>\",\n \"expression\": {\n \"version\": 1,\n \"root\": {\n \"kind\": \"all\",\n \"children\": [\n {\n \"kind\": \"field\",\n \"field\": {\n \"kind\": \"trait\",\n \"key\": \"plan\"\n },\n \"op\": \"eq\",\n \"value\": \"free\"\n },\n {\n \"kind\": \"not\",\n \"child\": {\n \"kind\": \"event\",\n \"event\": \"used_csv_export\"\n }\n }\n ]\n }\n },\n \"description\": \"<string>\",\n \"reason\": \"<string>\",\n \"agentRunId\": \"<string>\",\n \"idempotencyKey\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"segment": {
"id": "seg_5d2f0f0e-9a1b-4c1d-8e2f-3a4b5c6d7e8f",
"key": "free-users",
"name": "Free users",
"description": "<string>",
"status": "active",
"currentVersion": 123,
"currentAudienceVersionId": "<string>",
"summary": "<string>",
"createdBy": "<string>",
"createdAt": 123,
"updatedAt": 123,
"schemaVersion": 123,
"expression": {
"version": 1,
"root": {
"kind": "all",
"children": [
{
"kind": "field",
"field": {
"kind": "trait",
"key": "plan"
},
"op": "eq",
"value": "free"
},
{
"kind": "not",
"child": {
"kind": "event",
"event": "used_csv_export"
}
}
]
}
},
"expressionHash": "<string>",
"reason": "<string>"
}
}{
"segment": {
"id": "seg_5d2f0f0e-9a1b-4c1d-8e2f-3a4b5c6d7e8f",
"key": "free-users",
"name": "Free users",
"description": "<string>",
"status": "active",
"currentVersion": 123,
"currentAudienceVersionId": "<string>",
"summary": "<string>",
"createdBy": "<string>",
"createdAt": 123,
"updatedAt": 123,
"schemaVersion": 123,
"expression": {
"version": 1,
"root": {
"kind": "all",
"children": [
{
"kind": "field",
"field": {
"kind": "trait",
"key": "plan"
},
"op": "eq",
"value": "free"
},
{
"kind": "not",
"child": {
"kind": "event",
"event": "used_csv_export"
}
}
]
}
},
"expressionHash": "<string>",
"reason": "<string>"
}
}{
"error": "<string>",
"diagnostics": [
{
"severity": "error",
"code": "unobserved_event",
"path": "/root/children/1",
"message": "<string>",
"suggestions": [
"<string>"
]
}
]
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}Create a segment
Creates a reusable named segment from a checked audience expression; version 1 is created atomically. Check the expression first with POST /api/v1/audiences/check. Pass idempotencyKey so retries return the original segment (200) instead of erroring; without one, a duplicate machine key is a 409.
curl --request POST \
--url https://galinum.com/api/v1/segments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"key": "<string>",
"name": "<string>",
"expression": {
"version": 1,
"root": {
"kind": "all",
"children": [
{
"kind": "field",
"field": {
"kind": "trait",
"key": "plan"
},
"op": "eq",
"value": "free"
},
{
"kind": "not",
"child": {
"kind": "event",
"event": "used_csv_export"
}
}
]
}
},
"description": "<string>",
"reason": "<string>",
"agentRunId": "<string>",
"idempotencyKey": "<string>"
}
'import requests
url = "https://galinum.com/api/v1/segments"
payload = {
"key": "<string>",
"name": "<string>",
"expression": {
"version": 1,
"root": {
"kind": "all",
"children": [
{
"kind": "field",
"field": {
"kind": "trait",
"key": "plan"
},
"op": "eq",
"value": "free"
},
{
"kind": "not",
"child": {
"kind": "event",
"event": "used_csv_export"
}
}
]
}
},
"description": "<string>",
"reason": "<string>",
"agentRunId": "<string>",
"idempotencyKey": "<string>"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
key: '<string>',
name: '<string>',
expression: {
version: 1,
root: {
kind: 'all',
children: [
{kind: 'field', field: {kind: 'trait', key: 'plan'}, op: 'eq', value: 'free'},
{kind: 'not', child: {kind: 'event', event: 'used_csv_export'}}
]
}
},
description: '<string>',
reason: '<string>',
agentRunId: '<string>',
idempotencyKey: '<string>'
})
};
fetch('https://galinum.com/api/v1/segments', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://galinum.com/api/v1/segments",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'key' => '<string>',
'name' => '<string>',
'expression' => [
'version' => 1,
'root' => [
'kind' => 'all',
'children' => [
[
'kind' => 'field',
'field' => [
'kind' => 'trait',
'key' => 'plan'
],
'op' => 'eq',
'value' => 'free'
],
[
'kind' => 'not',
'child' => [
'kind' => 'event',
'event' => 'used_csv_export'
]
]
]
]
],
'description' => '<string>',
'reason' => '<string>',
'agentRunId' => '<string>',
'idempotencyKey' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://galinum.com/api/v1/segments"
payload := strings.NewReader("{\n \"key\": \"<string>\",\n \"name\": \"<string>\",\n \"expression\": {\n \"version\": 1,\n \"root\": {\n \"kind\": \"all\",\n \"children\": [\n {\n \"kind\": \"field\",\n \"field\": {\n \"kind\": \"trait\",\n \"key\": \"plan\"\n },\n \"op\": \"eq\",\n \"value\": \"free\"\n },\n {\n \"kind\": \"not\",\n \"child\": {\n \"kind\": \"event\",\n \"event\": \"used_csv_export\"\n }\n }\n ]\n }\n },\n \"description\": \"<string>\",\n \"reason\": \"<string>\",\n \"agentRunId\": \"<string>\",\n \"idempotencyKey\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://galinum.com/api/v1/segments")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"key\": \"<string>\",\n \"name\": \"<string>\",\n \"expression\": {\n \"version\": 1,\n \"root\": {\n \"kind\": \"all\",\n \"children\": [\n {\n \"kind\": \"field\",\n \"field\": {\n \"kind\": \"trait\",\n \"key\": \"plan\"\n },\n \"op\": \"eq\",\n \"value\": \"free\"\n },\n {\n \"kind\": \"not\",\n \"child\": {\n \"kind\": \"event\",\n \"event\": \"used_csv_export\"\n }\n }\n ]\n }\n },\n \"description\": \"<string>\",\n \"reason\": \"<string>\",\n \"agentRunId\": \"<string>\",\n \"idempotencyKey\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://galinum.com/api/v1/segments")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"key\": \"<string>\",\n \"name\": \"<string>\",\n \"expression\": {\n \"version\": 1,\n \"root\": {\n \"kind\": \"all\",\n \"children\": [\n {\n \"kind\": \"field\",\n \"field\": {\n \"kind\": \"trait\",\n \"key\": \"plan\"\n },\n \"op\": \"eq\",\n \"value\": \"free\"\n },\n {\n \"kind\": \"not\",\n \"child\": {\n \"kind\": \"event\",\n \"event\": \"used_csv_export\"\n }\n }\n ]\n }\n },\n \"description\": \"<string>\",\n \"reason\": \"<string>\",\n \"agentRunId\": \"<string>\",\n \"idempotencyKey\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"segment": {
"id": "seg_5d2f0f0e-9a1b-4c1d-8e2f-3a4b5c6d7e8f",
"key": "free-users",
"name": "Free users",
"description": "<string>",
"status": "active",
"currentVersion": 123,
"currentAudienceVersionId": "<string>",
"summary": "<string>",
"createdBy": "<string>",
"createdAt": 123,
"updatedAt": 123,
"schemaVersion": 123,
"expression": {
"version": 1,
"root": {
"kind": "all",
"children": [
{
"kind": "field",
"field": {
"kind": "trait",
"key": "plan"
},
"op": "eq",
"value": "free"
},
{
"kind": "not",
"child": {
"kind": "event",
"event": "used_csv_export"
}
}
]
}
},
"expressionHash": "<string>",
"reason": "<string>"
}
}{
"segment": {
"id": "seg_5d2f0f0e-9a1b-4c1d-8e2f-3a4b5c6d7e8f",
"key": "free-users",
"name": "Free users",
"description": "<string>",
"status": "active",
"currentVersion": 123,
"currentAudienceVersionId": "<string>",
"summary": "<string>",
"createdBy": "<string>",
"createdAt": 123,
"updatedAt": 123,
"schemaVersion": 123,
"expression": {
"version": 1,
"root": {
"kind": "all",
"children": [
{
"kind": "field",
"field": {
"kind": "trait",
"key": "plan"
},
"op": "eq",
"value": "free"
},
{
"kind": "not",
"child": {
"kind": "event",
"event": "used_csv_export"
}
}
]
}
},
"expressionHash": "<string>",
"reason": "<string>"
}
}{
"error": "<string>",
"diagnostics": [
{
"severity": "error",
"code": "unobserved_event",
"path": "/root/children/1",
"message": "<string>",
"suggestions": [
"<string>"
]
}
]
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}Authorizations
Your project's secret key (pk_…, without the pub segment). Server-side only — never ship it to a browser. Get it from Settings → Projects in the dashboard.
Body
Stable machine key, unique within the project: lowercase letters, digits, hyphens, underscores; must not start with "seg_" (reserved for opaque ids).
64^[a-z0-9](?:[a-z0-9_-]*[a-z0-9])?$80Versioned, strictly validated audience rule. Example: { "version": 1, "root": { "kind": "all", "children": [ { "kind": "field", "field": { "kind": "trait", "key": "plan" }, "op": "eq", "value": "free" }, { "kind": "not", "child": { "kind": "event", "event": "used_csv_export" } } ] } }
Show child attributes
Show child attributes
{
"version": 1,
"root": {
"kind": "all",
"children": [
{
"kind": "field",
"field": { "kind": "trait", "key": "plan" },
"op": "eq",
"value": "free"
},
{
"kind": "not",
"child": {
"kind": "event",
"event": "used_csv_export"
}
}
]
}
}
The audience's intent.
1000Why this segment/version exists; stored on version 1.
500Originating agent run in this project (400 if it belongs elsewhere).
1Retry-safety token: the same project + key always returns the originally created segment.
128Response
Idempotent replay — the segment this idempotencyKey originally created.
Show child attributes
Show child attributes