Skip to content

05.03 Units API


📌 At a Glance

รายการรายละเอียด
TopicUnits API
EndpointGET /units
MethodGET
AuthenticationAPI Key
Difficulty⭐ Beginner
Reading Time6 นาที
TargetDeveloper

🎯 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

Figure 5-3 แสดงขั้นตอนการดึงข้อมูลหน่วยนับจาก SISAHYGO API การตรวจสอบ API Key และการส่งข้อมูล Unit Master กลับในรูปแบบ JSON


Business Purpose

Units API มีวัตถุประสงค์เพื่อ

  • Synchronize หน่วยนับสินค้า
  • ใช้ Unit ID มาตรฐานเดียวกัน
  • ลดความผิดพลาดในการอ้างอิงหน่วยนับ
  • รองรับการขยาย Master Data ในอนาคต

Endpoint

http
GET /units

Base URL

text
https://app.sisahygo.online/api/v1/units

Authentication

Header

http
X-API-Key: {your_api_key}

Accept: application/json

Query Parameters

Units API ไม่มี Query Parameters


Sample Request

http
GET /units

Sample Response

json
{
    "data": [
        {
            "unit_id": 1,
            "unit_name": "ขวด"
        },
        {
            "unit_id": 2,
            "unit_name": "ลัง"
        },
        {
            "unit_id": 3,
            "unit_name": "กล่อง"
        }
    ]
}

Response Fields

FieldTypeDescription
unit_idIntegerรหัสหน่วยนับ
unit_nameStringชื่อหน่วยนับ

Business Rules

  • ส่งคืนข้อมูลหน่วยนับทั้งหมดในระบบ
  • เรียงลำดับตามชื่อหน่วยนับ
  • ไม่มีการกรองตามลูกค้า
  • ไม่มีการแบ่งหน้า (Pagination)

Validation Rules

RuleDescription
API Keyต้องถูกต้องและเปิดใช้งาน

Error Response

HTTP StatusDescription
401Invalid API Key
403Permission Denied
500Internal 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

SISAHYGO API Integration Guide