Appearance
05.03 Units API
📌 At a Glance
| รายการ | รายละเอียด |
|---|---|
| Topic | Units API |
| Endpoint | GET /units |
| Method | GET |
| Authentication | API Key |
| Difficulty | ⭐ Beginner |
| Reading Time | 6 นาที |
| Target | Developer |
🎯 Learning Objectives
หลังจากศึกษาหัวข้อนี้แล้ว ผู้อ่านจะสามารถ
- ดึงข้อมูลหน่วยนับ (Units) จาก SISAHYGO API
- Synchronize Unit Master เข้าสู่ Client System
- ใช้ Unit ID ให้ตรงกับ Products API และ Order Checking API
Overview
Units API ใช้สำหรับดึงข้อมูลหน่วยนับ (Unit Master) จาก SISAHYGO เช่น
- ขวด
- กล่อง
- ชิ้น
- ลัง
- ถุง
Unit Master เป็นข้อมูลอ้างอิงที่ใช้ร่วมกับ Products API และ Order Checking API
ถึงแม้ Products API จะส่ง unit_id และ unit_name มาด้วย แต่การ Synchronize Units แยกต่างหากช่วยให้ Client System มี Master Data ที่สมบูรณ์ และรองรับการใช้งานในอนาคต
Figure 5-3 Units API Workflow

Figure 5-3 แสดงขั้นตอนการดึงข้อมูลหน่วยนับจาก SISAHYGO API การตรวจสอบ API Key และการส่งข้อมูล Unit Master กลับในรูปแบบ JSON
Business Purpose
Units API มีวัตถุประสงค์เพื่อ
- Synchronize หน่วยนับสินค้า
- ใช้ Unit ID มาตรฐานเดียวกัน
- ลดความผิดพลาดในการอ้างอิงหน่วยนับ
- รองรับการขยาย Master Data ในอนาคต
Endpoint
http
GET /unitsBase URL
text
https://app.sisahygo.online/api/v1/unitsAuthentication
Header
http
X-API-Key: {your_api_key}
Accept: application/jsonQuery Parameters
Units API ไม่มี Query Parameters
Sample Request
http
GET /unitsSample Response
json
{
"data": [
{
"unit_id": 1,
"unit_name": "ขวด"
},
{
"unit_id": 2,
"unit_name": "ลัง"
},
{
"unit_id": 3,
"unit_name": "กล่อง"
}
]
}Response Fields
| Field | Type | Description |
|---|---|---|
| unit_id | Integer | รหัสหน่วยนับ |
| unit_name | String | ชื่อหน่วยนับ |
Business Rules
- ส่งคืนข้อมูลหน่วยนับทั้งหมดในระบบ
- เรียงลำดับตามชื่อหน่วยนับ
- ไม่มีการกรองตามลูกค้า
- ไม่มีการแบ่งหน้า (Pagination)
Validation Rules
| Rule | Description |
|---|---|
| API Key | ต้องถูกต้องและเปิดใช้งาน |
Error Response
| HTTP Status | Description |
|---|---|
| 401 | Invalid API Key |
| 403 | Permission Denied |
| 500 | Internal Server Error |
Implementation Notes
- Synchronize Unit Master ก่อนใช้งาน Order Checking API
- ใช้
unit_idจาก SISAHYGO เป็นข้อมูลอ้างอิงหลัก - ไม่ควรสร้าง Unit ใหม่ใน Client System
- สามารถเก็บข้อมูลไว้ใน Local Database ได้
Best Practices
- Synchronize Unit Master เมื่อเริ่มต้นระบบ
- ตรวจสอบการเปลี่ยนแปลงเป็นระยะ
- ใช้ Unit ID เป็น Primary Reference
- ใช้ Unit Name สำหรับการแสดงผลเท่านั้น
Related APIs
- GET /products
- GET /receivers
- POST /order-checkings
Summary
Units API เป็น Master Data สำหรับหน่วยนับสินค้า ซึ่งใช้ร่วมกับ Products API และ Order Checking API เพื่อให้ Client System ใช้รหัสหน่วยนับเดียวกับ SISAHYGO ลดความคลาดเคลื่อนของข้อมูลและเพิ่มความถูกต้องในการสร้างรายการสินค้า
Next Step
➡️ 05.04 Receivers API
