ผู้ติดต่อ: การค้นหา

ค้นหาผู้ติดต่อ

ค้นหาผู้ติดต่อด้วยการผสมรายชื่อ สถานะ แท็ก ฟิลด์กำหนดเอง การมีส่วนร่วม และวันที่ คุณบอกว่าต้องการใคร เซิร์ฟเวอร์เลือกดัชนีเอง

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

ต้องมีขอบเขต contact:read บน API key ของคุณ

เซิร์ฟเวอร์วัดเงื่อนไขที่มีดัชนีทุกข้อใน 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 ส่ง next_cursor เป็น cursor พร้อม where และ sort เดิม

  • 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 แคมเปญ ผู้ติดต่อที่เปิดหรือคลิกแคมเปญนั้น

คีย์ที่ไม่รู้จัก หรือฟิลด์ที่ไม่มีอยู่ จะทำให้คำสั่งล้มเหลวด้วย 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

    ล่าสุดก่อน

การแบ่งหน้า

แต่ละการเรียกอ่านรายการดัชนีได้สูงสุด 20,000 รายการ เมื่อถึงเพดานก่อนเต็มหน้า จะส่งผู้ติดต่อน้อยลง (บางครั้งไม่มีเลย) พร้อม has_more: true ทำต่อไปขณะที่ 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 คือตัวช่วยใดก็ได้ที่ POST { commands: [...] } ไปที่ /v1/contacts และส่งกลับ results เหมือนใน Run Commands

ตัวอย่างเพิ่มเติม

body คำขอ

{
  "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

    เกิน 15 คำขอ/วินาที หรือ 15 คำขอพร้อมกันสำหรับ IP + API key เดียวกัน รอจำนวนวินาทีใน Retry-After

  • CMDMISSING_SCOPE

    API key ไม่มีขอบเขตที่คำสั่งนี้ต้องการ คำสั่งอื่นในคำขอยังทำงาน

  • CMDINVALID_ARGS

    อาร์กิวเมนต์ที่จำเป็นหายไปหรือไม่ถูกต้อง: อีเมล ค่าฟิลด์ ตัวเลือก enum คีย์ where id รายชื่อ…

  • CMDINVALID_CURSOR

    cursor ผิดรูปแบบหรือเป็นของคิวรีหรือบัญชีอื่น

  • CMDINTERNAL

    ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์