Appearance
09.04 Authentication & Connection Verification
📌 At a Glance
| รายการ | รายละเอียด |
|---|---|
| Topic | Authentication & Connection Verification |
| Difficulty | ⭐ Beginner |
| Reading Time | 10 นาที |
| Target | Developer, System Integrator |
| Related APIs | GET /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 แสดงขั้นตอนการตรวจสอบการเชื่อมต่อและการยืนยันตัวตน ก่อนเรียกใช้งาน 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 APIs1. 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
| Field | Description |
|---|---|
| status | สถานะของ API |
| service | ชื่อบริการ |
| api_version | เวอร์ชัน API |
| server_time | เวลาปัจจุบันของ Server |
Recommended Usage
ใช้สำหรับ
- 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
| Field | Description |
|---|---|
| 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/jsonCommon Authentication Errors
| HTTP Status | Description |
|---|---|
| 401 Unauthorized | ไม่พบ API Key หรือ API Key ไม่ถูกต้อง |
| 403 Forbidden | API 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 APIsBest 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
