สารบัญหน้านี้ (22)
- ภาพรวม
- Workflow: ปรับราคาเมนูทุกสาขาเช้า 06:00 (2 สาขาออฟไลน์)
- Workflow: ข้อมูลชนกัน: เบอร์สมาชิก (ตัดสินเอง) และราคาสาขา (ให้คนตัดสิน)
- The SyncJob object
- The Mapping object
- The Conflict object
- Endpoints (10)
- POSTสั่งงานซิงก์
- GETดูงานซิงก์
- GETรายการงานซิงก์
- POSTยกเลิกงานซิงก์
- GETความล้มเหลวของงาน
- GETรายการการ map ฟิลด์
- PUTบันทึกการ map ฟิลด์
- GETรายการข้อมูลชนกัน
- POSTตัดสินข้อมูลชนกัน
- GETChange feed (อ่านการเปลี่ยนแปลงตาม cursor)
- Webhooks (5)
- Errors (16)
- Rate limit
- เวอร์ชัน + Changelog
- เครื่องมือ: ตัวจำลองการ map ฟิลด์ + แก้ข้อมูลชนกัน
- CHUAMTHANG Hub
- Docs
- Integration API
- Data Sync
Data Sync · /v1/sync
Data Sync API
ทำให้เมนู ราคา สาขา สต็อก และสมาชิกตรงกันทุกระบบ — ซิงก์ตามรอบหรือทันที อ่านเฉพาะที่เปลี่ยนด้วย cursor map ฟิลด์ข้ามรูปแบบ และจัดการข้อมูลชนกันตามกฎที่กำหนดต่อข้อมูล
- 10endpoint
- 2workflow
- 3object
- 5webhook event
- 16รหัส error

โมดูลนี้ทำอะไร
- งานซิงก์ 5 ข้อมูล: menu · menu_price · branch · stock · member ในทิศทางที่กำหนด (รวม two_way สำหรับสมาชิก)
- incremental ด้วย cursor (updated_at / change_seq) + งานซ่อมเฉพาะส่วนที่ล้มเหลว
- การ map ฟิลด์ + ฟังก์ชันแปลง 8 แบบ (บาท→สตางค์ บวก VAT · พ.ศ.→ISO · ตาราง lookup …) พร้อม dry run
- ข้อมูลชนกัน: last_write_wins · source_priority (ระบบหลักชนะ) · manual_review (ให้คนตัดสิน)
ใช้เมื่อไร / ใครเรียก
- ตารางเวลาทุกเช้า 06:00 (เมนู/ราคา) และทุก 15 นาที (สต็อก สมาชิก)
- ทีมไอทีสั่งซิงก์/ซ่อมเมื่อมีปัญหา
- ผู้จัดการเขตตัดสินข้อมูลชนกันที่ต้องใช้คน
- BI อ่าน change feed
Base path/v1/syncBase URLhttps://api.chuamthang.exampleSandboxhttps://sandbox.api.chuamthang.example
การยืนยันตัวตนและสิทธิ์ (scope)
ทุกคำขอส่ง API key ในหัว Authorization: Bearer … — คีย์ sandbox ขึ้นต้น ct_test_ คีย์ production ขึ้นต้น ct_live_ · คีย์ของ POS สาขาถูกจำกัดให้เห็นเฉพาะสาขาตัวเอง (branch_not_allowed) · ส่ง Chuamthang-Version เพื่อตรึงเวอร์ชัน · คีย์แต่ละตัวมี scope ตามตารางนี้ (ขอเพิ่มได้ใน Developer Console)
GET https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0600 HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
Chuamthang-Version: 2026-08-01
Accept: application/json| scope | ให้ทำอะไร | ระบบที่มักใช้ |
|---|---|---|
sync.jobs:read | ดูงานและความล้มเหลว | ทีมไอที · แดชบอร์ด |
sync.jobs:write | สั่ง/ยกเลิกงาน | ทีมไอที · ตัวตั้งเวลา |
sync.mappings:read | ดูการ map | ทีมไอที |
sync.mappings:write | แก้การ map | ทีมไอที (ผ่านรีวิว) |
sync.conflicts:read | ดูข้อมูลชนกัน | ผู้จัดการเขต · ไอที |
sync.conflicts:write | ตัดสินข้อมูลชนกัน | ผู้จัดการเขต |
sync.changes:read | อ่าน change feed | BI · ระบบภายนอกที่ได้รับอนุญาต |
Object หลัก
SyncJobงานซิงก์ 1 ครั้ง (ตัวอย่าง: ราคาเมนูรอบเช้า)18 ฟิลด์Mappingการ map ฟิลด์ ERP → POS ของเมนู13 ฟิลด์Conflictข้อมูลชนกัน 1 รายการ (ตัวอย่าง: ราคาที่สาขาตั้งเอง)12 ฟิลด์
ความสัมพันธ์กับโมดูลอื่น
- ERPERP เป็นระบบหลักของเมนู ราคา และทะเบียนวัตถุดิบ
- CRMCRM เป็นระบบหลักของข้อมูลสมาชิก (ซิงก์สองทางกับ POS)
- Third-Party Serviceส่งเมนูและราคาไปแอปส่งอาหารผ่าน connector
- Webhookแจ้ง sync.job.completed และ sync.conflict.detected ไปยัง endpoint ที่สมัคร
- ระบบหลัก (master) ของแต่ละข้อมูล: เมนู/ราคา/วัตถุดิบ = ERP · สมาชิก = CRM · ยอดขาย = POS
- incremental อ่านตาม cursor — งานที่ถูกยกเลิกไม่ขยับ cursor รอบถัดไปอ่านช่วงเดิมซ้ำ (ไม่ตกหล่น)
- เงินในปลายทางเป็นสตางค์รวม VAT · ERP เก็บบาทไม่รวม VAT (ทศนิยม 2) — แปลงด้วย baht_to_satang_vat
- เวลา ISO 8601 +07:00 (ERP เดิมใช้ วว/ดด/ปปปป พ.ศ. → แปลงด้วย be_date_to_iso) · list ใช้ cursor
Workflow — ลำดับการทำงานจริง (2 เรื่อง)
แต่ละเรื่องดูได้ 2 แบบ: Infographic อธิบายภาษาคนทั่วไป และ Sequence ทีละขั้น กดเล่นแล้วดูคำขอ/ผลลัพธ์ของทุกขั้น (ลูกศรประ = ไม่รอผล เช่น webhook หรือคิว)
ปรับราคาเมนูทุกสาขาเช้า 06:00 (2 สาขาออฟไลน์)
ฝ่ายการตลาดปรับราคา 3 เมนูใน ERP เมื่อวาน — งานซิงก์รอบเช้าส่งไป POS 60 สาขา (เช่น กะเพรา ฿89.00 → ฿94.00)
- ตัวตั้งเวลา06:00 ทุกวัน
- CHUAMTHANG HubData Sync
- ERP กลางทะเบียนเมนู
- POS 60 สาขา
- ทีมปฏิบัติการ
- 1
ตัวตั้งเวลา → CHUAMTHANG Hub
ถึงเวลา 06:00 สร้างงาน menu_price แบบ incremental
POST /v1/sync/jobs - 2
CHUAMTHANG Hub → ERP กลาง
อ่านทะเบียน 186 รายการ พบเปลี่ยน 3 รายการ
- 3
CHUAMTHANG Hub → CHUAMTHANG Hub
unit_price "87.85" (บาท ไม่รวม VAT) → price 9400 สตางค์รวม VAT · "11/10/2569" → ISO 8601
- 4
CHUAMTHANG Hub → POS 60 สาขา
ส่งราคาใหม่ไปทุกสาขาพร้อมกันครั้งละ 10 สาขา
- 5
POS 60 สาขา → CHUAMTHANG Hub
POS ของ brn_017 และ brn_052 ไม่ตอบ (ปิดเครื่องข้ามคืน) — ลองครบ 3 ครั้ง
- 6
CHUAMTHANG Hub → ทีมปฏิบัติการ
แจ้งทีมพร้อมตัวเลข
ไม่รอผล (async) - 7
ทีมปฏิบัติการ → CHUAMTHANG Hub
ทีมกดซิงก์ใหม่ทั้งหมดเร็วเกินไป
POST /v1/sync/jobs - 8
ทีมปฏิบัติการ → CHUAMTHANG Hub
ดูว่าพลาดตรงไหน
GET /v1/sync/jobs/syj_menu_20261012_0600/failures - 9
ทีมปฏิบัติการ → CHUAMTHANG Hub
เมื่อสองสาขาเปิดร้าน สร้างงานซ่อมเฉพาะ 2 สาขา
POST /v1/sync/jobs - 10
CHUAMTHANG Hub → POS 60 สาขา
ทุกสาขาใช้ราคาเดียวกันก่อนเปิดขายมื้อกลางวัน
ภายใน 3 นาที 42 วินาที 58 สาขาได้ราคาใหม่ · 2 สาขาที่ออฟไลน์ได้ตามมาด้วยงานซ่อมเฉพาะส่วน (6 รายการ) ไม่ต้องซิงก์ทั้งหมดใหม่
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 ตัวตั้งเวลา CHUAMTHANG Hub
POST /v1/sync/jobs (schedule)
ถึงเวลา 06:00 สร้างงาน menu_price แบบ incremental
POST /v1/sync/jobs HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
{
"entity": "menu_price",
"direction": "erp_to_pos",
"mode": "incremental",
"mapping_id": "map_menu_erp_pos"
}HTTP/1.1 202 Accepted
{
"id": "syj_menu_20261012_0600",
"status": "queued"
}2 CHUAMTHANG Hub ERP กลาง
อ่านที่เปลี่ยนตั้งแต่ 2026-10-11T06:00
อ่านทะเบียน 186 รายการ พบเปลี่ยน 3 รายการ
3 CHUAMTHANG Hub CHUAMTHANG Hub
map ฟิลด์ + แปลงค่า
unit_price "87.85" (บาท ไม่รวม VAT) → price 9400 สตางค์รวม VAT · "11/10/2569" → ISO 8601
4 CHUAMTHANG Hub POS 60 สาขา
เขียน 180 ครั้ง (3 × 60)
ส่งราคาใหม่ไปทุกสาขาพร้อมกันครั้งละ 10 สาขา
5 POS 60 สาขา CHUAMTHANG Hub
174 สำเร็จ · 6 timeout
POS ของ brn_017 และ brn_052 ไม่ตอบ (ปิดเครื่องข้ามคืน) — ลองครบ 3 ครั้ง
6 CHUAMTHANG Hub ทีมปฏิบัติการasync
webhook sync.job.completed (partially_failed)
แจ้งทีมพร้อมตัวเลข
HTTP/1.1 200 OK
{
"type": "sync.job.completed",
"data": {
"id": "syj_menu_20261012_0600",
"status": "partially_failed",
"stats": {
"writes": 180,
"succeeded": 174,
"failed": 6
}
}
}7 ทีมปฏิบัติการ CHUAMTHANG Hub
POST /v1/sync/jobs (ทุกสาขา) ← ขณะงานเดิมยังลองซ้ำ
ทีมกดซิงก์ใหม่ทั้งหมดเร็วเกินไป
Console แสดงงานที่วิ่งอยู่ให้กดดู แทนการสร้างงานซ้ำที่อาจเขียนทับกัน
POST /v1/sync/jobs HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
{
"entity": "menu_price",
"direction": "erp_to_pos",
"mapping_id": "map_menu_erp_pos"
}HTTP/1.1 409 Conflict
{
"error": {
"code": "sync_job_running",
"running_job_id": "syj_menu_20261012_0600"
}
}8 ทีมปฏิบัติการ CHUAMTHANG Hub
GET /v1/sync/jobs/syj_menu_20261012_0600/failures
ดูว่าพลาดตรงไหน
GET /v1/sync/jobs/syj_menu_20261012_0600/failures HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWkHTTP/1.1 200 OK
{
"data": [
{
"branch_id": "brn_017",
"code": "upstream_timeout"
},
{
"branch_id": "brn_052",
"code": "upstream_timeout"
}
]
}9 ทีมปฏิบัติการ CHUAMTHANG Hub
POST /v1/sync/jobs (retry_of, 2 สาขา)
เมื่อสองสาขาเปิดร้าน สร้างงานซ่อมเฉพาะ 2 สาขา
POST /v1/sync/jobs HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
{
"entity": "menu_price",
"direction": "erp_to_pos",
"mode": "incremental",
"mapping_id": "map_menu_erp_pos",
"scope": {
"branches": [
"brn_017",
"brn_052"
]
},
"retry_of": "syj_menu_20261012_0600"
}HTTP/1.1 202 Accepted
{
"id": "syj_menu_20261012_0815",
"status": "queued",
"stats": {
"writes": 6
}
}10 CHUAMTHANG Hub POS 60 สาขา
เขียน 6 ครั้ง → สำเร็จ
ทุกสาขาใช้ราคาเดียวกันก่อนเปิดขายมื้อกลางวัน
ภายใน 3 นาที 42 วินาที 58 สาขาได้ราคาใหม่ · 2 สาขาที่ออฟไลน์ได้ตามมาด้วยงานซ่อมเฉพาะส่วน (6 รายการ) ไม่ต้องซิงก์ทั้งหมดใหม่
ข้อมูลชนกัน: เบอร์สมาชิก (ตัดสินเอง) และราคาสาขา (ให้คนตัดสิน)
เช้านี้มีข้อมูลถูกแก้พร้อมกันจากสองระบบ 2 เรื่อง — แต่ละเรื่องใช้กฎต่างกันตามความเสี่ยง
- POS สาขา 041
- CRM สมาชิก
- CHUAMTHANG Hub
- ERP กลาง
- ผู้จัดการเขตโซนเหนือ
- 1
POS สาขา 041 → CHUAMTHANG Hub
10:02 แคชเชียร์แก้เบอร์ของ mem_5Tq8 ตามที่ลูกค้าบอก (พิมพ์ผิด 1 หลัก)
- 2
CRM สมาชิก → CHUAMTHANG Hub
10:05 ลูกค้ายืนยันเบอร์เดิมด้วย OTP ในแอป
- 3
CHUAMTHANG Hub → CHUAMTHANG Hub
map_member_crm_pos ใช้ CRM เป็นระบบหลัก → ใช้ +66800000418
- 4
CHUAMTHANG Hub → POS สาขา 041
POS ได้เบอร์ที่ถูก — บันทึกเป็น auto_resolved
- 5
POS สาขา 041 → CHUAMTHANG Hub
08:45 ผู้จัดการสาขาตั้งราคาโปรเปิดร้านเองใน POS
- 6
CHUAMTHANG Hub → CHUAMTHANG Hub
ราคาใช้กฎให้คนตัดสิน (ผลกระทบต่อรายได้) — POS ขายราคาเดิมจาก ERP ฿94.00 ระหว่างรอ
- 7
CHUAMTHANG Hub → ผู้จัดการเขต
แจ้งผู้จัดการเขตในแอป
ไม่รอผล (async) - 8
ผู้จัดการเขต → CHUAMTHANG Hub
เปิดรายการรอตัดสิน
GET /v1/sync/conflicts?status=open&branch_id=brn_041 - 9
ผู้จัดการเขต → CHUAMTHANG Hub
เลือกราคากลางจาก ERP พร้อมบันทึกเหตุผล
POST /v1/sync/conflicts/syc_02/resolve - 10
CHUAMTHANG Hub → POS สาขา 041
POS สาขา 041 ล้างราคาที่ตั้งเอง
ไม่รอผล (async) - 11
CHUAMTHANG Hub → ERP กลาง
บันทึกว่าใครตัดสินอะไรเมื่อไร
เบอร์สมาชิกถูกต้องอัตโนมัติใน 1 วินาที (CRM ยืนยันด้วย OTP) · ราคาไม่ผ่านอนุมัติไม่หลุดขายเกิน 30 นาที · ทุกการตัดสินมีผู้รับผิดชอบในล็อก
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 POS สาขา 041 CHUAMTHANG Hub
phone → +66800000419
10:02 แคชเชียร์แก้เบอร์ของ mem_5Tq8 ตามที่ลูกค้าบอก (พิมพ์ผิด 1 หลัก)
2 CRM สมาชิก CHUAMTHANG Hub
phone = +66800000418 (OTP)
10:05 ลูกค้ายืนยันเบอร์เดิมด้วย OTP ในแอป
3 CHUAMTHANG Hub CHUAMTHANG Hub
ตรวจพบชนกัน → source_priority
map_member_crm_pos ใช้ CRM เป็นระบบหลัก → ใช้ +66800000418
4 CHUAMTHANG Hub POS สาขา 041
เขียนค่าที่ถูกกลับ
POS ได้เบอร์ที่ถูก — บันทึกเป็น auto_resolved
5 POS สาขา 041 CHUAMTHANG Hub
price MN-101 → ฿85.00
08:45 ผู้จัดการสาขาตั้งราคาโปรเปิดร้านเองใน POS
6 CHUAMTHANG Hub CHUAMTHANG Hub
ชนกับราคา ERP → manual_review
ราคาใช้กฎให้คนตัดสิน (ผลกระทบต่อรายได้) — POS ขายราคาเดิมจาก ERP ฿94.00 ระหว่างรอ
7 CHUAMTHANG Hub ผู้จัดการเขตasync
webhook sync.conflict.detected
แจ้งผู้จัดการเขตในแอป
HTTP/1.1 200 OK
{
"type": "sync.conflict.detected",
"data": {
"id": "syc_02",
"record_id": "MN-101@brn_041",
"values": [
9400,
8500
]
}
}8 ผู้จัดการเขต CHUAMTHANG Hub
GET /v1/sync/conflicts?status=open
เปิดรายการรอตัดสิน
GET /v1/sync/conflicts?status=open&branch_id=brn_041 HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWkHTTP/1.1 200 OK
{
"object": "list",
"data": [
{
"id": "syc_02",
"object": "sync_conflict",
"entity": "menu_price",
"record_id": "MN-101@brn_041",
"field": "price",
"values": [
{
"system": "erp",
"value": 9400,
"changed_at": "2026-10-12T06:00:00+07:00",
"by": "ฝ่ายการตลาดปรับราคาทุกสาขา"
},
{
"system": "pos",
"value": 8500,
"changed_at": "2026-10-12T08:45:00+07:00",
"by": "ผู้จัดการสาขาตั้งราคาโปรเปิดร้าน (ไม่ผ่านอนุมัติ)"
}
],
"rule": "manual_review",
"status": "open",
"suggested": {
"status": "resolved",
"value": 9400,
"winner": "erp",
"why": "ใช้ค่าจากระบบหลักของข้อมูลนี้ (ERP)"
},
"detected_at": "2026-10-12T08:45:03+07:00",
"resolved_at": null,
"resolution": null
}
],
"has_more": false,
"next_cursor": null
}9 ผู้จัดการเขต CHUAMTHANG Hub
POST /v1/sync/conflicts/syc_02/resolve
เลือกราคากลางจาก ERP พร้อมบันทึกเหตุผล
POST /v1/sync/conflicts/syc_02/resolve HTTP/1.1
Authorization: Bearer ct_test_4Lm9QxB27dWk
{
"choose": "erp",
"note": "ราคาโปรเปิดร้านไม่ผ่านอนุมัติ ใช้ราคากลาง",
"resolved_by": "emp_area_n_02"
}HTTP/1.1 200 OK
{
"id": "syc_02",
"status": "resolved",
"resolution": {
"choose": "erp",
"value": 9400
}
}10 CHUAMTHANG Hub POS สาขา 041async
price = 9400
POS สาขา 041 ล้างราคาที่ตั้งเอง
11 CHUAMTHANG Hub ERP กลาง
audit log
บันทึกว่าใครตัดสินอะไรเมื่อไร
เบอร์สมาชิกถูกต้องอัตโนมัติใน 1 วินาที (CRM ยืนยันด้วย OTP) · ราคาไม่ผ่านอนุมัติไม่หลุดขายเกิน 30 นาที · ทุกการตัดสินมีผู้รับผิดชอบในล็อก
Objects
The SyncJob object
งานซิงก์ 1 ครั้ง (ตัวอย่าง: ราคาเมนูรอบเช้า)
idstringไม่บังคับอ่านอย่างเดียวรหัสงาน
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
entitystringจำเป็นข้อมูลที่ซิงก์
directionstringจำเป็นทิศทาง (ระบบต้นทาง_to_ปลายทาง หรือสองทาง)
modestringไม่บังคับincremental = เฉพาะที่เปลี่ยนตั้งแต่ cursor · full = ทั้งหมด (ช้า ใช้แก้ข้อมูลเพี้ยน)
mapping_idstringจำเป็นการ map ฟิลด์ที่ใช้
triggerstringไม่บังคับอ่านอย่างเดียวที่มาของงาน
scopeobjectไม่บังคับขอบเขต
ฟิลด์ย่อยของ
scope(2)branchesarray<string>ไม่บังคับสาขาปลายทาง (all = ทุกสาขา)
record_idsarray<string>ไม่บังคับเฉพาะรายการ
statusstringไม่บังคับอ่านอย่างเดียวสถานะ
cursorobjectไม่บังคับอ่านอย่างเดียวช่วงการเปลี่ยนแปลงที่อ่าน (งานถัดไปเริ่มจาก to)
ฟิลด์ย่อยของ
cursor(3)fieldstringไม่บังคับฟิลด์ที่ใช้ตรวจการเปลี่ยน
fromstring · date-timeไม่บังคับตั้งแต่
tostring · date-timeไม่บังคับถึง
statsobjectไม่บังคับอ่านอย่างเดียวตัวเลขผล — writes = changed × targets
ฟิลด์ย่อยของ
stats(8)scannedintegerไม่บังคับระเบียนที่อ่านจากต้นทาง
changedintegerไม่บังคับระเบียนที่เปลี่ยนจริง
targetsintegerไม่บังคับจำนวนปลายทาง (สาขา)
writesintegerไม่บังคับจำนวนเขียนทั้งหมด
succeededintegerไม่บังคับเขียนสำเร็จ
failedintegerไม่บังคับเขียนไม่สำเร็จ
skippedintegerไม่บังคับข้าม (ค่าเหมือนเดิม)
conflictsintegerไม่บังคับพบข้อมูลชนกัน
failures_samplearray<object>ไม่บังคับอ่านอย่างเดียวตัวอย่างความล้มเหลว (ทั้งหมดที่ /failures)
ฟิลด์ย่อยของ
failures_sample(4)branch_idstringไม่บังคับสาขา
recordstringไม่บังคับระเบียน
codestringไม่บังคับรหัส
messagestringไม่บังคับข้อความ
started_atstring · date-timeไม่บังคับอ่านอย่างเดียวเริ่ม
finished_atstring · date-timeไม่บังคับอ่านอย่างเดียวจบ
duration_msintegerไม่บังคับอ่านอย่างเดียวใช้เวลา
next_run_atstring · date-timeไม่บังคับอ่านอย่างเดียวรอบถัดไป (งานตามรอบ)
retry_ofstringไม่บังคับอ่านอย่างเดียวถ้าเป็นงานซ่อม — รหัสงานเดิม
created_bystringไม่บังคับอ่านอย่างเดียวผู้สร้าง (ตารางเวลา / พนักงาน / event)
{
"id": "syj_menu_20261012_0600",
"object": "sync_job",
"entity": "menu_price",
"direction": "erp_to_pos",
"mode": "incremental",
"mapping_id": "map_menu_erp_pos",
"trigger": "schedule",
"scope": {
"branches": "all"
},
"status": "partially_failed",
"cursor": {
"field": "updated_at",
"from": "2026-10-11T06:00:00+07:00",
"to": "2026-10-12T05:59:59+07:00"
},
"stats": {
"scanned": 186,
"changed": 3,
"targets": 60,
"writes": 180,
"succeeded": 174,
"failed": 6,
"skipped": 0,
"conflicts": 1
},
"failures_sample": [
{
"branch_id": "brn_017",
"record": "MN-101",
"code": "upstream_timeout",
"message": "POS ของ brn_017 ไม่ตอบ (ออฟไลน์) หลังลอง 3 ครั้ง"
},
{
"branch_id": "brn_052",
"record": "MN-101",
"code": "upstream_timeout",
"message": "POS ของ brn_052 ไม่ตอบ (ออฟไลน์) หลังลอง 3 ครั้ง"
}
],
"started_at": "2026-10-12T06:00:00+07:00",
"finished_at": "2026-10-12T06:03:42+07:00",
"duration_ms": 222000,
"next_run_at": "2026-10-13T06:00:00+07:00",
"retry_of": null,
"created_by": "schedule:menu-price-daily"
}
The Mapping object
การ map ฟิลด์ ERP → POS ของเมนู
idstringไม่บังคับอ่านอย่างเดียวรหัสการ map
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
entitystringไม่บังคับอ่านอย่างเดียวข้อมูล
sourcestringไม่บังคับอ่านอย่างเดียวระบบต้นทาง
targetstringไม่บังคับอ่านอย่างเดียวระบบปลายทาง
versionintegerไม่บังคับอ่านอย่างเดียวเวอร์ชัน (เพิ่มทุกครั้งที่บันทึก · ใช้คู่กับ If-Match)
fieldsarray<object>จำเป็นกฎต่อฟิลด์ปลายทาง
ฟิลด์ย่อยของ
fields(4)targetstringจำเป็นฟิลด์ปลายทาง
sourcestringจำเป็นฟิลด์ต้นทาง
transformstringจำเป็นฟังก์ชันแปลง
requiredbooleanไม่บังคับอ่านอย่างเดียวปลายทางบังคับ (อ่านอย่างเดียว ตาม schema ปลายทาง)
lookupsobjectไม่บังคับตารางค่าที่ฟังก์ชัน lookup_* ใช้
conflict_rulestringจำเป็นกฎเมื่อข้อมูลชนกัน
masterstringไม่บังคับระบบหลักของข้อมูลนี้ (ใช้กับ source_priority)
previewobjectไม่บังคับอ่านอย่างเดียวตัวอย่างผลแปลงจากระเบียนจริง 1 รายการ
updated_atstring · date-timeไม่บังคับอ่านอย่างเดียวแก้ล่าสุด
updated_bystringไม่บังคับอ่านอย่างเดียวผู้แก้
{
"id": "map_menu_erp_pos",
"object": "sync_mapping",
"entity": "menu",
"source": "erp",
"target": "pos",
"version": 7,
"fields": [
{
"target": "sku",
"source": "item_code",
"transform": "sku_from_erp",
"required": true
},
{
"target": "name",
"source": "desc_th",
"transform": "trim",
"required": true
},
{
"target": "price",
"source": "unit_price",
"transform": "baht_to_satang_vat",
"required": true
},
{
"target": "category",
"source": "category_code",
"transform": "lookup_category",
"required": true
},
{
"target": "is_active",
"source": "status",
"transform": "flag_to_bool",
"required": true
},
{
"target": "updated_at",
"source": "updated_on",
"transform": "be_date_to_iso",
"required": false
}
],
"lookups": {
"category": {
"R01": "rice",
"S01": "soup",
"N01": "noodle",
"D01": "drink",
"X01": "dessert",
"T01": "set"
}
},
"conflict_rule": "source_priority",
"master": "erp",
"preview": {
"input": {
"item_code": "FG-10101",
"desc_th": " ข้าวกะเพราหมูกรอบไข่ดาว ",
"desc_en": "Crispy pork basil rice with fried egg",
"unit_price": "87.85",
"category_code": "R01",
"status": "A",
"updated_on": "11/10/2569",
"branch_scope": "ALL"
},
"output": {
"sku": "MN-101",
"name": "ข้าวกะเพราหมูกรอบไข่ดาว",
"price": 9400,
"category": "rice",
"is_active": true,
"updated_at": "2026-10-11T00:00:00+07:00"
}
},
"updated_at": "2026-08-20T15:00:00+07:00",
"updated_by": "emp_ho_it_01"
}
The Conflict object
ข้อมูลชนกัน 1 รายการ (ตัวอย่าง: ราคาที่สาขาตั้งเอง)
idstringไม่บังคับอ่านอย่างเดียวรหัสข้อมูลชนกัน
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
entitystringไม่บังคับอ่านอย่างเดียวข้อมูล
record_idstringไม่บังคับอ่านอย่างเดียวระเบียน (รหัส@สาขา สำหรับข้อมูลรายสาขา)
fieldstringไม่บังคับอ่านอย่างเดียวฟิลด์ที่ชน
valuesarray<object>ไม่บังคับอ่านอย่างเดียวค่าจากแต่ละระบบ
ฟิลด์ย่อยของ
values(4)systemstringไม่บังคับระบบ
valuestringไม่บังคับค่า (ชนิดตามฟิลด์)
changed_atstring · date-timeไม่บังคับแก้เมื่อ
bystringไม่บังคับใครแก้
rulestringไม่บังคับอ่านอย่างเดียวกฎที่ใช้กับข้อมูลนี้
statusstringไม่บังคับอ่านอย่างเดียวสถานะ (open = รอคนตัดสิน)
suggestedobjectไม่บังคับอ่านอย่างเดียวค่าที่ระบบแนะนำ (ตามระบบหลัก)
detected_atstring · date-timeไม่บังคับอ่านอย่างเดียวพบเมื่อ
resolved_atstring · date-timeไม่บังคับอ่านอย่างเดียวตัดสินเมื่อ
resolutionobjectไม่บังคับอ่านอย่างเดียวผลการตัดสิน
ฟิลด์ย่อยของ
resolution(4)choosestringไม่บังคับเลือกค่าจากระบบ หรือ custom
valuestringไม่บังคับค่าที่ใช้
bystringไม่บังคับผู้ตัดสิน
notestringไม่บังคับบันทึก
{
"id": "syc_02",
"object": "sync_conflict",
"entity": "menu_price",
"record_id": "MN-101@brn_041",
"field": "price",
"values": [
{
"system": "erp",
"value": 9400,
"changed_at": "2026-10-12T06:00:00+07:00",
"by": "ฝ่ายการตลาดปรับราคาทุกสาขา"
},
{
"system": "pos",
"value": 8500,
"changed_at": "2026-10-12T08:45:00+07:00",
"by": "ผู้จัดการสาขาตั้งราคาโปรเปิดร้าน (ไม่ผ่านอนุมัติ)"
}
],
"rule": "manual_review",
"status": "open",
"suggested": {
"status": "resolved",
"value": 9400,
"winner": "erp",
"why": "ใช้ค่าจากระบบหลักของข้อมูลนี้ (ERP)"
},
"detected_at": "2026-10-12T08:45:03+07:00",
"resolved_at": null,
"resolution": null
}Endpoints (10)
| Method | Path | ทำอะไร | scope |
|---|---|---|---|
| POST | /v1/sync/jobs | สั่งงานซิงก์idempotent | sync.jobs:write |
| GET | /v1/sync/jobs/{job_id} | ดูงานซิงก์ | sync.jobs:read |
| GET | /v1/sync/jobs | รายการงานซิงก์ | sync.jobs:read |
| POST | /v1/sync/jobs/{job_id}/cancel | ยกเลิกงานซิงก์ | sync.jobs:write |
| GET | /v1/sync/jobs/{job_id}/failures | ความล้มเหลวของงาน | sync.jobs:read |
| GET | /v1/sync/mappings | รายการการ map ฟิลด์ | sync.mappings:read |
| PUT | /v1/sync/mappings/{mapping_id} | บันทึกการ map ฟิลด์ | sync.mappings:write |
| GET | /v1/sync/conflicts | รายการข้อมูลชนกัน | sync.conflicts:read |
| POST | /v1/sync/conflicts/{conflict_id}/resolve | ตัดสินข้อมูลชนกันidempotent | sync.conflicts:write |
| GET | /v1/sync/changes | Change feed (อ่านการเปลี่ยนแปลงตาม cursor) | sync.changes:read |
สั่งงานซิงก์
สั่งซิงก์ทันที (นอกตารางเวลา) — เลือกข้อมูล ทิศทาง โหมด และขอบเขตสาขา · งานวิ่งแบบเบื้องหลัง ผลมาทาง webhook
Headersheader
Idempotency-Keystring · uuidไม่บังคับกันรายการซ้ำเมื่อส่งซ้ำ (เก็บ 24 ชม.) — แนะนำ UUID v4 ต่อ 1 รายการ
Request bodyapplication/json
entitystringจำเป็นข้อมูล
directionstringจำเป็นทิศทาง
modestringไม่บังคับโหมด
mapping_idstringจำเป็นการ map
scopeobjectไม่บังคับขอบเขต
ฟิลด์ย่อยของ
scope(2)branchesarray<string>ไม่บังคับสาขา
record_idsarray<string>ไม่บังคับเฉพาะรายการ
retry_ofstringไม่บังคับอ้างงานเดิมเมื่อเป็นงานซ่อม (ใช้ cursor เดิม)
ผลลัพธ์
- 202เข้าคิวแล้ว (งานซ่อม 2 สาขา × 3 รายการ)
- 409มีงานชนิดเดียวกันกำลังวิ่ง
- 400
invalid_requestคำขอไม่ถูกต้อง - 422
entity_unsupportedไม่รองรับข้อมูลชนิดนี้ - 409
sync_job_runningมีงานซิงก์ข้อมูลชนิดนี้กำลังทำอยู่ - 422
mapping_invalidการ map ฟิลด์ไม่ถูกต้อง - 409
idempotency_conflictIdempotency-Key ซ้ำแต่เนื้อหาต่าง - 429
rate_limitedเรียกเกินโควตา
- งาน full ของ member ทั้งองค์กรใช้เวลา ~40 นาที — ใช้ incremental เป็นหลัก
- ทิศทาง two_way ใช้ได้กับ member เท่านั้น และต้องมี conflict_rule
curl -X POST "https://sandbox.api.chuamthang.example/v1/sync/jobs" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Chuamthang-Version: 2026-08-01" \
-d '{
"entity": "menu_price",
"direction": "erp_to_pos",
"mode": "incremental",
"mapping_id": "map_menu_erp_pos",
"scope": {
"branches": [
"brn_017",
"brn_052"
]
},
"retry_of": "syj_menu_20261012_0600"
}'const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/jobs', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Chuamthang-Version': '2026-08-01',
},
body: JSON.stringify({
"entity": "menu_price",
"direction": "erp_to_pos",
"mode": "incremental",
"mapping_id": "map_menu_erp_pos",
"scope": {
"branches": [
"brn_017",
"brn_052"
]
},
"retry_of": "syj_menu_20261012_0600"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.post(
"https://sandbox.api.chuamthang.example/v1/sync/jobs",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Chuamthang-Version": "2026-08-01",
},
json={
"entity": "menu_price",
"direction": "erp_to_pos",
"mode": "incremental",
"mapping_id": "map_menu_erp_pos",
"scope": {
"branches": [
"brn_017",
"brn_052"
]
},
"retry_of": "syj_menu_20261012_0600"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "syj_menu_20261012_0815",
"object": "sync_job",
"entity": "menu_price",
"direction": "erp_to_pos",
"status": "queued",
"scope": {
"branches": [
"brn_017",
"brn_052"
]
},
"retry_of": "syj_menu_20261012_0600",
"stats": {
"targets": 2,
"writes": 6
}
}{
"error": {
"code": "sync_job_running",
"message": "menu_price erp_to_pos กำลังซิงก์อยู่ (syj_menu_20261012_0600)",
"running_job_id": "syj_menu_20261012_0600",
"request_id": "req_4Hs8Qp2E"
}
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}{
"error": {
"code": "entity_unsupported",
"message": "ไม่รองรับข้อมูลชนิดนี้",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#entity_unsupported"
}
}{
"error": {
"code": "sync_job_running",
"message": "มีงานซิงก์ข้อมูลชนิดนี้กำลังทำอยู่",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#sync_job_running"
}
}{
"error": {
"code": "mapping_invalid",
"message": "การ map ฟิลด์ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#mapping_invalid"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่เนื้อหาต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#idempotency_conflict"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#rate_limited"
}
}ดูงานซิงก์
สถานะ ช่วง cursor ตัวเลขผล และตัวอย่างความล้มเหลว
Path parameterspath
job_idstringจำเป็นรหัสงาน (syj_…)
ผลลัพธ์
- 200งานรอบ 06:00: เขียน 180 ครั้ง สำเร็จ 174 ล้มเหลว 6
- 404
resource_not_foundไม่พบข้อมูล - 401
unauthorizedไม่ได้ยืนยันตัวตน
curl -X GET "https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0600" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0600', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0600",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "syj_menu_20261012_0600",
"object": "sync_job",
"entity": "menu_price",
"direction": "erp_to_pos",
"mode": "incremental",
"mapping_id": "map_menu_erp_pos",
"trigger": "schedule",
"scope": {
"branches": "all"
},
"status": "partially_failed",
"cursor": {
"field": "updated_at",
"from": "2026-10-11T06:00:00+07:00",
"to": "2026-10-12T05:59:59+07:00"
},
"stats": {
"scanned": 186,
"changed": 3,
"targets": 60,
"writes": 180,
"succeeded": 174,
"failed": 6,
"skipped": 0,
"conflicts": 1
},
"failures_sample": [
{
"branch_id": "brn_017",
"record": "MN-101",
"code": "upstream_timeout",
"message": "POS ของ brn_017 ไม่ตอบ (ออฟไลน์) หลังลอง 3 ครั้ง"
},
{
"branch_id": "brn_052",
"record": "MN-101",
"code": "upstream_timeout",
"message": "POS ของ brn_052 ไม่ตอบ (ออฟไลน์) หลังลอง 3 ครั้ง"
}
],
"started_at": "2026-10-12T06:00:00+07:00",
"finished_at": "2026-10-12T06:03:42+07:00",
"duration_ms": 222000,
"next_run_at": "2026-10-13T06:00:00+07:00",
"retry_of": null,
"created_by": "schedule:menu-price-daily"
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#resource_not_found"
}
}{
"error": {
"code": "unauthorized",
"message": "ไม่ได้ยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#unauthorized"
}
}รายการงานซิงก์
ประวัติงานทั้งหมด กรองตามข้อมูล ทิศทาง สถานะ ช่วงเวลา
Query parametersquery
entitystringไม่บังคับข้อมูล
statusstringไม่บังคับสถานะ
triggerstringไม่บังคับที่มา
started_fromstring · date-timeไม่บังคับเริ่มตั้งแต่
sortstringไม่บังคับเรียงลำดับ — ใส่ - นำหน้าเพื่อเรียงจากมากไปน้อย
limitintegerไม่บังคับจำนวนรายการต่อหน้า
starting_afterstringไม่บังคับcursor — รหัสของรายการสุดท้ายในหน้าก่อน (ใช้ค่า next_cursor ที่ได้)
ending_beforestringไม่บังคับcursor ย้อนกลับ — รหัสของรายการแรกในหน้าปัจจุบัน
ผลลัพธ์
- 200งาน
- 400
invalid_requestคำขอไม่ถูกต้อง
curl -X GET "https://sandbox.api.chuamthang.example/v1/sync/jobs?started_from=2026-10-12T00%3A00%3A00%2B07%3A00&limit=20" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/jobs?started_from=2026-10-12T00%3A00%3A00%2B07%3A00&limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/sync/jobs?started_from=2026-10-12T00%3A00%3A00%2B07%3A00&limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"data": [
{
"id": "syj_menu_20261012_0600",
"entity": "menu_price",
"direction": "erp_to_pos",
"status": "partially_failed",
"started_at": "2026-10-12T06:00:00+07:00",
"stats": {
"writes": 180,
"failed": 6
}
},
{
"id": "syj_member_20261012_0930",
"entity": "member",
"direction": "two_way",
"status": "succeeded",
"started_at": "2026-10-12T09:30:00+07:00",
"stats": {
"writes": 412,
"failed": 0,
"conflicts": 1
}
},
{
"id": "syj_stock_20261012_0915",
"entity": "stock",
"direction": "pos_to_erp",
"status": "succeeded",
"started_at": "2026-10-12T09:15:00+07:00",
"stats": {
"writes": 60,
"failed": 0
}
}
],
"has_more": true,
"next_cursor": "syj_stock_20261012_0915"
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}ยกเลิกงานซิงก์
POST/v1/sync/jobs/{job_id}/cancel
หยุดงานที่ queued/running — ระเบียนที่เขียนไปแล้วไม่ย้อนกลับ (cursor ไม่ขยับ งานถัดไปจะอ่านช่วงเดิมซ้ำ)
Path parameterspath
job_idstringจำเป็นรหัสงาน
Request bodyapplication/json
reasonstringจำเป็นเหตุผล
ผลลัพธ์
- 200ยกเลิกแล้ว
- 409งานจบไปแล้ว
- 404
resource_not_foundไม่พบข้อมูล - 409
sync_job_finishedงานซิงก์จบแล้ว
curl -X POST "https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0815/cancel" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Content-Type: application/json" \
-H "Chuamthang-Version: 2026-08-01" \
-d '{
"reason": "สั่งผิดสาขา"
}'const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0815/cancel', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Chuamthang-Version': '2026-08-01',
},
body: JSON.stringify({
"reason": "สั่งผิดสาขา"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.post(
"https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0815/cancel",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Chuamthang-Version": "2026-08-01",
},
json={
"reason": "สั่งผิดสาขา"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "syj_menu_20261012_0815",
"status": "canceled",
"stats": {
"writes": 6,
"succeeded": 2,
"failed": 0
}
}{
"error": {
"code": "sync_job_finished",
"message": "งานนี้ succeeded แล้ว ยกเลิกไม่ได้"
}
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#resource_not_found"
}
}{
"error": {
"code": "sync_job_finished",
"message": "งานซิงก์จบแล้ว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#sync_job_finished"
}
}ความล้มเหลวของงาน
GET/v1/sync/jobs/{job_id}/failures
ทุกระเบียน × ปลายทางที่เขียนไม่สำเร็จ พร้อมสาเหตุ — ใช้สร้างงานซ่อมเฉพาะส่วนที่พลาด
Path parameterspath
job_idstringจำเป็นรหัสงาน (syj_…)
Query parametersquery
codestringไม่บังคับกรองรหัส
limitintegerไม่บังคับจำนวนรายการต่อหน้า
starting_afterstringไม่บังคับcursor — รหัสของรายการสุดท้ายในหน้าก่อน (ใช้ค่า next_cursor ที่ได้)
ผลลัพธ์
- 2006 รายการ (2 สาขาออฟไลน์ × 3 เมนู)
- 404
resource_not_foundไม่พบข้อมูล
curl -X GET "https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0600/failures?code=upstream_timeout&limit=20" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0600/failures?code=upstream_timeout&limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/sync/jobs/syj_menu_20261012_0600/failures?code=upstream_timeout&limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"data": [
{
"branch_id": "brn_017",
"record": "MN-101",
"code": "upstream_timeout",
"attempts": 3,
"last_attempt_at": "2026-10-12T06:03:30+07:00"
},
{
"branch_id": "brn_017",
"record": "MN-102",
"code": "upstream_timeout",
"attempts": 3,
"last_attempt_at": "2026-10-12T06:03:30+07:00"
},
{
"branch_id": "brn_017",
"record": "MN-901",
"code": "upstream_timeout",
"attempts": 3,
"last_attempt_at": "2026-10-12T06:03:30+07:00"
},
{
"branch_id": "brn_052",
"record": "MN-101",
"code": "upstream_timeout",
"attempts": 3,
"last_attempt_at": "2026-10-12T06:03:30+07:00"
},
{
"branch_id": "brn_052",
"record": "MN-102",
"code": "upstream_timeout",
"attempts": 3,
"last_attempt_at": "2026-10-12T06:03:30+07:00"
},
{
"branch_id": "brn_052",
"record": "MN-901",
"code": "upstream_timeout",
"attempts": 3,
"last_attempt_at": "2026-10-12T06:03:30+07:00"
}
],
"has_more": false,
"next_cursor": null
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#resource_not_found"
}
}รายการการ map ฟิลด์
การ map ทุกชุด (ต้นทาง → ปลายทาง) พร้อมกฎข้อมูลชนกันและตัวอย่างผลแปลง
Query parametersquery
entitystringไม่บังคับข้อมูล
sourcestringไม่บังคับต้นทาง
limitintegerไม่บังคับจำนวนรายการต่อหน้า
starting_afterstringไม่บังคับcursor — รหัสของรายการสุดท้ายในหน้าก่อน (ใช้ค่า next_cursor ที่ได้)
ผลลัพธ์
- 200การ map
- 403
insufficient_scopeสิทธิ์ของคีย์ไม่พอ
curl -X GET "https://sandbox.api.chuamthang.example/v1/sync/mappings?limit=20" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/mappings?limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/sync/mappings?limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"data": [
{
"id": "map_menu_erp_pos",
"object": "sync_mapping",
"entity": "menu",
"source": "erp",
"target": "pos",
"version": 7,
"fields": [
{
"target": "sku",
"source": "item_code",
"transform": "sku_from_erp",
"required": true
},
{
"target": "name",
"source": "desc_th",
"transform": "trim",
"required": true
},
{
"target": "price",
"source": "unit_price",
"transform": "baht_to_satang_vat",
"required": true
},
{
"target": "category",
"source": "category_code",
"transform": "lookup_category",
"required": true
},
{
"target": "is_active",
"source": "status",
"transform": "flag_to_bool",
"required": true
},
{
"target": "updated_at",
"source": "updated_on",
"transform": "be_date_to_iso",
"required": false
}
],
"lookups": {
"category": {
"R01": "rice",
"S01": "soup",
"N01": "noodle",
"D01": "drink",
"X01": "dessert",
"T01": "set"
}
},
"conflict_rule": "source_priority",
"master": "erp",
"preview": {
"input": {
"item_code": "FG-10101",
"desc_th": " ข้าวกะเพราหมูกรอบไข่ดาว ",
"desc_en": "Crispy pork basil rice with fried egg",
"unit_price": "87.85",
"category_code": "R01",
"status": "A",
"updated_on": "11/10/2569",
"branch_scope": "ALL"
},
"output": {
"sku": "MN-101",
"name": "ข้าวกะเพราหมูกรอบไข่ดาว",
"price": 9400,
"category": "rice",
"is_active": true,
"updated_at": "2026-10-11T00:00:00+07:00"
}
},
"updated_at": "2026-08-20T15:00:00+07:00",
"updated_by": "emp_ho_it_01"
},
{
"id": "map_member_crm_pos",
"object": "sync_mapping",
"entity": "member",
"source": "crm",
"target": "pos",
"version": 4,
"conflict_rule": "source_priority",
"master": "crm"
},
{
"id": "map_price_branch",
"object": "sync_mapping",
"entity": "menu_price",
"source": "erp",
"target": "pos",
"version": 3,
"conflict_rule": "manual_review",
"master": "erp"
}
],
"has_more": false,
"next_cursor": null
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ของคีย์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#insufficient_scope"
}
}บันทึกการ map ฟิลด์
PUT/v1/sync/mappings/{mapping_id}
แทนที่กฎทั้งชุด — ตรวจว่าฟิลด์จำเป็นของปลายทางถูกจับคู่ครบ และชนิดผลลัพธ์ของฟังก์ชันแปลงตรงกับปลายทาง · ใช้ dry_run ดูผลกับระเบียนจริงก่อน
Path parameterspath
mapping_idstringจำเป็นรหัสการ map
Headersheader
If-Matchstringไม่บังคับETag ของข้อมูลที่อ่านล่าสุด — กันเขียนทับการแก้ของคนอื่น (ได้ 412 ถ้าไม่ตรง)
Request bodyapplication/json
fieldsarray<object>จำเป็นกฎต่อฟิลด์
ฟิลด์ย่อยของ
fields(3)targetstringจำเป็นฟิลด์ปลายทาง
sourcestringจำเป็นฟิลด์ต้นทาง
transformstringจำเป็นฟังก์ชันแปลง
lookupsobjectไม่บังคับตารางค่า
conflict_rulestringจำเป็นกฎข้อมูลชนกัน
masterstringไม่บังคับระบบหลัก
dry_runbooleanไม่บังคับทดสอบกับระเบียนตัวอย่างโดยไม่บันทึก
sample_record_idstringไม่บังคับระเบียนที่ใช้ทดสอบ
ผลลัพธ์
- 200dry run ผ่าน: unit_price "87.85" → price 9400 (฿94.00 รวม VAT)
- 422ชนิดไม่ตรง (เลือก baht_to_satang ผิดเป็น identity)
- 422
mapping_invalidการ map ฟิลด์ไม่ถูกต้อง - 422
transform_failedฟังก์ชันแปลงค่าล้มเหลว - 412
precondition_failedข้อมูลถูกแก้ไปก่อนแล้ว - 404
resource_not_foundไม่พบข้อมูล - 422
validation_failedข้อมูลไม่ผ่านกฎธุรกิจ
- ใช้เครื่องมือจำลองท้ายหน้าทดลองจับคู่และฟังก์ชันแปลงก่อนส่งจริง
- บันทึกแล้วมีผลกับงานถัดไป งานที่วิ่งอยู่ใช้เวอร์ชันเดิมจนจบ
curl -X PUT "https://sandbox.api.chuamthang.example/v1/sync/mappings/map_menu_erp_pos" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Content-Type: application/json" \
-H "Chuamthang-Version: 2026-08-01" \
-d '{
"fields": [
{
"target": "sku",
"source": "item_code",
"transform": "sku_from_erp"
},
{
"target": "name",
"source": "desc_th",
"transform": "trim"
},
{
"target": "price",
"source": "unit_price",
"transform": "baht_to_satang_vat"
},
{
"target": "category",
"source": "category_code",
"transform": "lookup_category"
},
{
"target": "is_active",
"source": "status",
"transform": "flag_to_bool"
},
{
"target": "updated_at",
"source": "updated_on",
"transform": "be_date_to_iso"
}
],
"lookups": {
"category": {
"R01": "rice",
"S01": "soup",
"N01": "noodle",
"D01": "drink",
"X01": "dessert",
"T01": "set"
}
},
"conflict_rule": "source_priority",
"master": "erp",
"dry_run": true,
"sample_record_id": "FG-10101"
}'const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/mappings/map_menu_erp_pos', {
method: 'PUT',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Chuamthang-Version': '2026-08-01',
},
body: JSON.stringify({
"fields": [
{
"target": "sku",
"source": "item_code",
"transform": "sku_from_erp"
},
{
"target": "name",
"source": "desc_th",
"transform": "trim"
},
{
"target": "price",
"source": "unit_price",
"transform": "baht_to_satang_vat"
},
{
"target": "category",
"source": "category_code",
"transform": "lookup_category"
},
{
"target": "is_active",
"source": "status",
"transform": "flag_to_bool"
},
{
"target": "updated_at",
"source": "updated_on",
"transform": "be_date_to_iso"
}
],
"lookups": {
"category": {
"R01": "rice",
"S01": "soup",
"N01": "noodle",
"D01": "drink",
"X01": "dessert",
"T01": "set"
}
},
"conflict_rule": "source_priority",
"master": "erp",
"dry_run": true,
"sample_record_id": "FG-10101"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.put(
"https://sandbox.api.chuamthang.example/v1/sync/mappings/map_menu_erp_pos",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Chuamthang-Version": "2026-08-01",
},
json={
"fields": [
{
"target": "sku",
"source": "item_code",
"transform": "sku_from_erp"
},
{
"target": "name",
"source": "desc_th",
"transform": "trim"
},
{
"target": "price",
"source": "unit_price",
"transform": "baht_to_satang_vat"
},
{
"target": "category",
"source": "category_code",
"transform": "lookup_category"
},
{
"target": "is_active",
"source": "status",
"transform": "flag_to_bool"
},
{
"target": "updated_at",
"source": "updated_on",
"transform": "be_date_to_iso"
}
],
"lookups": {
"category": {
"R01": "rice",
"S01": "soup",
"N01": "noodle",
"D01": "drink",
"X01": "dessert",
"T01": "set"
}
},
"conflict_rule": "source_priority",
"master": "erp",
"dry_run": True,
"sample_record_id": "FG-10101"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"dry_run": true,
"valid": true,
"preview": {
"input": {
"item_code": "FG-10101",
"desc_th": " ข้าวกะเพราหมูกรอบไข่ดาว ",
"desc_en": "Crispy pork basil rice with fried egg",
"unit_price": "87.85",
"category_code": "R01",
"status": "A",
"updated_on": "11/10/2569",
"branch_scope": "ALL"
},
"output": {
"sku": "MN-101",
"name": "ข้าวกะเพราหมูกรอบไข่ดาว",
"price": 9400,
"category": "rice",
"is_active": true,
"updated_at": "2026-10-11T00:00:00+07:00"
}
}
}{
"error": {
"code": "mapping_invalid",
"message": "การ map ฟิลด์ไม่ถูกต้อง",
"details": [
{
"field": "price",
"message": "ได้ชนิด string แต่ปลายทางต้องการ integer"
}
]
}
}{
"error": {
"code": "mapping_invalid",
"message": "การ map ฟิลด์ไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#mapping_invalid"
}
}{
"error": {
"code": "transform_failed",
"message": "ฟังก์ชันแปลงค่าล้มเหลว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#transform_failed"
}
}{
"error": {
"code": "precondition_failed",
"message": "ข้อมูลถูกแก้ไปก่อนแล้ว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#precondition_failed"
}
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#resource_not_found"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านกฎธุรกิจ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#validation_failed"
}
}รายการข้อมูลชนกัน
ข้อมูลที่ถูกแก้ในสองระบบในช่วงซิงก์เดียวกัน — ทั้งที่กฎตัดสินเองแล้ว (auto_resolved) และที่รอคนตัดสิน (open)
Query parametersquery
statusstringไม่บังคับสถานะ
entitystringไม่บังคับข้อมูล
branch_idstringไม่บังคับสาขา
limitintegerไม่บังคับจำนวนรายการต่อหน้า
starting_afterstringไม่บังคับcursor — รหัสของรายการสุดท้ายในหน้าก่อน (ใช้ค่า next_cursor ที่ได้)
ผลลัพธ์
- 200ข้อมูลชนกัน
- 400
invalid_requestคำขอไม่ถูกต้อง - 403
insufficient_scopeสิทธิ์ของคีย์ไม่พอ
curl -X GET "https://sandbox.api.chuamthang.example/v1/sync/conflicts?status=open&limit=20" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/conflicts?status=open&limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/sync/conflicts?status=open&limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"data": [
{
"id": "syc_02",
"object": "sync_conflict",
"entity": "menu_price",
"record_id": "MN-101@brn_041",
"field": "price",
"values": [
{
"system": "erp",
"value": 9400,
"changed_at": "2026-10-12T06:00:00+07:00",
"by": "ฝ่ายการตลาดปรับราคาทุกสาขา"
},
{
"system": "pos",
"value": 8500,
"changed_at": "2026-10-12T08:45:00+07:00",
"by": "ผู้จัดการสาขาตั้งราคาโปรเปิดร้าน (ไม่ผ่านอนุมัติ)"
}
],
"rule": "manual_review",
"status": "open",
"suggested": {
"status": "resolved",
"value": 9400,
"winner": "erp",
"why": "ใช้ค่าจากระบบหลักของข้อมูลนี้ (ERP)"
},
"detected_at": "2026-10-12T08:45:03+07:00",
"resolved_at": null,
"resolution": null
},
{
"id": "syc_01",
"object": "sync_conflict",
"entity": "member",
"record_id": "mem_5Tq8",
"field": "phone",
"rule": "source_priority",
"status": "auto_resolved",
"resolution": {
"choose": "crm",
"value": "+66800000418",
"by": "rule:source_priority"
}
}
],
"has_more": false,
"next_cursor": null
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ของคีย์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#insufficient_scope"
}
}ตัดสินข้อมูลชนกัน
POST/v1/sync/conflicts/{conflict_id}/resolve
เลือกค่าที่ถูก (จากระบบใด หรือกำหนดเอง) — Hub เขียนค่าที่เลือกกลับไปทุกระบบที่เกี่ยวข้องและบันทึกผู้ตัดสิน
Path parameterspath
conflict_idstringจำเป็นรหัส syc_…
Headersheader
Idempotency-Keystring · uuidไม่บังคับกันรายการซ้ำเมื่อส่งซ้ำ (เก็บ 24 ชม.) — แนะนำ UUID v4 ต่อ 1 รายการ
Request bodyapplication/json
choosestringจำเป็นเลือกค่าจากระบบ หรือ custom
valuestringไม่บังคับค่าเมื่อ choose = custom
notestringไม่บังคับบันทึกเหตุผล
resolved_bystringจำเป็นผู้ตัดสิน
ผลลัพธ์
- 200ใช้ราคา ERP ฿94.00 — POS สาขา 041 อัปเดตใน 5 วินาที
- 404
resource_not_foundไม่พบข้อมูล - 409
conflict_already_resolvedข้อมูลชนกันนี้จัดการแล้ว - 422
validation_failedข้อมูลไม่ผ่านกฎธุรกิจ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่เนื้อหาต่าง
curl -X POST "https://sandbox.api.chuamthang.example/v1/sync/conflicts/syc_02/resolve" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "Chuamthang-Version: 2026-08-01" \
-d '{
"choose": "erp",
"value": "",
"note": "ราคาโปรเปิดร้านไม่ผ่านอนุมัติ ใช้ราคากลาง",
"resolved_by": "emp_area_n_02"
}'const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/conflicts/syc_02/resolve', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'Chuamthang-Version': '2026-08-01',
},
body: JSON.stringify({
"choose": "erp",
"value": "",
"note": "ราคาโปรเปิดร้านไม่ผ่านอนุมัติ ใช้ราคากลาง",
"resolved_by": "emp_area_n_02"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.post(
"https://sandbox.api.chuamthang.example/v1/sync/conflicts/syc_02/resolve",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"Chuamthang-Version": "2026-08-01",
},
json={
"choose": "erp",
"value": "",
"note": "ราคาโปรเปิดร้านไม่ผ่านอนุมัติ ใช้ราคากลาง",
"resolved_by": "emp_area_n_02"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "syc_02",
"object": "sync_conflict",
"entity": "menu_price",
"record_id": "MN-101@brn_041",
"field": "price",
"values": [
{
"system": "erp",
"value": 9400,
"changed_at": "2026-10-12T06:00:00+07:00",
"by": "ฝ่ายการตลาดปรับราคาทุกสาขา"
},
{
"system": "pos",
"value": 8500,
"changed_at": "2026-10-12T08:45:00+07:00",
"by": "ผู้จัดการสาขาตั้งราคาโปรเปิดร้าน (ไม่ผ่านอนุมัติ)"
}
],
"rule": "manual_review",
"status": "resolved",
"suggested": {
"status": "resolved",
"value": 9400,
"winner": "erp",
"why": "ใช้ค่าจากระบบหลักของข้อมูลนี้ (ERP)"
},
"detected_at": "2026-10-12T08:45:03+07:00",
"resolved_at": "2026-10-12T09:12:00+07:00",
"resolution": {
"choose": "erp",
"value": 9400,
"by": "emp_area_n_02",
"note": "ราคาโปรเปิดร้านไม่ผ่านอนุมัติ ใช้ราคากลาง"
}
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#resource_not_found"
}
}{
"error": {
"code": "conflict_already_resolved",
"message": "ข้อมูลชนกันนี้จัดการแล้ว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#conflict_already_resolved"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านกฎธุรกิจ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#validation_failed"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่เนื้อหาต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#idempotency_conflict"
}
}Change feed (อ่านการเปลี่ยนแปลงตาม cursor)
อ่านรายการที่เปลี่ยนตั้งแต่ cursor สำหรับระบบที่อยากดึงเอง (เช่น BI) — ส่ง cursor ที่ได้ครั้งก่อนเพื่ออ่านต่อโดยไม่ตกหล่น
Query parametersquery
entitystringจำเป็นข้อมูล
cursorstringไม่บังคับcursor จากครั้งก่อน (ไม่ส่ง = เริ่มจาก 7 วันก่อน)
limitintegerไม่บังคับจำนวนรายการต่อหน้า
ผลลัพธ์
- 200การเปลี่ยนแปลง (เรียงตามเวลา)
- 400
invalid_requestคำขอไม่ถูกต้อง - 422
entity_unsupportedไม่รองรับข้อมูลชนิดนี้ - 429
rate_limitedเรียกเกินโควตา
- cursor ใช้ได้ 7 วัน — เก่ากว่านั้นต้องทำ full sync
curl -X GET "https://sandbox.api.chuamthang.example/v1/sync/changes?entity=menu_price&cursor=chg_20261011T060000_000418&limit=20" \
-H "Authorization: Bearer ct_test_4Lm9QxB27dWk" \
-H "Chuamthang-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // ct_test_4Lm9QxB27dWk
const res = await fetch('https://sandbox.api.chuamthang.example/v1/sync/changes?entity=menu_price&cursor=chg_20261011T060000_000418&limit=20', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Chuamthang-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # ct_test_4Lm9QxB27dWk
res = requests.get(
"https://sandbox.api.chuamthang.example/v1/sync/changes?entity=menu_price&cursor=chg_20261011T060000_000418&limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"Chuamthang-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"data": [
{
"seq": "chg_20261012T055812_000431",
"entity": "menu_price",
"record_id": "MN-101",
"op": "update",
"changed": {
"price": {
"from": 8900,
"to": 9400
}
},
"at": "2026-10-12T05:58:12+07:00",
"by": "erp"
}
],
"next_cursor": "chg_20261012T055812_000431",
"has_more": false
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}{
"error": {
"code": "entity_unsupported",
"message": "ไม่รองรับข้อมูลชนิดนี้",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#entity_unsupported"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#rate_limited"
}
}Webhooks — แจ้งเหตุการณ์ไปที่ระบบของคุณ
ลงทะเบียน URL ปลายทาง แล้วระบบจะส่ง POST พร้อม JSON ทุกครั้งที่เกิดเหตุการณ์ด้านล่าง · ตอบกลับ 2xx ภายใน 10 วินาที ไม่งั้นจะส่งซ้ำตามตาราง · ทุกคำขอมีหัว Chuamthang-Signature ให้ตรวจว่ามาจากเราจริง · event อาจมาซ้ำหรือสลับลำดับ ให้ใช้ id กันประมวลผลซ้ำ
sync.job.completedงานซิงก์จบ (ทุกสถานะสุดท้าย)
ส่งเมื่อ: succeeded / partially_failed / failed / canceled
{
"id": "evt_01JB7Q00",
"type": "sync.job.completed",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "syj_menu_20261012_0600",
"entity": "menu_price",
"status": "partially_failed",
"stats": {
"scanned": 186,
"changed": 3,
"targets": 60,
"writes": 180,
"succeeded": 174,
"failed": 6,
"skipped": 0,
"conflicts": 1
},
"finished_at": "2026-10-12T06:03:42+07:00"
}
}sync.job.failedงานล้มเหลวทั้งงาน
ส่งเมื่อ: อ่านต้นทางไม่ได้ หรือ mapping ผิด
{
"id": "evt_01JB7Q01",
"type": "sync.job.failed",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "syj_stock_20261010_1415",
"entity": "stock",
"status": "failed",
"error": {
"code": "upstream_error",
"message": "ERP ตอบ 503 ระหว่างปิดงวด"
}
}
}sync.conflict.detectedพบข้อมูลชนกันที่ต้องให้คนตัดสิน
ส่งเมื่อ: กฎ = manual_review
{
"id": "evt_01JB7Q02",
"type": "sync.conflict.detected",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "syc_02",
"entity": "menu_price",
"record_id": "MN-101@brn_041",
"field": "price",
"values": [
{
"system": "erp",
"value": 9400,
"changed_at": "2026-10-12T06:00:00+07:00",
"by": "ฝ่ายการตลาดปรับราคาทุกสาขา"
},
{
"system": "pos",
"value": 8500,
"changed_at": "2026-10-12T08:45:00+07:00",
"by": "ผู้จัดการสาขาตั้งราคาโปรเปิดร้าน (ไม่ผ่านอนุมัติ)"
}
]
}
}sync.conflict.resolvedตัดสินข้อมูลชนกันแล้ว
ส่งเมื่อ: กฎตัดสินเอง หรือมีคนตัดสิน
{
"id": "evt_01JB7Q03",
"type": "sync.conflict.resolved",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "syc_01",
"status": "auto_resolved",
"resolution": {
"choose": "crm",
"value": "+66800000418",
"by": "rule:source_priority"
}
}
}sync.mapping.updatedการ map ถูกแก้
ส่งเมื่อ: PUT /v1/sync/mappings สำเร็จ
{
"id": "evt_01JB7Q04",
"type": "sync.mapping.updated",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "map_menu_erp_pos",
"version": 8,
"updated_by": "emp_ho_it_01"
}
}ส่งซ้ำเมื่อปลายทางไม่ตอบ
- 1ทันที
- 21 นาที
- 35 นาที
- 430 นาที
- 52 ชั่วโมง
- 66 ชั่วโมง
- 724 ชั่วโมง (ครั้งสุดท้าย)
ครบทุกครั้งแล้วยังล้มเหลว → ปิด endpoint อัตโนมัติและส่งอีเมลแจ้งผู้ดูแล · ดูประวัติการส่งและกดส่งซ้ำได้ในแดชบอร์ด
ตรวจลายเซ็น
# ลายเซ็นอยู่ในหัว Chuamthang-Signature: t=<unix>,v1=<hex>
# คำนวณ HMAC-SHA256(secret, "<t>.<raw body>") แล้วเทียบกับ v1
printf '%s' "$T.$BODY" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET"import crypto from 'node:crypto';
// ใช้ raw body (ยังไม่ parse JSON) เท่านั้น
export function verify(rawBody, sigHeader, secret) {
const parts = Object.fromEntries(sigHeader.split(',').map((p) => p.split('=')));
const age = Math.abs(Date.now() / 1000 - Number(parts.t));
if (age > 300) return false; // เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
const expected = crypto.createHmac('sha256', secret).update(parts.t + '.' + rawBody).digest('hex');
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}import hmac, hashlib, time
def verify(raw_body: bytes, sig_header: str, secret: str) -> bool:
parts = dict(p.split("=", 1) for p in sig_header.split(","))
if abs(time.time() - int(parts["t"])) > 300:
return False # เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
msg = parts["t"].encode() + b"." + raw_body
expected = hmac.new(secret.encode(), msg, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])Errors — รหัสข้อผิดพลาด
ทุก error ตอบกลับเป็น JSON รูปแบบเดียวกัน พร้อม request_id สำหรับแจ้งทีมสนับสนุน · รหัส HTTP บอกกลุ่มของปัญหา ส่วน error.code บอกสาเหตุที่แน่นอน (ใช้เขียนเงื่อนไขในโค้ดได้ เพราะไม่เปลี่ยนตามภาษา)
- 4xx คำขอไม่ถูกต้อง — แก้ที่ฝั่งผู้เรียก ส่งซ้ำแบบเดิมจะได้ผลเดิม
- 5xx ปัญหาฝั่งระบบ — ลองใหม่แบบเว้นระยะ (exponential backoff) พร้อม Idempotency-Key
{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"param": "items[0].quantity",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.chuamthang.example/errors#invalid_request"
}
}| HTTP | code | ความหมาย | วิธีแก้ |
|---|---|---|---|
| 400 | invalid_request | คำขอไม่ถูกต้อง ขาดฟิลด์ที่จำเป็น หรือชนิดข้อมูลผิด — ดู error.param ว่าฟิลด์ไหน | ตรวจ body ตาม schema ของ endpoint · เงินต้องเป็นจำนวนเต็มสตางค์ · เวลาเป็น ISO 8601 |
| 401 | unauthorized | ไม่ได้ยืนยันตัวตน ไม่มีหัว Authorization หรือ API key ไม่ถูกต้อง/ถูกเพิกถอน | ส่ง Authorization: Bearer ct_test_… (sandbox) หรือ ct_live_… (production) · ตรวจว่าใช้คีย์ให้ตรงสภาพแวดล้อม |
| 403 | insufficient_scope | สิทธิ์ของคีย์ไม่พอ API key นี้ไม่มี scope ที่ endpoint ต้องการ | ขอ scope เพิ่มในหน้า Developer Console (ผู้ดูแลระบบของ BAANKHAO อนุมัติ) |
| 404 | resource_not_found | ไม่พบข้อมูล รหัสใน path ไม่มีอยู่ หรืออยู่คนละสภาพแวดล้อม (sandbox/production) | ตรวจรหัสและสภาพแวดล้อม · ข้อมูล sandbox ถูกล้างทุกวันอาทิตย์ 03:00 |
| 409 | sync_job_running | มีงานซิงก์ข้อมูลชนิดนี้กำลังทำอยู่ entity เดียวกันในทิศทางเดียวกันกำลังซิงก์อยู่ (ป้องกันเขียนทับกัน) | รอให้งานเดิมจบ (webhook sync.job.completed) หรือยกเลิกงานเดิมก่อน |
| 409 | sync_job_finished | งานซิงก์จบแล้ว ยกเลิกงานที่สถานะ succeeded / failed / canceled ไม่ได้ | ไม่ต้องทำอะไร · ถ้าต้องย้อนผล สร้างงานใหม่แบบ full |
| 422 | mapping_invalid | การ map ฟิลด์ไม่ถูกต้อง ฟิลด์จำเป็นของปลายทางยังไม่ถูกจับคู่ หรือชนิดผลลัพธ์ของฟังก์ชันแปลงไม่ตรงปลายทาง | ทดสอบด้วย dry_run: true ก่อนบันทึก · ใช้เครื่องมือจำลองในหน้านี้ |
| 422 | transform_failed | ฟังก์ชันแปลงค่าล้มเหลว ค่าต้นทางแปลงไม่ได้ (เช่น วันที่ไม่ใช่ พ.ศ. หรือรหัสหมวดไม่อยู่ในตาราง) | แก้ข้อมูลต้นทาง หรือเพิ่มค่าในตาราง lookup |
| 409 | conflict_already_resolved | ข้อมูลชนกันนี้จัดการแล้ว conflict ถูก resolve ไปแล้ว (โดยกฎอัตโนมัติหรือผู้ดูแลคนอื่น) | ดึงสถานะล่าสุดด้วย GET /v1/sync/conflicts |
| 422 | entity_unsupported | ไม่รองรับข้อมูลชนิดนี้ entity ไม่อยู่ในรายการ menu menu_price branch stock member | เลือก entity ที่รองรับ |
| 412 | precondition_failed | ข้อมูลถูกแก้ไปก่อนแล้ว ค่า If-Match (ETag) ไม่ตรงกับเวอร์ชันปัจจุบันของข้อมูล | ดึงข้อมูลล่าสุดใหม่ (GET) แล้วส่งการแก้ไขพร้อม ETag ใหม่ |
| 422 | validation_failed | ข้อมูลไม่ผ่านกฎธุรกิจ รูปแบบถูกแต่ขัดกับกฎ เช่น วันที่ในอนาคต หรือจำนวนติดลบ — ดู error.details[] | แก้ตามรายการใน details แล้วส่งใหม่ |
| 409 | idempotency_conflict | Idempotency-Key ซ้ำแต่เนื้อหาต่าง เคยใช้ Idempotency-Key นี้กับคำขอที่ body ต่างกันภายใน 24 ชั่วโมง | สร้างคีย์ใหม่ (UUID v4) ต่อ 1 รายการ · ส่งคีย์เดิมซ้ำได้เฉพาะเมื่อ body เหมือนเดิม |
| 429 | rate_limited | เรียกเกินโควตา เกินโควตาของคีย์หรือของ endpoint ในช่วงเวลา | รอตามหัว Retry-After แล้วลองใหม่แบบเว้นระยะเพิ่มขึ้น + jitter |
| 502 | upstream_error | ระบบปลายทางตอบผิดพลาด ระบบที่ Hub เชื่อมอยู่ (ERP CRM ผู้ให้บริการรับชำระ แอปภายนอก) ตอบ 5xx หรือรูปแบบที่อ่านไม่ได้ | ลองใหม่ภายหลัง · ดู error.upstream ว่าระบบไหน · ตรวจสุขภาพที่ GET /v1/connectors/{id}/health |
| 504 | upstream_timeout | ระบบปลายทางตอบช้าเกิน ระบบปลายทางไม่ตอบภายในเวลาที่กำหนด (ค่าเริ่มต้น 8 วินาที) | ลองใหม่พร้อม Idempotency-Key เดิม — Hub กันรายการซ้ำให้ · ตรวจสถานะด้วย GET ก่อนสร้างใหม่ |
ไม่พบรหัสที่ค้นหา
Rate limit — โควตาการเรียก
| ขอบเขต | โควตา | Burst | หมายเหตุ |
|---|---|---|---|
| สั่งงานซิงก์ (ต่อคีย์) | 20 ครั้ง/นาที | — | งานชนิดเดียวกันวิ่งพร้อมกันได้ 1 งาน |
| อ่านงาน/ข้อมูลชนกัน (ต่อคีย์) | 120 ครั้ง/นาที | 30 | |
| change feed (ต่อคีย์) | 120 ครั้ง/นาที × 1,000 รายการ | — | |
| Hub → POS ระหว่างซิงก์ | 10 สาขาพร้อมกัน | — | ไม่ให้แท็บเล็ตสาขาช้าช่วงเปิดร้าน |
RateLimit-Limitโควตาของช่วงเวลาRateLimit-Remainingครั้งที่เหลือRateLimit-Resetวินาทีจนโควตาเริ่มใหม่- เกินโควตา → 429 พร้อม
Retry-After· แนะนำลองใหม่แบบเว้นระยะเพิ่มขึ้น + สุ่มเล็กน้อย (jitter)
HTTP/1.1 429 Too Many Requests
RateLimit-Limit: 100
RateLimit-Remaining: 0
RateLimit-Reset: 23
Retry-After: 23
{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา ลองใหม่ใน 23 วินาที",
"request_id": "req_2Kd9QwZ1"
}
}เวอร์ชันและ Changelog
เลือกเวอร์ชันด้วยหัว Chuamthang-Version (ไม่ส่ง = เวอร์ชันที่ผูกกับ API key) · การเปลี่ยนที่ไม่ทำให้โค้ดเดิมพัง (เพิ่มฟิลด์/endpoint) ออกในเวอร์ชันเดิมได้ · การเปลี่ยนที่ทำให้พังออกเป็นเวอร์ชันใหม่เสมอ และแจ้งล่วงหน้าอย่างน้อย 6 เดือนก่อนปิดเวอร์ชันเก่า
| เวอร์ชัน | สถานะ | รองรับถึง |
|---|---|---|
2026-08-01 ล่าสุด | ปัจจุบัน | — |
2025-11-15 | ยังรองรับ | 30 ก.ย. 2570 |
2024-06-01 | เลิกใช้แล้ว | 31 ธ.ค. 2569 |
- เพิ่ม
2026-08-01เพิ่ม GET /v1/sync/jobs/{id}/failures และ retry_of สำหรับงานซ่อมเฉพาะส่วน
- เปลี่ยน
2026-08-01POST /v1/sync/jobs ตอบ 409 sync_job_running แทนการต่อคิวเงียบ ๆ
- เพิ่ม
2025-11-15ฟังก์ชันแปลง be_date_to_iso (วันที่ พ.ศ. ของ ERP เดิม)
- แก้ไข
2025-11-15baht_to_satang_vat ปัด 87.85 × 1.07 เป็น 9399 — แก้เป็นปัดครึ่งขึ้น (9400)
- เพิ่ม
2025-11-15conflict_rule manual_review + webhook sync.conflict.detected
- ความปลอดภัย
2025-11-15change feed ของ member ตัดเบอร์/อีเมลออก (ส่งเฉพาะ id และฟิลด์ที่เปลี่ยนแบบไม่ใช่ PII)
- เปลี่ยน
2025-11-15cursor เปลี่ยนจากเลขหน้าเป็น change_seq — ไม่ตกหล่นเมื่อมีการแก้ระหว่างอ่าน
- เลิกใช้
2025-11-15เลิกใช้ POST /v1/sync/run (สั่งทุกข้อมูลพร้อมกัน) — สั่งรายข้อมูลแทน
- เพิ่ม
2024-06-01dry_run ใน PUT /v1/sync/mappings
ตัวจำลองการ map ฟิลด์ + แก้ข้อมูลชนกัน
จับคู่ฟิลด์ ERP → POS และเลือกฟังก์ชันแปลง → เห็นผลกับระเบียนจริงทันที · เลือกกฎข้อมูลชนกัน → เห็นค่าที่ได้และ JSON ที่ API จะคืน · คำนวณในเบราว์เซอร์ทั้งหมด ไม่ได้เรียก API จริง
1) จับคู่ฟิลด์ ERP → POS (เมนู)
ระเบียนต้นทางจาก ERP (แก้ได้)
| ฟิลด์ POS | จากฟิลด์ ERP | ฟังก์ชันแปลง | ผล |
|---|