Update a segment

PUT/api/v1/segments/{segment}
Requires anorganization API keywith the scopecontacts:write

Parameters

NameInTypeDescription
segmentrequiredpathstringThe segment identifier.

Request body

  • descriptionstring

    Optional. 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.

    • fieldstringrequired

      What to test: email, name or status; a custom field's key; opened, clicked or emailed; or tag or interest.

    • 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_days

      How to compare. opened, clicked and emailed take within_days or not_within_days only.

    • valuestring

      What to compare with: text, a number, a date, or a number of days (1 to 365) for within_days. Leave it out for is_set and is_not_set.

  • namestring

    A name for your team, like Lagos customers.

  • matchstringall | any

    all: a contact must match every rule. any: one rule is enough. Defaults to all.

Request

PUT/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"
  }'
The key names its own organization, so no X-Organization-ID header is needed.

Response

Success.

  • dataobject
    • objectstringsegment
    • idstring

      Unique identifier for the segment.

    • namestring
    • descriptionstring

      Your note on what the segment is for. Null when none was written. It does not affect the rules.

    • matchstringall | any

      How the rules combine: all of them must hold, or any one.

    • rulesarray<object>

      The segment's rules, as you wrote them.

      • fieldstring

        What the rule tests: email, name or status; opened, clicked or emailed (from email activity); or any key in the contact's fields. status is the stored status, not the contact's state.

      • 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_days

        How the rule compares. - within_days, not_within_days: only with opened, clicked or emailed. not_within_days includes 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.

      • valuestring

        What to compare with. Null for is_set and is_not_set; a number of days from 1 to 365 for the activity operators.

    • contact_countinteger

      LIVE. 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_atstring
    • updated_atstring

Returned inside the standard envelope.

Errors

StatusWhen
401The API key is missing, unknown, revoked or expired. All four answer identically, on purpose: distinguishing them would confirm which keys exist.
403The 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.
404No such resource in this organization.
422The request was understood but the values were not acceptable.
429Too 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.