Create segment
Save a segment under Messaging > Segments from criteria joined with and or or.
POST https://cotlet.dev/api/v1/postscript/segments
Saves a segment from the criteria you give, each as a criterion name from the Segments editor, a parameter such as equals or before last, and a value. join is and or or and links an item to the one before it; the first item has none. Returns the Segment Size Postscript computes. It messages nobody and only saves the definition, so it does not wait for your OK. include_phone_only adds subscribers not yet linked to a Shopify customer, and purchase filters do not apply to them.
Parameters
| Name | Type | Description |
|---|---|---|
| name string required | string | Segment name. |
| criteria array required | array | List of {criterion, parameter, value, join}. join is and or or, absent on the first item. |
| include_phone_only boolean | boolean | Include all phone-only subscribers. Default: false. |
Request
curl -X POST https://cotlet.dev/api/v1/postscript/segments \
-H "Authorization: Bearer $COTLET_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name":"Unengaged 180 days","include_phone_only":false,"criteria":[{"criterion":"Number of Orders","parameter":"equals","value":"0"},{"join":"or","criterion":"Last Order Date","parameter":"before last","value":"365 days"},{"join":"and","criterion":"Subscriber Has Clicked","parameter":"not equal to","value":"TRUE"},{"join":"and","criterion":"Subscriber Created Date","parameter":"before last","value":"180 days"},{"join":"and","criterion":"Number of Replies","parameter":"equals","value":"0"}]}' result = client.call("postscript", "create_segment", {"name":"Unengaged 180 days","include_phone_only":False,"criteria":[{"criterion":"Number of Orders","parameter":"equals","value":"0"},{"join":"or","criterion":"Last Order Date","parameter":"before last","value":"365 days"},{"join":"and","criterion":"Subscriber Has Clicked","parameter":"not equal to","value":"TRUE"},{"join":"and","criterion":"Subscriber Created Date","parameter":"before last","value":"180 days"},{"join":"and","criterion":"Number of Replies","parameter":"equals","value":"0"}]}) const result = await cotlet.call('postscript', 'create_segment', {"name":"Unengaged 180 days","include_phone_only":false,"criteria":[{"criterion":"Number of Orders","parameter":"equals","value":"0"},{"join":"or","criterion":"Last Order Date","parameter":"before last","value":"365 days"},{"join":"and","criterion":"Subscriber Has Clicked","parameter":"not equal to","value":"TRUE"},{"join":"and","criterion":"Subscriber Created Date","parameter":"before last","value":"180 days"},{"join":"and","criterion":"Number of Replies","parameter":"equals","value":"0"}]}); cotlet call postscript create_segment --data '{"name":"Unengaged 180 days","include_phone_only":false,"criteria":[{"criterion":"Number of Orders","parameter":"equals","value":"0"},{"join":"or","criterion":"Last Order Date","parameter":"before last","value":"365 days"},{"join":"and","criterion":"Subscriber Has Clicked","parameter":"not equal to","value":"TRUE"},{"join":"and","criterion":"Subscriber Created Date","parameter":"before last","value":"180 days"},{"join":"and","criterion":"Number of Replies","parameter":"equals","value":"0"}]}' Example response
{
"segment_id": "60418",
"name": "Unengaged 180 days",
"size": 3412,
"include_phone_only": false
}