Segments
Segments are logical separations of Cerkl Subscribers, similar in concept to distribution lists. Subscribers can be part of one segment, multiple segments, or no segments at all. You may notice that the Cerkl application offers users the ability to create Dynamic Segments with rulesets that allow you to include Subscribers that meet certain criteria. Importantly, only "normal", non-dynamic Segments can be created via the API.
Creating a Segment
Creating a Segment can be done by making a
$ curl --request POST 'api.cerkl.com/v3/segment' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \
--data-raw '{
"template": {
"version": "3.0",
"data": [
{
"description": "Engineers",
"external_id": "12345"
}
]
}
}'
Retrieving Existing Segments
Once created successfully, the response body from the API will contain the Segment's data, including the
$ curl --request GET 'api.cerkl.com/v3/segment' \
--header 'Authorization: Bearer {ACCESS_TOKEN}'
To get a specific existing Segment, use the
$ curl --request GET 'api.cerkl.com/v3/segment/558904' \
--header 'Authorization: Bearer {ACCESS_TOKEN}'
As with other Cerkl data, Segments can be filtered by the values in their fields to search for those that meet certain
criteria. Check out our API Reference for more details on searchable fields. As an example, here's how you
can find all of your Segments that have been updated since
$ curl -G 'api.cerkl.com/v3/segment' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \
--data-urlencode 'filters_json={"date_modified_utc": {"gt": "2020-07-16 00:00:00"}}'
Adding Subscribers to a Segment
Adding Subscribers to Segments is done by making a
For example, where the
$ curl --request POST 'api.cerkl.com/v3/segment/12345/subscriber' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \
--data-raw '{
"template": {
"version": "3.0",
"data": [
{
"id": 98765
}
]
}
}'
Note: only one Subscriber can be added to a Segment at a time using this method.
Getting All Subscribers in a Segment
If you need to retrieve all of the Subscribers associated with a particular Segment, just use a
For instance, if you want to get all of your organization's Subscribers in a Segment with an
$ curl --request GET 'api.cerkl.com/v3/segment/12345/subscriber' \
--header 'Authorization: Bearer {ACCESS_TOKEN}'
Removing Subscribers From a Segment
To remove Subscribers from a Segment, use a
For example, where
$ curl --request DELETE 'api.cerkl.com/v3/segment/12345/subscriber/98765' \
--header 'Authorization: Bearer {ACCESS_TOKEN}'
Updating a Segment
Segment information (
$ curl --request PUT 'api.cerkl.com/v3/segment/558904' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {ACCESS_TOKEN}' \
--data-raw '{
"template": {
"version": "3.0",
"data": [
{
"description": "New Segment Name",
"external_id": "new_external_id"
}
]
}
}'
Deleting a Segment
Deleting a Segment only requires the Segment's
$ curl --location --request DELETE 'api.cerkl.com/v3/segment/558904' \
--header 'Authorization: Bearer {ACCESS_TOKEN}'
Note: deleting a Segment does not delete Subscribers.