Skip to content

Create a segment

POST
https://api.getsitecontrol.com/v1/sites/{site_id}/segments
curl --request POST \
--url https://api.getsitecontrol.com/v1/sites/1/segments \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "name": "example", "conditions": { "op": "and", "args": [ { "op": "and", "args": [ { "op": "=", "args": [ "{{$contact.isSubscribed}}", "S" ] }, { "op": "ina", "args": [ "{{$contact.tags}}", [ 12, 15 ] ] } ] }, { "op": "or", "args": [ { "op": ">", "args": [ "{{$contact.date}}", "2026-01-01" ] }, { "op": "in", "args": [ "{{$contact.email}}", "@example.com" ] } ] } ] } }'

Creates a segment from a name and conditions, a tree of op/args nodes in the admin’s condition language described with the conditions field, and returns it. The segment is created in General, folder.id 0. Names need not be unique, so a repeated call creates another segment. Use segment_id of the result with list_contacts.

FieldDescription
site_id
required
Site Id
integer
FieldDescription
Idempotency-Key
Idempotency-Key

Makes a retry of a POST safe: a repeat with the same key, body and GSC-Version returns the stored response with Idempotency-Replayed: true instead of running again. The key protects against repeated execution while the key store works. Saving the change and storing the response under the key are not atomic: if the process or the key store fails between them, the change is kept, the key is released after 15 minutes and a retry runs the request again. After a timeout or a 5xx, read the resource to check the result before retrying. 5xx and 429 responses and responses over 256 KB are not stored, so a repeat runs the request again. A key is kept for 24 hours. The same key with another body or version is 422; a repeat while the first request runs is 409.

string
>= 1 characters <= 128 characters /^[A-Za-z0-9_-]+$/

Makes a retry of a POST safe: a repeat with the same key, body and GSC-Version returns the stored response with Idempotency-Replayed: true instead of running again. The key protects against repeated execution while the key store works. Saving the change and storing the response under the key are not atomic: if the process or the key store fails between them, the change is kept, the key is released after 15 minutes and a retry runs the request again. After a timeout or a 5xx, read the resource to check the result before retrying. 5xx and 429 responses and responses over 256 KB are not stored, so a repeat runs the request again. A key is kept for 24 hours. The same key with another body or version is 422; a repeat while the first request runs is 409.

Media typeapplication/json
SegmentCreate
object
FieldDescription
name
required
Name

Name; surrounding spaces are trimmed, need not be unique

string
>= 1 characters <= 500 characters
conditions
required
Conditions

Which contacts belong to the segment: a tree of conditions, applied to the contacts as they are at the moment it is used.

Conditions are the condition language of the Getsitecontrol admin, with its own variable names and codes; they are not the field names and values of Contact. A segment written here can be edited in the admin, and the variables below are the ones the admin’s condition editor offers.

A node is an object with exactly op and args. A group has op and or or and nodes in args; a leaf has the variable {{$contact.<name>}} as the first argument, then its values: none for * (is set) and undefined (is not set), two for between and !between, one for the rest. To negate, use the opposite operator; there is no not node.

The admin editor shows a root group whose args are groups, each holding leaves, as in the example; write that shape so the segment stays editable there. {"op": "and", "args": []} matches every contact of the site. Conditions are saved as sent.

Values are integers, strings or, for ina and !ina, a list of them.

OperatorMeaning
=, !=equals, differs
ina, !inaany of the list, none of it
<, >, between, !betweencompare; between includes both ends
^, $, in, match (and !-forms)starts with, ends with, contains, wildcard * without case
*, undefinedis set, is not set

Text operators other than match are case sensitive, except on $contact.email: a contact’s email is stored lowercase and compared without case by every operator. In ^, $, in, match and their negations _ matches any single character and % is a plain character.

VariableOperatorsValue
$contact.email, phone, firstName, lastNametext operators, =, !=, ina, !ina, *, undefinedstring
$contact.country=, !=, ina, !ina, *, undefinedISO 3166-1 alpha-2, upper case
$contact.date=, !=, <, >, between, !between, *, undefineddate the contact was added
$contact.isSubscribed=marketing status: S subscribed, U unsubscribed, B bounced
$contact.emailQuality=, !=, ina, !ina, *, undefinedCorp+, Corp corporate, Pers+, Pers personal (+ is the higher grade), Edu education, Gov government, Risk risky, Temp disposable, Unk unknown
$contact.tags=, !=, ina, !ina, *, undefinedtag ids from list_tags
$contact.segments=, !=, ina, !inaids from list_segments, as integers
$contact.emailSend, emailOpen, emailClick=, !=, ina, !ina, *, undefinede-mail id, as email_id of a broadcast
$contact.emailSendCount, emailOpenCount, emailClickCount=, !=, <, >, between, !between, *, undefinedinteger, not negative
$contact.emailSendDate, emailOpenDate, emailClickDateas $contact.datethe latest event
$contact.$shopifySpent, $shopifyOrdersas the countsinteger
$contact.$shopifyOrderDateas $contact.datethe latest order
$contact.<field id>by the field type from list_contact_fields: text, integer, number, date or datetimeas the field; boolean and other fields are refused

ina and !ina on tags and segments take at least one id. On $contact.tags, = means the contact has that tag among its tags.

$contact.isSubscribed compares the stored status code as the admin does: S does not match a contact who confirmed double opt-in, U does not match one who never subscribed or awaits double opt-in, and B matches every bounced contact. The contact statuses subscribed, unsubscribed and bounced are the broader groups.

Ids are integers or strings of digits. A number is a 32-bit integer or a string holding one. A date is YYYY-MM-DD or ISO 8601 with an offset. For $contact.date, $shopifyOrderDate and datetime fields, a value at midnight is a whole day: = and != cover the day, and the second value of between runs to its end. Date fields and $contact.email*Date compare with midnight exactly.

Nested segments may not form a cycle. A list must reference each nested segment once, and not one nested inside another.

Conditions are checked the way they run: nested segments must exist and the whole tree must compile, so an unknown variable or a value of the wrong type is refused. Conditions saved in the admin are returned as they are and may use other variables and values.

Example

{
"op": "and",
"args": [
{
"op": "and",
"args": [
{
"op": "=",
"args": [
"{{$contact.isSubscribed}}",
"S"
]
},
{
"op": "ina",
"args": [
"{{$contact.tags}}",
[
12,
15
]
]
}
]
},
{
"op": "or",
"args": [
{
"op": ">",
"args": [
"{{$contact.date}}",
"2026-01-01"
]
},
{
"op": "in",
"args": [
"{{$contact.email}}",
"@example.com"
]
}
]
}
]
}

Successful Response

Media typeapplication/json
Segment
object
FieldDescription
id
required
Id

Segment id; list_contacts takes it as segment_id

integer
name
required
Name

Name; several segments may share one

string
conditions
required
Conditions

Which contacts belong to the segment: a tree of conditions, applied to the contacts as they are at the moment it is used.

Conditions are the condition language of the Getsitecontrol admin, with its own variable names and codes; they are not the field names and values of Contact. A segment written here can be edited in the admin, and the variables below are the ones the admin’s condition editor offers.

A node is an object with exactly op and args. A group has op and or or and nodes in args; a leaf has the variable {{$contact.<name>}} as the first argument, then its values: none for * (is set) and undefined (is not set), two for between and !between, one for the rest. To negate, use the opposite operator; there is no not node.

The admin editor shows a root group whose args are groups, each holding leaves, as in the example; write that shape so the segment stays editable there. {"op": "and", "args": []} matches every contact of the site. Conditions are saved as sent.

Values are integers, strings or, for ina and !ina, a list of them.

OperatorMeaning
=, !=equals, differs
ina, !inaany of the list, none of it
<, >, between, !betweencompare; between includes both ends
^, $, in, match (and !-forms)starts with, ends with, contains, wildcard * without case
*, undefinedis set, is not set

Text operators other than match are case sensitive, except on $contact.email: a contact’s email is stored lowercase and compared without case by every operator. In ^, $, in, match and their negations _ matches any single character and % is a plain character.

VariableOperatorsValue
$contact.email, phone, firstName, lastNametext operators, =, !=, ina, !ina, *, undefinedstring
$contact.country=, !=, ina, !ina, *, undefinedISO 3166-1 alpha-2, upper case
$contact.date=, !=, <, >, between, !between, *, undefineddate the contact was added
$contact.isSubscribed=marketing status: S subscribed, U unsubscribed, B bounced
$contact.emailQuality=, !=, ina, !ina, *, undefinedCorp+, Corp corporate, Pers+, Pers personal (+ is the higher grade), Edu education, Gov government, Risk risky, Temp disposable, Unk unknown
$contact.tags=, !=, ina, !ina, *, undefinedtag ids from list_tags
$contact.segments=, !=, ina, !inaids from list_segments, as integers
$contact.emailSend, emailOpen, emailClick=, !=, ina, !ina, *, undefinede-mail id, as email_id of a broadcast
$contact.emailSendCount, emailOpenCount, emailClickCount=, !=, <, >, between, !between, *, undefinedinteger, not negative
$contact.emailSendDate, emailOpenDate, emailClickDateas $contact.datethe latest event
$contact.$shopifySpent, $shopifyOrdersas the countsinteger
$contact.$shopifyOrderDateas $contact.datethe latest order
$contact.<field id>by the field type from list_contact_fields: text, integer, number, date or datetimeas the field; boolean and other fields are refused

ina and !ina on tags and segments take at least one id. On $contact.tags, = means the contact has that tag among its tags.

$contact.isSubscribed compares the stored status code as the admin does: S does not match a contact who confirmed double opt-in, U does not match one who never subscribed or awaits double opt-in, and B matches every bounced contact. The contact statuses subscribed, unsubscribed and bounced are the broader groups.

Ids are integers or strings of digits. A number is a 32-bit integer or a string holding one. A date is YYYY-MM-DD or ISO 8601 with an offset. For $contact.date, $shopifyOrderDate and datetime fields, a value at midnight is a whole day: = and != cover the day, and the second value of between runs to its end. Date fields and $contact.email*Date compare with midnight exactly.

Nested segments may not form a cycle. A list must reference each nested segment once, and not one nested inside another.

Conditions are checked the way they run: nested segments must exist and the whole tree must compile, so an unknown variable or a value of the wrong type is refused. Conditions saved in the admin are returned as they are and may use other variables and values.

object
folder
required
Folder

Folder the segment is in; folders come from list_folders

object
FieldDescription
id
required
Id

0 is General, where items outside any folder are

integer
name
required
Name
string
created_at
required
Created At
string format: date-time
updated_at
required
Updated At

A move to another folder does not change it

string format: date-time

Example

{
"conditions": {
"op": "and",
"args": [
{
"op": "and",
"args": [
{
"op": "=",
"args": [
"{{$contact.isSubscribed}}",
"S"
]
},
{
"op": "ina",
"args": [
"{{$contact.tags}}",
[
12,
15
]
]
}
]
},
{
"op": "or",
"args": [
{
"op": ">",
"args": [
"{{$contact.date}}",
"2026-01-01"
]
},
{
"op": "in",
"args": [
"{{$contact.email}}",
"@example.com"
]
}
]
}
]
}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds

Idempotency-Replayed
string

True when the response is a stored one, replayed

Unsupported GSC-Version

Media typeapplication/problem+json
Problem

The documented shape of every error body on the versioned surface.

object
FieldDescription
type
required
Type
string
title
required
Title
string
status
required
Status
integer
detail
Detail
string
nullable
instance
required
Instance
string
reason
Reason
string
nullable
next
Next
string
nullable
request_id
required
Request Id
string
errors
Errors
Array<object>
nullable
ValidationIssue
object
FieldDescription
loc
required
Loc
Array
msg
required
Msg
string
type
required
Type
string
metadata
Metadata
object

Example · Generated

{
"type": "example",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"reason": "example",
"next": "example",
"request_id": "example",
"errors": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
],
"metadata": {}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds

Missing or invalid API key or access token

Media typeapplication/problem+json
Problem

The documented shape of every error body on the versioned surface.

object
FieldDescription
type
required
Type
string
title
required
Title
string
status
required
Status
integer
detail
Detail
string
nullable
instance
required
Instance
string
reason
Reason
string
nullable
next
Next
string
nullable
request_id
required
Request Id
string
errors
Errors
Array<object>
nullable
ValidationIssue
object
FieldDescription
loc
required
Loc
Array
msg
required
Msg
string
type
required
Type
string
metadata
Metadata
object

Example · Generated

{
"type": "example",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"reason": "example",
"next": "example",
"request_id": "example",
"errors": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
],
"metadata": {}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds

WWW-Authenticate
string

Authentication scheme: Bearer

Access denied

Media typeapplication/problem+json
Problem

The documented shape of every error body on the versioned surface.

object
FieldDescription
type
required
Type
string
title
required
Title
string
status
required
Status
integer
detail
Detail
string
nullable
instance
required
Instance
string
reason
Reason
string
nullable
next
Next
string
nullable
request_id
required
Request Id
string
errors
Errors
Array<object>
nullable
ValidationIssue
object
FieldDescription
loc
required
Loc
Array
msg
required
Msg
string
type
required
Type
string
metadata
Metadata
object

Example · Generated

{
"type": "example",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"reason": "example",
"next": "example",
"request_id": "example",
"errors": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
],
"metadata": {}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds

Not found

Media typeapplication/problem+json
Problem

The documented shape of every error body on the versioned surface.

object
FieldDescription
type
required
Type
string
title
required
Title
string
status
required
Status
integer
detail
Detail
string
nullable
instance
required
Instance
string
reason
Reason
string
nullable
next
Next
string
nullable
request_id
required
Request Id
string
errors
Errors
Array<object>
nullable
ValidationIssue
object
FieldDescription
loc
required
Loc
Array
msg
required
Msg
string
type
required
Type
string
metadata
Metadata
object

Example · Generated

{
"type": "example",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"reason": "example",
"next": "example",
"request_id": "example",
"errors": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
],
"metadata": {}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds

Conflict

Media typeapplication/problem+json
Problem

The documented shape of every error body on the versioned surface.

object
FieldDescription
type
required
Type
string
title
required
Title
string
status
required
Status
integer
detail
Detail
string
nullable
instance
required
Instance
string
reason
Reason
string
nullable
next
Next
string
nullable
request_id
required
Request Id
string
errors
Errors
Array<object>
nullable
ValidationIssue
object
FieldDescription
loc
required
Loc
Array
msg
required
Msg
string
type
required
Type
string
metadata
Metadata
object

Example · Generated

{
"type": "example",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"reason": "example",
"next": "example",
"request_id": "example",
"errors": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
],
"metadata": {}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds

Request body too large

Media typeapplication/problem+json
Problem

The documented shape of every error body on the versioned surface.

object
FieldDescription
type
required
Type
string
title
required
Title
string
status
required
Status
integer
detail
Detail
string
nullable
instance
required
Instance
string
reason
Reason
string
nullable
next
Next
string
nullable
request_id
required
Request Id
string
errors
Errors
Array<object>
nullable
ValidationIssue
object
FieldDescription
loc
required
Loc
Array
msg
required
Msg
string
type
required
Type
string
metadata
Metadata
object

Example · Generated

{
"type": "example",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"reason": "example",
"next": "example",
"request_id": "example",
"errors": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
],
"metadata": {}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds

Media typeapplication/problem+json

segment_conditions_invalid: the conditions cannot run. metadata.problem says why: reference_not_found (a nested segment does not exist), segment_cycle (nested segments form a cycle or repeat in one list), not_compilable (an unknown variable, operator or value). validation_failed: the body itself is malformed

Problem

The documented shape of every error body on the versioned surface.

object
FieldDescription
type
required
Type
string
title
required
Title
string
status
required
Status
integer
detail
Detail
string
nullable
instance
required
Instance
string
reason
Reason
string
nullable
next
Next
string
nullable
request_id
required
Request Id
string
errors
Errors
Array<object>
nullable
ValidationIssue
object
FieldDescription
loc
required
Loc
Array
msg
required
Msg
string
type
required
Type
string
metadata
Metadata
object

Example · Generated

{
"type": "example",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"reason": "example",
"next": "example",
"request_id": "example",
"errors": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
],
"metadata": {}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds

Rate limited

Media typeapplication/problem+json
Problem

The documented shape of every error body on the versioned surface.

object
FieldDescription
type
required
Type
string
title
required
Title
string
status
required
Status
integer
detail
Detail
string
nullable
instance
required
Instance
string
reason
Reason
string
nullable
next
Next
string
nullable
request_id
required
Request Id
string
errors
Errors
Array<object>
nullable
ValidationIssue
object
FieldDescription
loc
required
Loc
Array
msg
required
Msg
string
type
required
Type
string
metadata
Metadata
object

Example · Generated

{
"type": "example",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"reason": "example",
"next": "example",
"request_id": "example",
"errors": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
],
"metadata": {}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds

Retry-After
integer

Seconds until the bucket refills

Temporarily unavailable; retry later

Media typeapplication/problem+json
Problem

The documented shape of every error body on the versioned surface.

object
FieldDescription
type
required
Type
string
title
required
Title
string
status
required
Status
integer
detail
Detail
string
nullable
instance
required
Instance
string
reason
Reason
string
nullable
next
Next
string
nullable
request_id
required
Request Id
string
errors
Errors
Array<object>
nullable
ValidationIssue
object
FieldDescription
loc
required
Loc
Array
msg
required
Msg
string
type
required
Type
string
metadata
Metadata
object

Example · Generated

{
"type": "example",
"title": "example",
"status": 1,
"detail": "example",
"instance": "example",
"reason": "example",
"next": "example",
"request_id": "example",
"errors": [
{
"loc": [
"example"
],
"msg": "example",
"type": "example"
}
],
"metadata": {}
}
FieldDescription
GSC-Version
string

API version the response was produced for

X-Request-Id
string

Request id, echoed from the request when valid

X-RateLimit-Limit
integer

Limit of the tightest bucket

X-RateLimit-Remaining
integer

Requests left in its window

X-RateLimit-Reset
integer

End of its window, epoch seconds