---
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/receive-emails/audience/get-audience

รับอีเมล: ผู้ติดต่อและกลุ่มเป้าหมาย

# Get Audience

ตรวจกลุ่มเป้าหมายก่อนส่ง: กี่คนและ 30 คนแรก อ่านอย่างเดียว

POST `https://g.sendcorex.com/v1` command: get_audience

คนที่ยกเลิกรับจะถูกตัดออกเสมอ

ใช้ได้ในแพ็กเกจแบบชำระเงิน

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

- `segment` string จำเป็น
`subscribed`, `opened`, `clicked`, `both`, `seg:<segment_id>` หรือ `msg:<message_uid>:opened|clicked|not_opened`

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

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "get_audience",
        args: {
          segment: "opened"
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_TOKEN } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);
```

## การตอบกลับ

```
{
  "type": "SUCCESS",
  "results": [
    {
      "command": "get_audience",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "segment": "opened",
        "emails": [
          "ana@empresa.com"
        ],
        "total": 1240
      }
    }
  ]
}
```

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

- `segment`
กลุ่มเป้าหมายที่คุณขอ
- `emails`
30 ที่อยู่แรก
- `total`
จำนวนคนที่จะได้รับ

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

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

- 401`TOKEN_EXPIRED`
access token หมดอายุแล้ว เรียก Refresh Token แล้วส่งคำขอซ้ำ
- 401`INVALID_TOKEN`
โทเค็นผิดรูปแบบ ไม่รู้จัก หรือถูกเพิกถอน
- 429`RATE_LIMITED`
เกิน 15 คำขอ/วินาที หรือ 15 คำขอพร้อมกันสำหรับ IP + กล่องจดหมายเดียวกัน รอจำนวนวินาทีใน Retry-After
- CMD`INVALID_AUDIENCE`
กลุ่มเป้าหมายไม่ถูกต้อง: กลุ่มที่ไม่รู้จัก กลุ่มของกล่องจดหมายอื่น หรือข้อความที่กล่องนี้ไม่ได้ส่ง
- CMD`PAID_PLAN_REQUIRED`
มากกว่าหนึ่งที่อยู่ใน `to` ต้องใช้แพ็กเกจแบบชำระเงิน
- CMD`INTERNAL`
ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์
