# createTask สร้างงาน

> POST /createTask สร้างงานจดจำ CAPTCHA ฟิลด์ในคำขอ (clientKey, task, softID) ลำดับการตรวจสอบ ประเภทแบบอะซิงโครนัสคืนค่า taskId ส่วนประเภทแบบซิงโครนัสคืนค่า solution ทันที ยอดคงเหลือต้องมากกว่า 10 พอยต์

Source: https://docs.yescaptcha.com/th/api/create-task/ · Last verified: 2026-10-15

> This page was machine-translated from the Chinese version. If anything differs, the Chinese version prevails: https://docs.yescaptcha.com/zh/api/create-task/

`createTask` สร้างงานจดจำ โดยระบุใน `task.type` ว่าจะจดจำ CAPTCHA ชนิดใด ประเภทแบบอะซิงโครนัสจะคืนค่า `taskId` จากนั้นใช้ [getTaskResult](https://docs.yescaptcha.com/th/api/get-task-result.md) เพื่อดึงผลลัพธ์ ส่วนประเภทแบบซิงโครนัสจะคืนผลลัพธ์ทันที

> **หมายเหตุ:** ระบบจะหักพอยต์เมื่อสร้างงานสำเร็จ และยอดคงเหลือต้องมากกว่า 10 พอยต์จึงจะสร้างงานได้ งานที่จดจำไม่สำเร็จหรือหมดเวลาจะคืนพอยต์โดยอัตโนมัติ

- POST `https://api.yescaptcha.com/createTask` (endpoint ทั่วโลก)
- POST `https://cn.yescaptcha.com/createTask` (endpoint จีน)

## ฟิลด์ในคำขอ

| ฟิลด์ | ชนิด | จำเป็น | คำอธิบาย |
| --- | --- | --- | --- |
| `clientKey` | string | ใช่ | ClientKey ของบัญชี คัดลอกได้จากแดชบอร์ดที่ [yescaptcha.com](https://yescaptcha.com/) |
| `task` | object | ใช่ | อ็อบเจกต์งาน ต้องมี `type` ส่วนฟิลด์อื่นกรอกตามประเภทงาน ดูได้ในหน้าของแต่ละประเภทงาน |
| `softID` | integer | ไม่ | ID นักพัฒนา ใส่ค่านี้เมื่อซอฟต์แวร์ที่คุณพัฒนามีผู้อื่นนำไปใช้ เพื่อรับส่วนแบ่งรายได้ ดู [ส่วนแบ่งรายได้นักพัฒนา](https://docs.yescaptcha.com/th/account/developer.md) |

## ตัวอย่างคำขอ

จดจำ CAPTCHA แบบรูปภาพ (แบบซิงโครนัส):

```json
{
  "clientKey": "YOUR_CLIENT_KEY",
  "task": {
    "type": "ImageToTextTaskOcrBase",
    "body": "BASE64_IMAGE"
  }
}
```

ขอ token ของ reCAPTCHA v2 (แบบอะซิงโครนัส):

```json
{
  "clientKey": "YOUR_CLIENT_KEY",
  "task": {
    "type": "NoCaptchaTaskProxyless",
    "websiteURL": "https://www.google.com/recaptcha/api2/demo",
    "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
  }
}
```

ฟิลด์ `task` ของแต่ละประเภทงานดูได้ในหน้าต่าง ๆ ภายใต้ [ประเภทงานและราคา](https://docs.yescaptcha.com/th/tasks.md)

## ผลลัพธ์ที่ได้รับ

ประเภทแบบอะซิงโครนัส:

```json
{
  "errorId": 0,
  "taskId": "61138bb6-19fb-11ec-a9c8-0242ac110006"
}
```

เก็บ `taskId` ไว้ แล้วเริ่มเรียก `getTaskResult` หลังจากผ่านไป 5 วินาที

ประเภทแบบซิงโครนัส:

```json
{
  "errorId": 0,
  "status": "ready",
  "taskId": "2376919c-1863-11ec-a012-94e6f7355a0b",
  "solution": {
    "text": "LMResm"
  }
}
```

ล้มเหลว:

```json
{
  "errorId": 1,
  "errorCode": "ERROR_TASK_NOT_SUPPORTED",
  "errorDescription": "任务类型不正确或不受支持"
}
```

## ลำดับการตรวจสอบ

เซิร์ฟเวอร์จะตรวจสอบคำขอตามลำดับนี้ และเมื่อพบปัญหาแรกจะคืนรหัสข้อผิดพลาดที่ตรงกันทันที โดยไม่หักพอยต์:

1.  เนื้อหาคำขอเป็น JSON ที่ถูกต้อง: `ERROR_REQUEST_FORMATS`
2.  มี `clientKey`: `ERROR_REQUIRED_FIELDS`
3.  `clientKey` มีอยู่ในระบบ: `ERROR_KEY_DOES_NOT_EXIST`
4.  ไม่ได้ถูกหยุดชั่วคราวอัตโนมัติ: `ERROR_IP_BLOCKED_5MIN` (ดู [ขีดจำกัดงานพร้อมกันและการหยุดชั่วคราวอัตโนมัติ](https://docs.yescaptcha.com/th/api/rate-limits.md))
5.  ยอดคงเหลือมากกว่า 10 พอยต์: `ERROR_ZERO_BALANCE`
6.  มี `task`: `ERROR_TASK_ABSENT`
7.  มี `task.type`: `ERROR_TASK_NOT_SUPPORTED`
8.  ฟิลด์ที่จำเป็นครบถ้วน: `ERROR_REQUIRED_FIELDS` (`errorDescription` จะระบุว่าขาดฟิลด์ใด)
9.  รูปภาพของงานประเภทรูปภาพถูกต้อง: `ERROR_ZERO_CAPTCHA_FILESIZE`, `ERROR_IMAGE_TYPE_NOT_SUPPORTED` เป็นต้น

## ตัวอย่างฉบับสมบูรณ์

สร้างงานและทำ polling (เรียกตรวจซ้ำเป็นระยะ) เพื่อรอผลลัพธ์ (ประเภทแบบอะซิงโครนัส):

**curl**

```bash
curl -s https://api.yescaptcha.com/createTask \
  -H 'Content-Type: application/json' \
  -d '{
  "clientKey": "YOUR_CLIENT_KEY",
  "task": {
    "type": "NoCaptchaTaskProxyless",
    "websiteURL": "https://www.google.com/recaptcha/api2/demo",
    "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
  }
}'

# Returns {"errorId":0,"taskId":"..."}; then poll every 5 seconds:
curl -s https://api.yescaptcha.com/getTaskResult \
  -H 'Content-Type: application/json' \
  -d '{"clientKey": "YOUR_CLIENT_KEY", "taskId": "TASK_ID"}'
```

**Python**

solve.py

```python
import os
import time

import requests

API = "https://api.yescaptcha.com"
CLIENT_KEY = os.environ["YESCAPTCHA_CLIENT_KEY"]  # Read the clientKey from an environment variable

def call(method, payload):
    r = requests.post(f"{API}/{method}", json={"clientKey": CLIENT_KEY, **payload}, timeout=30)
    data = r.json()
    if data.get("errorId"):
        raise RuntimeError(f"{data.get('errorCode')}: {data.get('errorDescription')}")
    return data

def solve(task):
    task_id = call("createTask", {"task": task})["taskId"]
    for _ in range(36):  # Poll every 5 seconds, for up to about 3 minutes
        time.sleep(5)
        result = call("getTaskResult", {"taskId": task_id})
        if result.get("status") == "ready":
            return result["solution"]
    raise TimeoutError(task_id)

solution = solve({
    "type": "NoCaptchaTaskProxyless",
    "websiteURL": "https://www.google.com/recaptcha/api2/demo",
    "websiteKey": "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
})
print(solution["gRecaptchaResponse"])
```

**Node.js**

solve.mjs

```js
const API = 'https://api.yescaptcha.com';
const CLIENT_KEY = process.env.YESCAPTCHA_CLIENT_KEY; // Read the clientKey from an environment variable

async function call(method, payload) {
  const res = await fetch(`${API}/${method}`, {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ clientKey: CLIENT_KEY, ...payload }),
  });
  const data = await res.json();
  if (data.errorId) throw new Error(`${data.errorCode}: ${data.errorDescription}`);
  return data;
}

async function solve(task) {
  const { taskId } = await call('createTask', { task });
  for (let i = 0; i < 36; i++) { // Poll every 5 seconds, for up to about 3 minutes
    await new Promise((r) => setTimeout(r, 5000));
    const result = await call('getTaskResult', { taskId });
    if (result.status === 'ready') return result.solution;
  }
  throw new Error(`timeout: ${taskId}`);
}

const solution = await solve({
  type: "NoCaptchaTaskProxyless",
  websiteURL: "https://www.google.com/recaptcha/api2/demo",
  websiteKey: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-",
});
console.log(solution.gRecaptchaResponse);
```
