Contacts: Tags, status & fields

Add Tags

Add one or more tags to up to 500 contacts. Tags are created on the fly and ignore case and accents.

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

Needs the contact:update scope on your API key.

Arguments

  • emailsstring[]optional

    Up to 500 emails. Case and surrounding spaces are ignored, and repeated emails count once.

  • emailstringoptional

    A single email. Use this or emails.

  • tagsstring[]required

    The tags to add. "Black Friday" and "black friday" are the same tag.

    e.g. ["black-friday"]

  • return_contactsbooleanoptional

    Add the whole contact after the change to each item.

Quick start

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/contacts',
  {
    commands: [
      {
        command: "add_tags",
        args: {
          emails: [
            "ana@acme.com",
            "bob@gmail.com"
          ],
          tags: [
            "black-friday"
          ]
        }
      }
    ]
  },
  { 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": "add_tags",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 14,
      "data": {
        "items": [
          {
            "id": "ana@acme.com",
            "ok": true,
            "data": {
              "changed": true
            }
          },
          {
            "id": "bob@gmail.com",
            "ok": true,
            "data": {
              "changed": true
            }
          }
        ],
        "ok_count": 2,
        "failed_count": 0
      }
    }
  ]
}

Response fields

  • items[].id

    The email you sent, as you sent it.

  • items[].ok

    true when this email worked. When false, the item has code and message.

  • items[].data.changed

    false means the contact was already like this, so nothing was written.

  • items[].data.contact

    The whole contact after the change. Only with return_contacts: true.

  • ok_count / failed_count

    How many emails worked and how many failed.

Tag everyone a query finds

Combine with Query Contacts and $ref to tag a whole segment in one request, without moving the emails through your app.

Request body

{
  "commands": [
    {
      "command": "query_contacts",
      "id": "q",
      "args": {
        "where": {
          "last_open_at": {
            "within_days": 7
          }
        },
        "select": [
          "email"
        ],
        "limit": 500
      }
    },
    {
      "command": "add_tags",
      "args": {
        "emails": {
          "$ref": "q",
          "path": "contacts/*/email"
        },
        "tags": [
          "active-this-week"
        ]
      }
    }
  ]
}
i

A contact holds up to 50 tags. Tag counts per account are in Get Stats.

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…

  • CMDNOT_FOUND

    The contact, list, field or segment does not exist.

  • CMDINTERNAL

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