Import Leave
นำเข้าเอกสารการลาแบบกลุ่ม (Batch Import)
ใช้ API นี้เพื่อนำเข้าข้อมูลการลาจำนวนมากพร้อมกัน รองรับทั้งการเพิ่ม/แก้ไข (UPSERT) และการลบ (DEL) ข้อมูลจะถูกส่งเข้า Queue เพื่อประมวลผลแบบ Asynchronous
Endpoint
POST /api/v1/open-apis/time-leave/importRequest Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
import_data | array | Yes | รายการข้อมูลการลาที่ต้องการนำเข้า | (ดูตัวอย่างด้านล่าง) |
import_data[].status | string | Yes | การดำเนินการ: UPSERT หรือ DEL | UPSERT |
import_data[].employee_code | string | Yes | รหัสพนักงาน | EMP001 |
import_data[].type | string | Yes | รหัสประเภทการลา | absence-01 |
import_data[].start_dt | string | Yes | วันเวลาเริ่มต้น (YYYY-MM-DD HH:MM:SS) | 2025-11-15 08:00:00 |
import_data[].end_dt | string | Yes | วันเวลาสิ้นสุด (YYYY-MM-DD HH:MM:SS) | 2025-11-15 17:00:00 |
import_data[].description | string | No | รายละเอียดการลา | ป่วยเป็นไข้หวัด |
Leave Type Codes
รองรับ 19 ประเภท: absence-01 ถึง absence-08 และ absence-10 ถึง absence-20 (ไม่มี absence-09)
| Type Code | Description |
|---|---|
absence-01 | ประเภทการลา 01 |
absence-02 | ประเภทการลา 02 |
absence-03 | ประเภทการลา 03 |
absence-04 | ประเภทการลา 04 |
absence-05 | ประเภทการลา 05 |
absence-06 | ประเภทการลา 06 |
absence-07 | ประเภทการลา 07 |
absence-08 | ประเภทการลา 08 |
absence-10 | ประเภทการลา 10 |
absence-11 | ประเภทการลา 11 |
absence-12 | ประเภทการลา 12 |
absence-13 | ประเภทการลา 13 |
absence-14 | ประเภทการลา 14 |
absence-15 | ประเภทการลา 15 |
absence-16 | ประเภทการลา 16 |
absence-17 | ประเภทการลา 17 |
absence-18 | ประเภทการลา 18 |
absence-19 | ประเภทการลา 19 |
absence-20 | ประเภทการลา 20 |
Request Body Example
{
"import_data": [
{
"status": "UPSERT",
"employee_code": "EMP001",
"type": "absence-01",
"start_dt": "2025-11-15 08:00:00",
"end_dt": "2025-11-15 17:00:00",
"description": "ป่วยเป็นไข้หวัด"
},
{
"status": "UPSERT",
"employee_code": "EMP002",
"type": "absence-02",
"start_dt": "2025-11-16 08:00:00",
"end_dt": "2025-11-16 17:00:00",
"description": "ลากิจส่วนตัว"
}
]
}Response Format
Success Response (HTTP 200)
เมื่อมีข้อมูลที่ถูกต้องอย่างน้อย 1 รายการ ระบบจะส่งข้อมูลที่ถูกต้องเข้า Queue และตอบกลับรายการที่ไม่ผ่าน validation
{
"code": 200,
"message": "successfully en-queued",
"payload": {
"invalid_items": [
{
"index": 1,
"data": {
"status": "UPSERT",
"employee_code": "EMP999",
"type": "absence-01",
"start_dt": "2025-11-16 08:00:00",
"end_dt": "2025-11-16 17:00:00"
},
"errors": ["employee_code 'EMP999' not found"]
}
]
}
}Error Response - Validation Failed (HTTP 400)
เมื่อโครงสร้างข้อมูลไม่ถูกต้อง (ไม่มี import_data, ไม่ใช่ array, หรือว่างเปล่า)
{
"code": 400,
"message": "Validation failed",
"errors": ["Missing 'import_data' field"]
}Error Response - No Valid Data (HTTP 400)
เมื่อไม่มีข้อมูลที่ผ่าน validation เลย
{
"code": 400,
"message": "No valid data to import",
"payload": {
"invalid_items": [
{
"index": 0,
"data": {
"status": "UPSERT",
"employee_code": "EMP999",
"type": "absence-01",
"start_dt": "2025-11-15 08:00:00",
"end_dt": "2025-11-15 17:00:00"
},
"errors": ["employee_code 'EMP999' not found"]
}
]
}
}Response Fields
| Field | Type | Description |
|---|---|---|
code | number | รหัสสถานะ (200 = สำเร็จ, 400 = ไม่สำเร็จ) |
message | string | ข้อความตอบกลับ |
payload.invalid_items | array | รายการข้อมูลที่ไม่ผ่าน validation |
errors | array | รายการข้อผิดพลาดของโครงสร้างข้อมูล (กรณี validation ไม่ผ่าน) |
Code Examples
cURL
curl -X POST "https://openapi.humansoft.co.th/api/v1/open-apis/time-leave/import" \
-H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"import_data": [
{
"status": "UPSERT",
"employee_code": "EMP001",
"type": "absence-01",
"start_dt": "2025-11-15 08:00:00",
"end_dt": "2025-11-15 17:00:00",
"description": "ป่วยเป็นไข้หวัด"
}
]
}'Validation Rules
| Parameter | Validation | Error Message |
|---|---|---|
status | ต้องเป็น UPSERT หรือ DEL | status must be 'UPSERT' or 'DEL' |
employee_code | ต้องมีอยู่ในระบบ | employee_code 'XXX' not found |
type | ต้องเป็น absence-01 ถึง absence-08 หรือ absence-10 ถึง absence-20 | type must be absence-01 to absence-08 or absence-10 to absence-20 |
start_dt | ต้องอยู่ในรูปแบบ YYYY-MM-DD HH:MM:SS | start_dt must be in format YYYY-MM-DD HH:MM:SS |
end_dt | ต้อง >= start_dt | end_dt must be greater than or equal to start_dt |
Business Rules
Partial Success:
- ระบบจะประมวลผลเฉพาะรายการที่ถูกต้อง และแจ้งรายการที่ไม่ถูกต้องกลับมาใน response
- รายการที่ผ่าน validation จะถูกส่งเข้า Queue ทันที
- รายการที่ไม่ผ่าน validation จะถูกส่งกลับมาพร้อม error message
Asynchronous Processing
- ข้อมูลจะถูกส่งเข้าระบบคิว (Queue) เพื่อประมวลผล
- API จะตอบกลับทันทีหลังจาก validate และส่งข้อมูลเข้า Queue สำเร็จ
- เหมาะสำหรับการนำเข้าข้อมูลจำนวนมาก
Notes
Status Values
| Status | Description |
|---|---|
UPSERT | เพิ่มหรือแก้ไขข้อมูลการลา |
DEL | ลบข้อมูลการลาที่มีอยู่ |
Use Cases
- Migration - ย้ายข้อมูลการลาจากระบบเดิม
- Bulk Update - อัปเดตข้อมูลการลาจำนวนมาก
- Integration - รับข้อมูลจากระบบภายนอก
Related APIs
- Get Leave Types - ดึงรายการประเภทการลา
- Get Leave List - ดึงรายการคำขอลา
- Submit Leave - ยื่นคำขอลาทีละรายการ
- Delete Leave - ลบคำขอลา
Last updated on