---
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/segments/run-segment

ผู้ติดต่อ: กลุ่ม

# เรียกใช้กลุ่ม

ดึงผู้ติดต่อที่ตรงกับกลุ่มที่บันทึกไว้ ณ ตอนนี้ ผลลัพธ์และการแบ่งหน้าเหมือน Query Contacts

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

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

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

- `segment_id` string จำเป็น
กลุ่มที่จะเรียกใช้
เช่น `"engaged-vips"`
- `limit` number ไม่บังคับ
ขนาดหน้า 1 ถึง 1000 ค่าเริ่มต้น 50
- `cursor` string ไม่บังคับ
`next_cursor` ของหน้าก่อน
- `select` string[] ไม่บังคับ
ส่งกลับเฉพาะส่วนเหล่านี้ของผู้ติดต่อแต่ละราย เช่น `["status", "fields.plan", "stats.open_count"]` `email` จะกลับมาเสมอ หากไม่ใส่จะได้ผู้ติดต่อทั้งหมด

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

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/contacts',
  {
    commands: [
      {
        command: "run_segment",
        args: {
          segment_id: "engaged-vips",
          select: [
            "first_name",
            "stats.open_rate"
          ],
          limit: 500
        }
      }
    ]
  },
  { 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": "run_segment",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 14,
      "data": {
        "contacts": [
          {
            "email": "ana@acme.com",
            "first_name": "Ana",
            "stats": {
              "open_rate": 0.58
            }
          }
        ],
        "has_more": false,
        "next_cursor": null,
        "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`
เวลาที่ใช้สแกน ดึง กรอง และรวม หน่วยมิลลิวินาที

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

ข้อผิดพลาดระดับ 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`NOT_FOUND`
ไม่มีผู้ติดต่อ รายชื่อ ฟิลด์ หรือกลุ่มนี้
- CMD`INVALID_CURSOR`
cursor ผิดรูปแบบหรือเป็นของคิวรีหรือบัญชีอื่น
- CMD`INTERNAL`
ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์
