Create segment

Save a segment under Messaging > Segments from criteria joined with and or or.

POST https://cotlet.dev/api/v1/postscript/segments

write

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

Parameters: create_segment
NameTypeDescription
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
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"}]}'
Python
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"}]})
Node.js
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"}]});
CLI
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

JSON

{
  "segment_id": "60418",
  "name": "Unengaged 180 days",
  "size": 3412,
  "include_phone_only": false
}

Sign in once. Your agent does the rest.

Sign up and add the apps you need. Free 7-day trial with 2,000 credits, no card needed.