---
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/fields/define-field

ผู้ติดต่อ: ฟิลด์กำหนดเอง

# กำหนดฟิลด์

สร้างฟิลด์กำหนดเอง หรือเปลี่ยนชื่อและตัวเลือก ทุกฟิลด์มีดัชนีของตัวเอง จึงกรองและเรียงได้ทันที

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

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

เรียกอีกครั้งด้วย `key` และ `type` เดิมจะอัปเดตชื่อและตัวเลือก ชนิดเปลี่ยนไม่ได้ ลองเปลี่ยนจะล้มเหลวด้วย `TYPE_LOCKED` หากต้องการเปลี่ยน ให้ลบฟิลด์แล้วสร้างใหม่

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

- `key` string จำเป็น
`a-z`, `0-9` และ `_` ขึ้นต้นด้วยตัวอักษร ไม่เกิน 40 ตัว
เช่น `"plan"`
- `type` string จำเป็น
`text`, `number`, `date`, `bool`, `enum` หรือ `multi_enum`
เช่น `"enum"`
- `name` string ไม่บังคับ
ชื่อที่แสดง ค่าเริ่มต้นคือคีย์
เช่น `"Plan"`
- `options` string[] ไม่บังคับ
จำเป็นสำหรับ `enum` และ `multi_enum`: ค่าที่อนุญาต
เช่น `["free", "pro", "business"]`

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

```
import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1/contacts',
  {
    commands: [
      {
        command: "define_field",
        args: {
          key: "plan",
          name: "Plan",
          type: "enum",
          options: [
            "free",
            "pro",
            "business"
          ]
        }
      }
    ]
  },
  { 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": "define_field",
      "id": "0",
      "type": "SUCCESS",
      "took_ms": 14,
      "data": {
        "key": "plan",
        "name": "Plan",
        "type": "enum",
        "options": [
          "free",
          "pro",
          "business"
        ],
        "created_at": "2026-10-01T10:00:00.000Z",
        "updated_at": "2026-10-01T10:00:00.000Z"
      }
    }
  ]
}
```

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

- `(field)`
ฟิลด์ตามที่บันทึก: `key`, `name`, `type`, `options`, `created_at`, `updated_at`

## ชนิด

- `text`
ไม่เกิน 2,000 ตัวอักษร กรองด้วยเท่ากับ (ไม่สนตัวพิมพ์และวรรณยุกต์) `contains` หรือ `exists`
- `number`
จำนวนเต็มหรือทศนิยม รวมค่าติดลบ `"1234,5"` อ่านเป็น 1234.5 รองรับช่วงและการเรียง
- `date`
`YYYY-MM-DD` หรือ ISO รองรับช่วงและการเรียง
- `bool`
`true` หรือ `false` `"yes"`, `"sim"` และ `"1"` อ่านเป็น true
- `enum`
หนึ่งใน `options` `"PRO"` ถูกเก็บเป็น `"pro"` ค่านอกตัวเลือกทำให้รายการล้มเหลว
- `multi_enum`
`options` กี่ค่าก็ได้ เป็นรายการหรือ `"tech, golf"` ใช้เรียงไม่ได้

## ตั้งค่าทุกฟิลด์ในครั้งเดียว

body คำขอ

```
{
  "commands": [
    {
      "command": "define_field",
      "args": {
        "key": "plan",
        "name": "Plan",
        "type": "enum",
        "options": [
          "free",
          "pro",
          "business"
        ]
      }
    },
    {
      "command": "define_field",
      "args": {
        "key": "age",
        "name": "Age",
        "type": "number"
      }
    },
    {
      "command": "define_field",
      "args": {
        "key": "city",
        "name": "City",
        "type": "text"
      }
    },
    {
      "command": "define_field",
      "args": {
        "key": "birthday",
        "name": "Birthday",
        "type": "date"
      }
    },
    {
      "command": "define_field",
      "args": {
        "key": "interests",
        "name": "Interests",
        "type": "multi_enum",
        "options": [
          "golf",
          "tech",
          "travel"
        ]
      }
    },
    {
      "command": "define_field",
      "args": {
        "key": "vip",
        "name": "VIP",
        "type": "bool"
      }
    }
  ]
}
```

บัญชีหนึ่งมีฟิลด์ได้สูงสุด 100 เกินจากนั้น `define_field` จะล้มเหลวด้วย `LIMIT_REACHED`

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

ข้อผิดพลาดระดับ 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`TYPE_LOCKED`
define_field พยายามเปลี่ยนชนิดของฟิลด์ที่มีอยู่ ลบแล้วสร้างใหม่
- CMD`LIMIT_REACHED`
บัญชีมีฟิลด์กำหนดเองครบ 100 แล้ว
- CMD`INTERNAL`
ข้อผิดพลาดของเซิร์ฟเวอร์ รายละเอียดเขียนเฉพาะในล็อกเซิร์ฟเวอร์
