Update a segment
/api/v1/segments/{segment}Parameters
| Name | In | Type | Description |
|---|---|---|---|
segmentrequired | path | string | The segment identifier. |
Request body
descriptionstringOptional. A note for your team, shown in the dashboard.
rulesarray<object>The tests a contact must pass. The table above lists the fields you can test.
fieldstringrequiredWhat to test:
email,nameorstatus; a custom field's key;opened,clickedoremailed; ortagorinterest.opstringrequiredequals | not_equals | contains | not_contains | is_set | is_not_set | starts_with | ends_with | greater_than | less_than | before | after | within_days | not_within_daysHow to compare.
opened,clickedandemailedtakewithin_daysornot_within_daysonly.valuestringWhat to compare with: text, a number, a date, or a number of days (1 to 365) for
within_days. Leave it out foris_setandis_not_set.
namestringA name for your team, like
Lagos customers.matchstringall | anyall: a contact must match every rule.any: one rule is enough. Defaults toall.
Request
/api/v1/segments/{segment}curl -X PUT 'https://app.mailyte.com/api/v1/segments/01JBT8XQ2M9WYC3K4F6R7S8T9V' \
-H 'Authorization: Bearer mk_live_YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"rules": [
{
"field": "city",
"op": "equals",
"value": "Lagos"
}
],
"name": "Lagos customers",
"match": "all"
}'const response = await fetch('https://app.mailyte.com/api/v1/segments/01JBT8XQ2M9WYC3K4F6R7S8T9V', {
method: 'PUT',
headers: {
Authorization: 'Bearer mk_live_YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"rules": [
{
"field": "city",
"op": "equals",
"value": "Lagos"
}
],
"name": "Lagos customers",
"match": "all"
}),
});
const { data } = await response.json();import requests
response = requests.put(
"https://app.mailyte.com/api/v1/segments/01JBT8XQ2M9WYC3K4F6R7S8T9V",
headers={"Authorization": "Bearer mk_live_YOUR_API_KEY"},
json={
"rules": [
{
"field": "city",
"op": "equals",
"value": "Lagos"
}
],
"name": "Lagos customers",
"match": "all"
},
)
data = response.json()["data"]<?php
$response = Http::withToken('mk_live_YOUR_API_KEY')
->put('https://app.mailyte.com/api/v1/segments/01JBT8XQ2M9WYC3K4F6R7S8T9V', [
'rules' => [
[
'field' => 'city',
'op' => 'equals',
'value' => 'Lagos',
],
],
'name' => 'Lagos customers',
'match' => 'all',
]);
$data = $response->json('data');require "net/http"
require "json"
uri = URI("https://app.mailyte.com/api/v1/segments/01JBT8XQ2M9WYC3K4F6R7S8T9V")
request = Net::HTTP::Put.new(uri)
request["Authorization"] = "Bearer mk_live_YOUR_API_KEY"
request["Content-Type"] = "application/json"
request.body = {
"rules": [
{
"field": "city",
"op": "equals",
"value": "Lagos"
}
],
"name": "Lagos customers",
"match": "all"
}.to_json
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) { |http| http.request(request) }Response
Success.
dataobjectobjectstringsegmentidstringUnique identifier for the segment.
namestringdescriptionstringYour note on what the segment is for. Null when none was written. It does not affect the rules.
matchstringall | anyHow the rules combine:
allof them must hold, oranyone.rulesarray<object>The segment's rules, as you wrote them.
fieldstringWhat the rule tests:
email,nameorstatus;opened,clickedoremailed(from email activity); or any key in the contact'sfields.statusis the stored status, not the contact'sstate.opstringequals | not_equals | contains | not_contains | is_set | is_not_set | starts_with | ends_with | greater_than | less_than | before | after | within_days | not_within_daysHow the rule compares. -
within_days,not_within_days: only withopened,clickedoremailed.not_within_daysincludes contacts never emailed. -greater_than,less_than: compare as numbers. -before,after: compare as dates. -starts_with,ends_with: match the start or end of the value, not anywhere in it. A value that cannot be read as the right type matches nothing.valuestringWhat to compare with. Null for
is_setandis_not_set; a number of days from 1 to 365 for the activity operators.
contact_countintegerLIVE. A segment is a query, so this is what the rules match now, not what they matched when it was saved. Always an integer.
created_atstringupdated_atstring
Returned inside the standard envelope.
Errors
| Status | When |
|---|---|
401 | The API key is missing, unknown, revoked or expired. All four answer identically, on purpose: distinguishing them would confirm which keys exist. |
403 | The key is valid but may not do this: it lacks the required scope, its IP allowlist does not include you, or this endpoint does not accept API keys. |
404 | No such resource in this organization. |
422 | The request was understood but the values were not acceptable. |
429 | Too many requests, or the organization has spent its sending allowance. `Retry-After` says how long to wait. |
Every status, with what causes it and what to do, is on the error reference.