Skip to content

09.04 Authentication & Connection Verification


📌 At a Glance

รายการรายละเอียด
TopicAuthentication & Connection Verification
Difficulty⭐ Beginner
Reading Time10 นาที
TargetDeveloper, System Integrator
Related APIsGET /ping, GET /profile

🎯 Learning Objectives

หลังจากศึกษาหัวข้อนี้แล้ว ผู้อ่านจะสามารถ

  • ตรวจสอบว่า SISAHYGO API พร้อมให้บริการ
  • ตรวจสอบว่า API Key ใช้งานได้ถูกต้อง
  • ตรวจสอบข้อมูล API Client และ Customer ที่เชื่อมโยงกับ API Key
  • เข้าใจข้อผิดพลาดด้าน Authentication และวิธีจัดการ

Overview

ก่อนเริ่มใช้งาน Business APIs เช่น

  • Master Data APIs
  • Order Checking APIs
  • Shipment Tracking APIs
  • Order Rejection APIs

แนะนำให้ Client System ตรวจสอบการเชื่อมต่อและยืนยันตัวตนก่อนทุกครั้ง

SISAHYGO มี API สำหรับตรวจสอบสองรายการ ได้แก่

  • GET /ping
  • GET /profile

ทั้งสอง API ช่วยให้ตรวจสอบได้ว่าระบบพร้อมให้บริการและ API Key เชื่อมโยงกับข้อมูลลูกค้าได้ถูกต้อง


Figure 9-4 Authentication & Connection Verification

Figure 9-4

Figure 9-4 แสดงขั้นตอนการตรวจสอบการเชื่อมต่อและการยืนยันตัวตน ก่อนเรียกใช้งาน Business APIs


Authentication Workflow

text
Client System





HTTPS Request





GET /ping





Server Available ?



      ├──── No





Retry Later



      └──── Yes





       GET /profile





Verify API Key





Verify Customer





Business APIs

1. Ping API

ใช้ตรวจสอบว่า API Server พร้อมให้บริการ

Endpoint

http
GET /ping

ตัวอย่าง Response

json
{
    "data": {
        "status": "ok",
        "service": "SISAHYGO API",
        "api_version": "1.1",
        "server_time": "2026-07-01T14:30:00+07:00"
    }
}

Response Fields

FieldDescription
statusสถานะของ API
serviceชื่อบริการ
api_versionเวอร์ชัน API
server_timeเวลาปัจจุบันของ Server

ใช้สำหรับ

  • Health Check
  • Integration Test
  • Monitoring
  • ตรวจสอบก่อนเริ่ม Sync ข้อมูล

2. Profile API

ใช้ตรวจสอบ API Key และข้อมูล Customer

Endpoint

http
GET /profile

ตัวอย่าง Response

json
{
    "data": {
        "api_version": "1.1",
        "api_client_id": 1,
        "api_client_name": "ABC Logistics ERP",
        "customer_id": 652239,
        "customer_name": "ABC Company",
        "customer_phone": "020000000",
        "paymenttype": "H",
        "paymenttype_mapped_for_order": "H",
        "default_branch_id": 1,
        "default_order_type": "general",
        "status": "active"
    }
}

Response Fields

FieldDescription
api_client_idรหัส API Client
api_client_nameชื่อ API Client
customer_idรหัสลูกค้า
customer_nameชื่อลูกค้า
paymenttypeรูปแบบการชำระเงิน
paymenttype_mapped_for_orderประเภทที่ใช้สร้าง Order
default_branch_idสาขาเริ่มต้น
default_order_typeประเภท Order เริ่มต้น
statusสถานะ API Client

Required Headers

ทุก Request ต้องส่ง

http
X-API-Key: your_api_key
Accept: application/json

Common Authentication Errors

HTTP StatusDescription
401 Unauthorizedไม่พบ API Key หรือ API Key ไม่ถูกต้อง
403 ForbiddenAPI Client ถูกปิดใช้งาน หรือไม่มีสิทธิ์ใช้งาน

Authentication Verification Checklist

ก่อนเรียก Business APIs

  • ✅ API Server ตอบกลับจาก /ping
  • ✅ API Key ใช้งานได้
  • ✅ API Client เป็น Active
  • ✅ Customer ถูกต้อง
  • ✅ Payment Type ถูกต้อง
  • ✅ Default Branch ถูกต้อง

Recommended Startup Sequence

text
Application Start





GET /ping





GET /profile





Load Master Data





Business APIs

Best Practices

  • เรียก /ping ทุกครั้งก่อน Integration Test
  • เรียก /profile เมื่อเริ่มต้นระบบหรือเมื่อมีการเปลี่ยน API Key
  • เก็บข้อมูลจาก /profile ไว้ในหน่วยความจำ (Cache) เพื่อลดการเรียก API ซ้ำ
  • หาก status เป็น inactive ไม่ควรส่ง Transaction ใด ๆ
  • ใช้ HTTPS และเก็บ API Key อย่างปลอดภัย

Related Sections

  • 09.02 HTTP Status Codes
  • 09.03 Standard Error Response Format
  • 09.05 Validation Errors

Summary

Authentication & Connection Verification เป็นขั้นตอนแรกที่แนะนำก่อนใช้งาน SISAHYGO API โดย GET /ping ใช้ตรวจสอบความพร้อมของบริการ ส่วน GET /profile ใช้ยืนยันข้อมูล API Client และ Customer ที่เชื่อมโยงกับ API Key การตรวจสอบทั้งสองรายการก่อนเริ่มต้นการทำงานจะช่วยลดปัญหาการเชื่อมต่อ เพิ่มความถูกต้องของการกำหนดค่า และทำให้การเชื่อมต่อกับ Business APIs มีความเสถียรมากยิ่งขึ้น


Next Step

➡️ 09.05 Validation Errors

SISAHYGO API Integration Guide