Update the segment name and/or criteria.
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.
TIP: | Use a text formatter or editor of your choice, such as the JSON Formatter, to remove white spaces, extra lines, and to replace ” with \” in the segment_criteria . |
Example PUT Segments Requests
PUT https://api.cc.email/v3/segments/{segment_id}
<?php
$request = new HttpRequest();
$request->setUrl('https://api.cc.email/v3/segments/3');
$request->setMethod(HTTP_METH_PUT);
$request->setHeaders(array(
'cache-control' => 'no-cache',
'Connection' => 'keep-alive',
'Content-Length' => '277',
'Accept-Encoding' => 'gzip, deflate',
'Host' => 'your_host.com',
'Cache-Control' => 'no-cache',
'Authorization' => 'Bearer {access_token}',
'Content-Type' => 'application/json',
'Accept' => '*/*'
));
$request->setBody(' {
"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\\"}]}}"
}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
curl -X PUT \
https://api.cc.email/v3/segments/3 \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Authorization: Bearer {access_token}' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Length: 277' \
-H 'Content-Type: application/json' \
-H 'Host: your_host.com' \
-H 'cache-control: no-cache' \
-d ' {
"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\"}]}}"
}'
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"
}