Update Employee Setting
แก้ไขการตั้งค่ากะพื้นฐานของพนักงาน
ใช้ API นี้เพื่อกำหนดกะพื้นฐานให้พนักงาน เช่น กะประจำวันจันทร์-ศุกร์
Endpoint
POST /api/v1/open-apis/work-cycle/update-employee-base-work-cycle-settingRequest Parameters
Required Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
employee_code | string | Yes | รหัสพนักงาน | EMP001 |
work_cycle_format | string | Yes | รูปแบบกะ | weekly |
day_lists | array | Yes | รายการกะแต่ละวัน | ดูตัวอย่างด้านล่าง |
day_lists[] Object
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
day | string | Yes | วัน (monday, tuesday, …) | monday |
id | string | Yes | ID ของกะ (Base64) | V0MwMDE= |
code | string | No | รหัสกะ | A |
name | string | No | ชื่อกะ | A : 08:00-17:00 |
Request Body Example
{
"employee_code": "EMP001",
"work_cycle_format": "weekly",
"day_lists": [
{"day": "monday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"},
{"day": "tuesday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"},
{"day": "wednesday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"},
{"day": "thursday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"},
{"day": "friday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"}
]
}Response Format
Success Response (HTTP 200)
{
"code": 200,
"message": "สำเร็จ",
"payload": {
"employee_id": "RU1QMDE=",
"employee_code": "EMP001",
"employee_name": "สมชาย ใจดี",
"employee_name_en": "Somchai Jaidee",
"work_cycle_format": "weekly",
"work_cycle_id_json": "{\"monday\":\"1\",\"tuesday\":\"1\",\"wednesday\":\"1\",\"thursday\":\"1\",\"friday\":\"1\"}",
"work_cycle_lists": {
"monday": {
"work_cycle_code": "A",
"work_cycle_id": "V0MwMDE="
},
"tuesday": {
"work_cycle_code": "A",
"work_cycle_id": "V0MwMDE="
},
"wednesday": {
"work_cycle_code": "A",
"work_cycle_id": "V0MwMDE="
},
"thursday": {
"work_cycle_code": "A",
"work_cycle_id": "V0MwMDE="
},
"friday": {
"work_cycle_code": "A",
"work_cycle_id": "V0MwMDE="
}
},
"updated": "2026-01-14 10:30:00"
}
}Error Response - Validation Failed (HTTP 400)
{
"code": 400,
"message": "Validation failed",
"errors": [
"Missing required parameter: 'employee_code'",
"Missing required parameter: 'work_cycle_format'",
"Missing required parameter: 'day_lists'"
]
}Error Response - Employee Not Found (HTTP 400)
{
"code": 400,
"message": "ไม่สำเร็จ",
"error": "Employee not found with code: EMP999"
}Response Fields
| Field | Type | Description |
|---|---|---|
employee_id | string | ID ของพนักงาน (Base64) |
employee_code | string | รหัสพนักงาน |
employee_name | string | ชื่อ-นามสกุลพนักงาน (ไทย) |
employee_name_en | string | ชื่อ-นามสกุลพนักงาน (อังกฤษ) |
work_cycle_format | string | รูปแบบกะ |
work_cycle_id_json | string | JSON ของ work_cycle_id แต่ละวัน |
work_cycle_lists | object | รายการกะแต่ละวัน |
updated | datetime | วันเวลาที่อัพเดท |
Code Examples
cURL
curl -X POST "https://openapi.humansoft.co.th/api/v1/open-apis/work-cycle/update-employee-base-work-cycle-setting" \
-H "Ocp-Apim-Subscription-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"employee_code": "EMP001",
"work_cycle_format": "weekly",
"day_lists": [
{"day": "monday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"},
{"day": "tuesday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"},
{"day": "wednesday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"},
{"day": "thursday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"},
{"day": "friday", "id": "V0MwMDE=", "code": "A", "name": "A : 08:00-17:00"}
]
}'Validation Rules
| Parameter | Validation | Error Message |
|---|---|---|
employee_code | ต้องระบุและเป็น string | Missing required parameter: 'employee_code' |
work_cycle_format | ต้องระบุและเป็น string | Missing required parameter: 'work_cycle_format' |
day_lists | ต้องระบุและเป็น array | Missing required parameter: 'day_lists' |
day_lists[].day | ต้องระบุ | Missing 'day' in day_lists[index] |
day_lists[].id | ต้องระบุ | Missing 'id' in day_lists[index] |
Day Keys
| Key | วัน |
|---|---|
monday | วันจันทร์ |
tuesday | วันอังคาร |
wednesday | วันพุธ |
thursday | วันพฤหัสบดี |
friday | วันศุกร์ |
saturday | วันเสาร์ |
sunday | วันอาทิตย์ |
Error Handling
| Error | Cause | Solution |
|---|---|---|
Missing required parameter: 'employee_code' | ไม่ได้ส่ง employee_code | ตรวจสอบ request body |
Missing required parameter: 'work_cycle_format' | ไม่ได้ส่ง work_cycle_format | ระบุ weekly หรือ daily |
Missing required parameter: 'day_lists' | ไม่ได้ส่ง day_lists | ส่ง array ของกะแต่ละวัน |
Missing 'id' in day_lists[index] | ไม่ได้ระบุ id ในรายการ | ใส่ work_cycle_id (Base64) |
Employee not found with code: XXX | ไม่พบพนักงาน | ตรวจสอบ employee_code |
Notes
Use Cases
- กำหนดกะพื้นฐาน - ตั้งกะประจำวันให้พนักงานใหม่
- เปลี่ยนกะทำงาน - ย้ายพนักงานไปทำกะอื่น
- แก้ไขวันหยุด - เพิ่ม/ลบวันที่ต้องเข้าทำงาน
Partial Update
- สามารถส่งเฉพาะวันที่ต้องการแก้ไข
- วันที่ไม่ได้ส่งจะคงค่าเดิม (ถ้า work_cycle_format เดิม)
- ถ้าเปลี่ยน work_cycle_format จะ reset ค่าทั้งหมด
หา work_cycle_id
- ใช้ Get Work Cycle Types เพื่อดู
work_cycle_idของกะทั้งหมด - ID เป็นรูปแบบ Base64
Activity Log
- ระบบจะบันทึก Log การแก้ไขกะอัตโนมัติ
- สามารถตรวจสอบได้ในประวัติการแก้ไขข้อมูลพนักงาน
Related APIs
- Get Work Cycle Types - ดูรายการกะทั้งหมด
- Get Employee Setting - ดูการตั้งค่าปัจจุบัน
- Get Monthly Schedule - ดูตารางกะรายเดือน
Last updated on