Constant
Contact
API Guide

Update a Segment

Use the PUT /segments/{segment_id} method to update a specified segment's name (name) and/or contact selection criteria (segment_criteria).

Example PUT /segments/{segment_id} request body

{
    "name": "Opened any of my last five campaigns",
    "segment_criteria": "{\"version\":\"1.0.0\",\"criteria\":{\"type\":\"and\",\"group\":[{\"source\":\"tracking\",\"field\":\"opened\",\"op\":\"contains-any\",\"const_value\":\"last-n-campaigns\",\"param\":\"5\"}]}}"
 }

Parameters

In the request body, you must specify both the name and the segment_criteria, even if you don't plan to update both. To avoid getting error responses, ensure that the segment_id currently exists, the name is unique, and the segment_criteria is valid and entered as single-string escaped JSON.

Example PUT Segments Requests

PUT
https://api.cc.email/v3/segments/{segment_id}
 
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "  {\n    \"name\": \"Opened any of my last five campaigns\",\n    \"segment_criteria\": \"{\\\"version\\\":\\\"1.0.0\\\",\\\"criteria\\\":{\\\"type\\\":\\\"and\\\",\\\"group\\\":[{\\\"source\\\":\\\"tracking\\\",\\\"field\\\":\\\"opened\\\",\\\"op\\\":\\\"contains-any\\\",\\\"const_value\\\":\\\"last-n-campaigns\\\",\\\"param\\\":\\\"5\\\"}]}}\"\n  }");
Request request = new Request.Builder()
  .url("https://api.cc.email/v3/segments/3")
  .put(body)
  .addHeader("Accept", "*/*")
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Bearer {access_token}")
  .addHeader("Cache-Control", "no-cache")
  .addHeader("Host", "your_host.com")
  .addHeader("Accept-Encoding", "gzip, deflate")
  .addHeader("Content-Length", "277")
  .addHeader("Connection", "keep-alive")
  .addHeader("cache-control", "no-cache")
  .build();

Response response = client.newCall(request).execute();

Response

{
    "name": "Opened any of my the last five campaigns",
    "segment_criteria": "{\"version\":\"1.0.0\",\"criteria\":{\"type\":\"and\",\"group\":[{\"source\":\"tracking\",\"field\":\"opened\",\"op\":\"contains-any\",\"const_value\":\"last-n-campaigns\",\"param\":\"5\"}]}}",
    "segment_id": 3,
    "created_at": "2020-01-21T15:25:52.000Z",
    "edited_at": "2020-01-21T15:25:52.000Z"
}
Try it!

On this page