Skip to Content
🚀 Welcome to Humansoft Open API Documentation

Import Leave

นำเข้าเอกสารการลาแบบกลุ่ม (Batch Import)

ใช้ API นี้เพื่อนำเข้าข้อมูลการลาจำนวนมากพร้อมกัน รองรับทั้งการเพิ่ม/แก้ไข (UPSERT) และการลบ (DEL) ข้อมูลจะถูกส่งเข้า Queue เพื่อประมวลผลแบบ Asynchronous

Endpoint

POST /api/v1/open-apis/time-leave/import

Request Parameters

ParameterTypeRequiredDescriptionExample
import_dataarrayYesรายการข้อมูลการลาที่ต้องการนำเข้า(ดูตัวอย่างด้านล่าง)
import_data[].statusstringYesการดำเนินการ: UPSERT หรือ DELUPSERT
import_data[].employee_codestringYesรหัสพนักงานEMP001
import_data[].typestringYesรหัสประเภทการลาabsence-01
import_data[].start_dtstringYesวันเวลาเริ่มต้น (YYYY-MM-DD HH:MM:SS)2025-11-15 08:00:00
import_data[].end_dtstringYesวันเวลาสิ้นสุด (YYYY-MM-DD HH:MM:SS)2025-11-15 17:00:00
import_data[].descriptionstringNoรายละเอียดการลาป่วยเป็นไข้หวัด

Leave Type Codes

รองรับ 19 ประเภท: absence-01 ถึง absence-08 และ absence-10 ถึง absence-20 (ไม่มี absence-09)

Type CodeDescription
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

FieldTypeDescription
codenumberรหัสสถานะ (200 = สำเร็จ, 400 = ไม่สำเร็จ)
messagestringข้อความตอบกลับ
payload.invalid_itemsarrayรายการข้อมูลที่ไม่ผ่าน validation
errorsarrayรายการข้อผิดพลาดของโครงสร้างข้อมูล (กรณี validation ไม่ผ่าน)

Code Examples

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

ParameterValidationError Message
statusต้องเป็น UPSERT หรือ DELstatus must be 'UPSERT' or 'DEL'
employee_codeต้องมีอยู่ในระบบemployee_code 'XXX' not found
typeต้องเป็น absence-01 ถึง absence-08 หรือ absence-10 ถึง absence-20type must be absence-01 to absence-08 or absence-10 to absence-20
start_dtต้องอยู่ในรูปแบบ YYYY-MM-DD HH:MM:SSstart_dt must be in format YYYY-MM-DD HH:MM:SS
end_dtต้อง >= start_dtend_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

StatusDescription
UPSERTเพิ่มหรือแก้ไขข้อมูลการลา
DELลบข้อมูลการลาที่มีอยู่

Use Cases

  1. Migration - ย้ายข้อมูลการลาจากระบบเดิม
  2. Bulk Update - อัปเดตข้อมูลการลาจำนวนมาก
  3. Integration - รับข้อมูลจากระบบภายนอก
Last updated on