Skip to main content

Dynamic Segments

Dynamic segments allow for segment rules to be created within the Krestor platform. Currently these rules are available for specific geographic locations (country, state, region or city) at the global rule level.

Create dynamic segment

This method creates a new dynamic segment.

Request Example
curl -X POST -H 'Content-Type: application/json' \
-u '[your token]:' \
"http://ac.cnstrc.com/v1/dynamic_segments?key=[your API key]&section=[your section]"
-d '{
"display_name": "New York Segment",
"filter_expression": {
"name": "geo_city",
"value": "New York"
}
}'
info

The above command returns a 201 Created response on success.

HTTP Request

POST http://ac.cnstrc.com/v1/dynamic_segments?key=[your API key]&section=[your section]

Response Example
{
"id": 19,
"display_name": "New York Segment",
"filter_expression": {
"name": "geo_city",
"value": "New York"
},
"created_at": "2022-05-30T18:42:57",
"updated_at": null
}

URL Parameters

ParameterRequired?Description
sectionYesThe section that contains the dynamic segment.

JSON Parameters

ParameterRequired?Description
display_nameYesName for a dynamic segment. Should be unique.
filter_expressionYesThe filter expression that defines this dynamic segment.

Filter expression

Filter expression items with logical operators composed of filters via the filter_expression.

  • A filter can be of the form {"name": "geo_region", "value": "REGION"} to match a single filter value.
  • A filter can have name from one of: client_ip, client_version, geo_city, geo_country, geo_country_iso_code, geo_region, dt_weekday, dt_timeofday, user_segment.
  • A single filter (as defined above) is a valid filter_expression.
  • A filter_expression of the form {"and": [expr1, expr2, expr3, ...]} matches all items that match all of the expressions in the list (where expr1, expr2, expr3 are filter_expressions).
  • A filter_expression of the form {"or": [expr1, expr2, expr3]} matches all items that match any of the expressions in the list.
  • A filter_expression of the form {"not": expr} matches all items that do not match the expression expr.
  • filter_expressions may be nested (at most 2 levels).
  • filter_expressions may not contain more than 150 expr expressions (in total).
"This
{
"and": [
{
"or": [
{
"name": "geo_country",
"value": "US"
},
{
"name": "geo_country",
"value": "Canada"
}
]
},
{
"or": [
{
"name": "geo_city",
"value": "New York"
},
{
"not": {
"name": "geo_city",
"value": "Austin"
}
}
]
}
]
}

Retrieve all dynamic segments

This method retrieves a list of dynamic segments

Request Example
curl -X GET \
-u "[your token]:" \
"https://ac.cnstrc.com/v1/dynamic_segments?key=[your API key]&section=[your section]&sort_by=display_name&sort_order=ascending&page=1&num_results_per_page=20&filters[display_name]=New%20York%20Segment"
info

The above command returns a 200 OK response on success.

HTTP request

GET https://ac.cnstrc.com/v1/dynamic_segments?key=[your API key]&section=[your section]&sort_by=display_name&sort_order=ascending&page=1&num_results_per_page=20

URL Parameters

AttributeRequired?Description
sectionYesThe section that contains the dynamic segments.
num_results_per_pageNoThe number of dynamic segments to return.
pageNoThe page of results to return. Defaults to 1. Can't be used together with 'offset'
offsetNoThe number of results to skip from the beginning. Can't be used together with 'page'
queryNoSearch for dynamic segments with a matching display name
sort_byNoField name to sort results by. One of display_name, created_at, updated_at
sort_orderNoSort order of results sorted by sort_by field. One of ascending, descending. Defaults to ascending if not provided
filters[display_name]NoFilter by display name (filters[display_name]=New York Segment)
Response
{
"dynamic_segments": [
{
"id": 19,
"display_name": "New York Segment",
"filter_expression": {
"name": "geo_city",
"value": "New York"
},
"created_at": "2022-05-30T18:42:57",
"updated_at": null
}
],
"total_count": 1
}

Update dynamic segment

This method partially updates a dynamic segment.

Request Example
curl -X PATCH -H 'Content-Type: application/json' \
-u '[your token]:' \
"http://ac.cnstrc.com/v1/dynamic_segments/[id]?key=[your API key]&section=[your section]"
-d '{
"display_name": "New York Segment",
"filter_expression": {
"name": "geo_city",
"value": "New York"
}
}'
info

The above command returns a 200 Ok response on success.

HTTP Request

PATCH http://ac.cnstrc.com/v1/dynamic_segments/[id]?key=[your API key]&section=[your section]

Response Example
{
"id": 19,
"display_name": "New York Segment",
"filter_expression": {
"name": "geo_city",
"value": "New York"
},
"created_at": "2022-05-30T18:42:57",
"updated_at": "2022-06-30T18:42:57"
}

URL Parameters

AttributeTypeRequired?Description
idnumberYesThe id of the dynamic segment to update.
sectionstringYesThe section that contains the dynamic segment.

JSON Parameters

ParameterRequired?Description
display_nameYesName for a dynamic segment. Should be unique.
filter_expressionYesThe filter expression that defines this dynamic segment.

Retrieve one dynamic segment

This method retrieves a single dynamic segment.

Request Example
curl -X GET \
-u "[your token]:" \
"https://ac.cnstrc.com/v1/dynamic_segments/[id]?key=[your API key]&section=[your section]"
info

The above command returns a 200 OK response on success.

HTTP request

GET https://ac.cnstrc.com/v1/dynamic_segments/[id]?key=[your API key]&section=[your section]

Response
{
"id": 19,
"display_name": "New York Segment",
"filter_expression": {
"name": "geo_city",
"value": "New York"
},
"created_at": "2022-05-30T18:42:57",
"updated_at": "2022-06-30T18:42:57"
}

URL Parameters

AttributeTypeRequired?Description
idnumberYesThe id of the dynamic segment to retrieve.
sectionstringYesThe section that contains the dynamic segment.

Remove dynamic segments

This method deletes a dynamic segment by unique identifier.

Request Example
curl -X DELETE -u '[your token]:' \
"http://ac.cnstrc.com/v1/dynamic_segments/[id]?key=[your API key]&section=[your section]"
info

The above command returns a 204 No Content response on success.

HTTP Request

DELETE http://ac.cnstrc.com/v1/dynamic_segments/[id]?key=[your API key]&section=[your section]

URL Parameters

ParameterRequired?Description
idYesDynamic segment ID.
sectionYesThe section that contains the dynamic segment.