連絡先:検索

連絡先の検索

リスト、ステータス、タグ、カスタム項目、エンゲージメント、日付を自由に組み合わせて連絡先を検索します。条件を書くだけで、インデックスはサーバーが選びます。

POSThttps://g.sendcorex.com/v1/contactscommand: query_contacts

API keyにcontact:readスコープが必要です。

サーバーはwhere内のインデックス付き条件をそれぞれ測定し、最も絞り込める条件を走査して、各連絡先をwhere全体と照合します。インデックスを選ぶ必要はありません。

引数

  • whereobject任意

    ANDで結合される条件。省略(または{})するとすべての連絡先を取得します。下のwhereのリファレンスを参照。

  • sortstring | object任意

    項目名または{ "field": "<name>" }。下の「並べ替え」を参照。

    例: "open_rate"

  • limitnumber任意

    ページサイズ(1〜1000)。デフォルトは50。

  • cursorstring任意

    前のページのnext_cursor。同じwhereとsortと一緒に送ります。

  • selectstring[]任意

    各連絡先のこれらの部分だけを返します(例:["status", "fields.plan", "stats.open_count"])。emailは常に返ります。指定しないと連絡先全体が返ります。

クイックスタート

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/contacts',
  {
    commands: [
      {
        command: "query_contacts",
        args: {
          where: {
            list: "customers",
            sendable: true,
            tags: {
              has: "vip",
              none: [
                "churn"
              ]
            },
            fields: {
              plan: {
                in: [
                  "pro",
                  "business"
                ]
              },
              age: {
                gte: 25,
                lte: 40
              }
            },
            last_open_at: {
              within_days: 30
            }
          },
          sort: "open_rate",
          limit: 100
        }
      }
    ]
  },
  { 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);

レスポンス

{
  "type": "SUCCESS",
  "results": [
    {
      "command": "query_contacts",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 14,
      "data": {
        "contacts": [
          {
            "email": "ana@acme.com",
            "domain": "acme.com",
            "first_name": "Ana",
            "last_name": "Costa",
            "phone": null,
            "company": "Acme",
            "locale": "pt-BR",
            "timezone": "America/Sao_Paulo",
            "source": "checkout",
            "status": "subscribed",
            "status_reason": null,
            "status_at": "2026-10-13T06:05:08.323Z",
            "created_at": "2026-10-13T06:05:08.323Z",
            "updated_at": "2026-10-14T09:12:40.118Z",
            "tags": [
              "customer",
              "vip"
            ],
            "lists": {
              "customers": {
                "subscribed": true,
                "sendable": true,
                "added_at": "2026-10-13T06:05:08.323Z",
                "unsubscribed_at": null
              }
            },
            "fields": {
              "plan": "pro",
              "age": 31,
              "city": "São Paulo"
            },
            "stats": {
              "sent_count": 12,
              "open_count": 7,
              "click_count": 2,
              "bounce_count": 0,
              "complaint_count": 0,
              "open_rate": 0.58,
              "click_rate": 0.17,
              "first_open_at": "2026-10-13T08:41:02.000Z",
              "last_open_at": "2026-10-14T21:03:55.000Z",
              "last_click_at": "2026-10-14T21:04:10.000Z",
              "last_sent_at": "2026-10-14T20:58:31.000Z"
            }
          }
        ],
        "has_more": true,
        "next_cursor": "eyJkIjoidGFnOnZpcCJ9",
        "plan": {
          "driver": "tag:vip",
          "examined": 412,
          "keys_only": false,
          "ms": {
            "scan": 4,
            "fetch": 9,
            "filter": 1,
            "total": 14
          }
        }
      }
    }
  ]
}

レスポンスの項目

  • contacts

    一致した連絡先。連絡先全体、またはselectで指定した部分のみ。

  • has_more / next_cursor

    ページネーション。has_moreがtrueの間は、同じwhereとsortでnext_cursorをcursorとして送ります。

  • plan.driver

    サーバーが走査に選んだインデックス(例:tag:vip、list:customers)。

  • plan.examined

    このページを埋めるために読み取ったインデックスのエントリー数。

  • plan.keys_only

    連絡先を読み込まずにインデックスだけで返した場合はtrue。

  • plan.ms

    走査、取得、絞り込み、合計にかかった時間(ミリ秒)。

whereオブジェクト

各キーは任意で、すべてが一致する必要があります。テキスト、enumの選択肢、タグは大文字小文字とアクセントを無視します。

  • email

    "ana@acme.com"。その連絡先を直接読み取ります。

  • search

    "jo sil"。各語が名、姓、会社名、メールアドレスのいずれかの語の先頭である必要があります。

  • status

    "subscribed"、["bounced", "complained"]のようなリスト、{ "in": [...] }、{ "not": "subscribed" }。

  • list

    "customers"、またはいずれかのメンバーなら{ "in": ["a", "b"] }。

  • sendable

    true。listありの場合:そのリストを購読中でステータスがsubscribed。listなしの場合:ステータスがsubscribed。

  • tags

    { "has": "vip" }、{ "all": [...] }、{ "any": [...] }、{ "none": [...] }。組み合わせ可能。

  • domain

    "gmail.com"または{ "in": [...] }。

  • fields

    { "plan": "pro" }、{ "age": { "gte": 25 } }、{ "plan": { "in": [...] } }、{ "city": { "contains": "paul" } }、{ "company": { "exists": true } }。項目が存在している必要があります。

  • sent_count, open_count, click_count, bounce_count, complaint_count, open_rate, click_rate

    数値、または{ "gte", "gt", "lte", "lt", "eq" }。率は0〜1です。

  • created_at, first_open_at, last_open_at, last_click_at, last_sent_at

    { "within_days": 30 }、{ "after": "2026-01-01" }、{ "before": "..." }、{ "never": true }、{ "exists": true }。

  • campaign_opened, campaign_clicked

    キャンペーンのid。そのキャンペーンを開封またはクリックした連絡先。

不明なキーや存在しない項目は、黙って0件になるのではなく、INVALID_ARGSでコマンドが失敗します。

カスタム項目の演算子

各カスタム項目は個別にインデックスされるため、大きなリストでもこれらの絞り込みは高速です。

  • 等しい

    { "plan": "pro" }。テキストとenumの値は大文字小文字とアクセントを無視します。multi_enum項目では、その選択肢を持つ連絡先に一致します。

  • in

    { "plan": { "in": ["pro", "business"] } }。いずれかの値。

  • gte, gt, lte, lt, eq

    numberとdate項目の範囲。日付はYYYY-MM-DDまたはISO。

  • contains

    textの値の一部(大文字小文字とアクセントを無視)。

  • exists

    値がある連絡先はtrue、ない連絡先はfalse。

並べ替え

並べ替え項目ごとに方向は固定です。カスタム項目や日付で並べ替えると、値のある連絡先のみが返ります。last_open_atは一度でも開封した人だけを返します。

  • email

    AからZ。

  • fields.<key>

    昇順。multi_enum項目では使えません。

  • sent_count, open_count, click_count, open_rate, click_rate

    大きい順。

  • created_at, last_open_at, last_click_at, last_sent_at

    新しい順。

ページネーション

1回の呼び出しで読み取るインデックスのエントリーは最大20,000件です。ページが埋まる前にその上限に達すると、has_more: trueで少ない件数(0件の場合も)を返します。has_moreがtrueの間は続けてください。空のページで止めないでください。

Node.js

const where = { list: 'customers', sendable: true };
const emails = [];
let cursor;

do {
  const [result] = await call({
    command: 'query_contacts',
    args: { where, select: ['email'], limit: 1000, ...(cursor ? { cursor } : {}) },
  });
  emails.push(...result.data.contacts.map((c) => c.email));
  cursor = result.data.has_more ? result.data.next_cursor : null;
} while (cursor);

callは、Run Commandsのように{ commands: [...] }を/v1/contactsにPOSTしてresultsを返す任意のヘルパーです。

その他の例

リクエストボディ

{
  "commands": [
    {
      "command": "query_contacts",
      "id": "inactive",
      "args": {
        "where": {
          "list": "customers",
          "last_open_at": {
            "never": true
          },
          "created_at": {
            "before": "2026-07-01"
          }
        }
      }
    },
    {
      "command": "query_contacts",
      "id": "bounced",
      "args": {
        "where": {
          "status": [
            "bounced",
            "complained"
          ]
        },
        "select": [
          "status",
          "status_reason"
        ]
      }
    },
    {
      "command": "query_contacts",
      "id": "search",
      "args": {
        "where": {
          "search": "ana acme"
        },
        "limit": 10
      }
    }
  ]
}

エラー

HTTPレベルのエラーはtype、code、messageを返します。CMDと表示されたエラーは、HTTP 200でコマンドの結果内に返ります。

  • 401INVALID_API_KEY

    API keyが存在しないか、取り消されたか、ダッシュボードで無効化されています。

  • 429RATE_LIMITED

    同じIP + API keyで毎秒15リクエストまたは同時15件を超えました。Retry-Afterの秒数だけ待ってください。

  • CMDMISSING_SCOPE

    API keyにこのコマンドに必要なスコープがありません。リクエスト内のほかのコマンドは実行されます。

  • CMDINVALID_ARGS

    必須の引数がないか不正です:メールアドレス、項目の値、enumの選択肢、whereのキー、リストのid…

  • CMDINVALID_CURSOR

    カーソルが不正か、別のクエリまたはアカウントのものです。

  • CMDINTERNAL

    サーバーエラー。詳細はサーバーのログにのみ記録されます。