Skip to Content
🚀 Welcome to Humansoft Open API Documentation

Excel Import

Import การตั้งค่าวงเงินสวัสดิการพนักงานจากไฟล์ Excel (.xlsx) หลายพนักงานพร้อมกันในครั้งเดียว ระบบจะอ่านข้อมูลจาก Excel แล้วแทนที่ Config เดิมด้วยข้อมูลใหม่

Endpoint

POST /api/v1/open-apis/welfare/excel_import

Content-Type: multipart/form-data

Request Body

ParameterTypeRequiredDescriptionExample
_fileUpdfileYesไฟล์ Excel (.xlsx)@/path/to/welfare_config.xlsx
yearstringYesปีสวัสดิการ (YYYY)"2026"

โครงสร้างไฟล์ Excel

ข้อมูลเริ่มที่ Row 3 (Row 1-2 เป็น Header)

Row 1: [Header Row - ไม่อ่านข้อมูล] Row 2: [Header Row - ไม่อ่านข้อมูล] Row 3: EMP001 | ... | ... | ... | ... | SAL_MED | ... | 5000 | 20000 Row 4: EMP002 | ... | ... | ... | ... | SAL_DEN | ... | 0 | 10000 ...
ColumnFieldDescription
Aemployee_codeรหัสพนักงาน (ต้องมีอยู่ในระบบ)
Fsalary_type_codeรหัสประเภทสวัสดิการ (ต้องมีอยู่ในระบบ)
Hwelfare_prev_amtยอดยกมาจากปีก่อน (ตัวเลข)
Iwelfare_quota_amtวงเงินสวัสดิการ (ตัวเลข)

Validation Rules

RuleDescription
_fileUpdต้องแนบไฟล์มาด้วย
yearต้องไม่ว่างเปล่า (รูปแบบ YYYY)
ไฟล์ต้องเป็นไฟล์ .xlsx เท่านั้น
employee_code (Column A)ต้องมีอยู่ในระบบ — ถ้าไม่พบจะข้ามรายการนั้น
salary_type_code (Column F)ต้องมีอยู่ในระบบ — ถ้าไม่พบจะข้ามรายการนั้น

Response Format

Success Response (HTTP 200)

{ "code": 200, "message": "Import สำเร็จ", "payload": { "year": "2026", "all_record": 50, "insert_record": 45, "update_record": 0, "delete_record": 0, "error_record": 5, "import_log_file_path": "https://example.com/file-import/employee-welfares/20260327/ABCD1234.xlsx", "error_log": "https://example.com/file-import/employee-welfares/20260327/ABCD1234_error_log.txt" } }

Response Fields

FieldTypeNullableDescription
yearstringNoปีที่ Import
all_recordintegerNoจำนวน Row ทั้งหมดที่อ่านได้
insert_recordintegerNoจำนวน Row ที่เพิ่มสำเร็จ
update_recordintegerNoจำนวน Row ที่อัปเดต (ปัจจุบัน = 0 เสมอ)
delete_recordintegerNoจำนวน Row ที่ลบ (= จำนวนที่ถูก replace)
error_recordintegerNoจำนวน Row ที่ Error (ข้ามไป)
import_log_file_pathstringYesURL ไฟล์ Excel ที่ upload ไว้
error_logstringYesURL ไฟล์ Log ผลการ Import

Error Response - Validation Failed (HTTP 422)

{ "code": 422, "message": "Validation failed", "errors": [ "'_fileUpd' file and 'year' are required" ] }

Error Response - Wrong File Type (HTTP 400)

{ "code": 400, "message": "Exception File type not support" }

Error Response - Server Error (HTTP 400)

{ "code": 400, "message": "Exception Cannot copy files" }

Code Examples

curl -X POST "https://openapi.humansoft.co.th/api/v1/open-apis/welfare/excel_import" \ -H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \ -F "year=2026" \ -F "_fileUpd=@/path/to/welfare_config_2026.xlsx"

Notes

ข้อควรทราบ:

  • ไฟล์ต้องเป็น .xlsx เท่านั้น (ไม่รองรับ .xls, .csv)
  • ข้อมูลต้องเริ่มที่ Row 3 (Row 1-2 เป็น Header)
  • ระบบจะ แทนที่ Config เดิม ก่อนสร้างใหม่เสมอ (Replace ไม่ใช่ Update)
  • Row ที่ Column A ว่างจะถือเป็นสัญญาณหยุดอ่าน
  • Row ที่ Column H และ I ว่างทั้งคู่จะถูกข้ามไป
  • ตัวเลขใน Excel รองรับ comma separator เช่น 20,000.00
  • Excel Template - ดาวน์โหลด template Excel พร้อม pre-fill ข้อมูลพนักงาน
  • Import File Log - อัปโหลดไฟล์ + สร้าง import log (ยังไม่ประมวลผลข้อมูลในไฟล์)
  • Import JSON - ส่งข้อมูลแถวที่ parse แล้วเป็น JSON เพื่อ import
  • Update Multiple - อัปเดตหลายพนักงานผ่าน JSON แทน Excel
  • List Welfare Employee By Type - ตรวจสอบผลหลัง Import
Last updated on