---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://docs.sendcorex.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://docs.sendcorex.com/llms.txt"
---

Source: https://docs.sendcorex.com/th/api-reference/contacts/search/count-contacts

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

# Count Contacts

นับผู้ติดต่อที่ตรงกับ where โดยไม่ส่งข้อมูลกลับ ใช้แสดง "1,834 คนจะได้รับอีเมลนี้" ก่อนส่ง

POST `https://g.sendcorex.com/v1/contacts` command: count_contacts

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

## อาร์กิวเมนต์

- `where` object ไม่บังคับ
`where` เดียวกับ Query Contacts ไม่ใส่เพื่อนับผู้ติดต่อทั้งหมด
- `max` number ไม่บังคับ
หยุดนับที่ตัวเลขนี้ 1 ถึง 1,000,000 ค่าเริ่มต้น 100,000

## เริ่มต้นอย่างรวดเร็ว

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/contacts',
  {
    commands: [
      {
        command: "count_contacts",
        args: {
          where: {
            list: "customers",
            sendable: true
          }
        }
      }
    ]
  },
  { 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": "count_contacts",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 14,
      "data": {
        "count": 1790,
        "exact": true
      }
    }
  ]
}
```

### ฟิลด์การตอบกลับ

- `count`
จำนวนผู้ติดต่อที่ตรง
- `exact`
`false` เมื่อหยุดนับก่อน ที่ `max` หรือที่ขีดจำกัดเวลาของคำขอ จำนวนจริงจึงอย่างน้อย `count`

## ยอดรวมโดยไม่ต้องนับ

สำหรับยอดรวมตามสถานะ รายชื่อ หรือแท็ก Get Stats ประหยัดกว่า เพราะอ่านตัวนับที่อัปเดตทุกครั้งที่เปลี่ยน แทนการไล่ผู้ติดต่อ

## ข้อผิดพลาด

ข้อผิดพลาดระดับ HTTP ส่งกลับ `type`, `code` และ `message` ข้อผิดพลาดที่มีเครื่องหมาย CMD จะกลับมาในผลลัพธ์ของคำสั่ง พร้อม HTTP 200

- 401`INVALID_API_KEY`
API key ไม่มีอยู่ ถูกเพิกถอน หรือถูกปิดในแดชบอร์ด
- 429`RATE_LIMITED`
เกิน 15 คำขอ/วินาที หรือ 15 คำขอพร้อมกันสำหรับ IP + API key เดียวกัน รอจำนวนวินาทีใน Retry-After
- CMD`MISSING_SCOPE`
API key ไม่มีขอบเขตที่คำสั่งนี้ต้องการ คำสั่งอื่นในคำขอยังทำงาน
- CMD`INVALID_ARGS`
อาร์กิวเมนต์ที่จำเป็นหายไปหรือไม่ถูกต้อง: อีเมล ค่าฟิลด์ ตัวเลือก enum คีย์ where id รายชื่อ…
- CMD`INTERNAL`
ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์
