---
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/actions/add-tags

ผู้ติดต่อ: แท็ก สถานะ และฟิลด์

# เพิ่มแท็ก

เพิ่มแท็กหนึ่งรายการขึ้นไปให้ผู้ติดต่อสูงสุด 500 ราย แท็กจะถูกสร้างทันทีและไม่สนตัวพิมพ์ใหญ่เล็กหรือวรรณยุกต์

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

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

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

- `emails` string[] ไม่บังคับ
สูงสุด 500 อีเมล ไม่สนตัวพิมพ์และช่องว่างรอบข้าง อีเมลซ้ำนับครั้งเดียว
- `email` string ไม่บังคับ
อีเมลเดียว ใช้อันนี้หรือ `emails`
- `tags` string[] จำเป็น
แท็กที่จะเพิ่ม `"Black Friday"` และ `"black friday"` เป็นแท็กเดียวกัน
เช่น `["black-friday"]`
- `return_contacts` boolean ไม่บังคับ
เพิ่มผู้ติดต่อทั้งหมดหลังเปลี่ยนในแต่ละรายการ

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

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/contacts',
  {
    commands: [
      {
        command: "add_tags",
        args: {
          emails: [
            "ana@acme.com",
            "bob@gmail.com"
          ],
          tags: [
            "black-friday"
          ]
        }
      }
    ]
  },
  { 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": "add_tags",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 14,
      "data": {
        "items": [
          {
            "id": "ana@acme.com",
            "ok": true,
            "data": {
              "changed": true
            }
          },
          {
            "id": "bob@gmail.com",
            "ok": true,
            "data": {
              "changed": true
            }
          }
        ],
        "ok_count": 2,
        "failed_count": 0
      }
    }
  ]
}
```

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

- `items[].id`
อีเมลที่คุณส่ง ตามที่คุณส่งมา
- `items[].ok`
`true` เมื่ออีเมลนี้สำเร็จ เมื่อเป็น `false` รายการจะมี `code` และ `message`
- `items[].data.changed`
`false` หมายความว่าผู้ติดต่อเป็นแบบนั้นอยู่แล้ว จึงไม่มีการเขียน
- `items[].data.contact`
ผู้ติดต่อทั้งหมดหลังเปลี่ยน เฉพาะเมื่อใช้ `return_contacts: true`
- `ok_count / failed_count`
จำนวนอีเมลที่สำเร็จและล้มเหลว

## ติดแท็กทุกคนที่คิวรีพบ

ใช้ร่วมกับ Query Contacts และ `$ref` เพื่อติดแท็กทั้งกลุ่มในคำขอเดียว โดยไม่ต้องส่งอีเมลผ่านแอปของคุณ

body คำขอ

```
{
  "commands": [
    {
      "command": "query_contacts",
      "id": "q",
      "args": {
        "where": {
          "last_open_at": {
            "within_days": 7
          }
        },
        "select": [
          "email"
        ],
        "limit": 500
      }
    },
    {
      "command": "add_tags",
      "args": {
        "emails": {
          "$ref": "q",
          "path": "contacts/*/email"
        },
        "tags": [
          "active-this-week"
        ]
      }
    }
  ]
}
```

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