Contacts: Segments

Save Segment

Save a query under a name, so your app and the dashboard can run it later. The contacts are not copied: the segment is re-evaluated every time it runs.

POSThttps://g.sendcorex.com/v1/contactscommand: save_segment
i

Needs the contact:create scope on your API key.

i

The where is validated when you save: an unknown key or field fails with INVALID_ARGS now, not on the next run.

Arguments

  • segment_idstringoptional

    Your own id. Generated when left out. Saving with an id that exists replaces that segment.

    e.g. "engaged-vips"

  • namestringoptional

    Display name.

    e.g. "Engaged VIPs"

  • whereobjectrequired

    Same where as Query Contacts.

  • sortstring | objectoptional

    Same sort as Query Contacts.

    e.g. "open_rate"

Quick start

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/contacts',
  {
    commands: [
      {
        command: "save_segment",
        args: {
          segment_id: "engaged-vips",
          name: "Engaged VIPs",
          where: {
            tags: {
              has: "vip"
            },
            last_open_at: {
              within_days: 30
            }
          },
          sort: "open_rate"
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_API_KEY } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);

Response

{
  "type": "SUCCESS",
  "results": [
    {
      "command": "save_segment",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 14,
      "data": {
        "segment_id": "engaged-vips",
        "name": "Engaged VIPs",
        "where": {
          "tags": {
            "has": "vip"
          },
          "last_open_at": {
            "within_days": 30
          }
        },
        "sort": {
          "field": "open_rate"
        },
        "created_at": "2026-10-10T12:00:00.000Z",
        "updated_at": "2026-10-10T12:00:00.000Z"
      }
    }
  ]
}

Response fields

  • (segment)

    The segment as stored.

Errors

HTTP-level errors return type, code and message. Errors marked CMD come back inside the command result, with HTTP 200.

  • 401INVALID_API_KEY

    The API key does not exist, was revoked or was disabled in the dashboard.

  • 429RATE_LIMITED

    More than 15 requests/s or 15 in flight for the same IP + API key. Wait the number of seconds in Retry-After.

  • CMDMISSING_SCOPE

    The API key does not have the scope this command needs. The other commands in the request still run.

  • CMDINVALID_ARGS

    A required argument is missing or invalid: email, field value, enum option, where key, list id…

  • CMDINTERNAL

    Server error. The detail is only written to the server log.