Appearance
04.04 Your First API Call
📌 At a Glance
| รายการ | รายละเอียด |
|---|---|
| Topic | Your First API Call |
| Difficulty | ⭐ Beginner |
| Reading Time | 8 นาที |
| Target | Developer |
🎯 Learning Objectives
หลังจากศึกษาหัวข้อนี้แล้ว ผู้อ่านจะสามารถ
- เรียกใช้งาน SISAHYGO API ครั้งแรก
- ตรวจสอบการเชื่อมต่อกับ Production Environment
- อ่านและเข้าใจ JSON Response
- เตรียมพร้อมสำหรับการใช้งาน API อื่น ๆ
Overview
เมื่อได้รับ API Key และตั้งค่า Development Environment เรียบร้อยแล้ว ขั้นตอนถัดไปคือการทดลองเรียก API
SISAHYGO แนะนำให้เริ่มจาก GET /products ซึ่งเป็น API สำหรับดึงข้อมูลสินค้า เนื่องจากเป็น API แบบ Read Only ไม่มีผลกระทบต่อข้อมูลในระบบ และใช้ตรวจสอบความพร้อมของการเชื่อมต่อได้เป็นอย่างดี
Figure 4-4 Your First API Call

Figure 4-4 แสดงลำดับการเรียก API ตั้งแต่ Client ส่ง HTTP Request ผ่าน HTTPS พร้อม API Key ไปยัง SISAHYGO Integration Platform และได้รับ JSON Response กลับมา
Step 1 : Prepare Request
Method
http
GETEndpoint
text
https://app.sisahygo.online/api/v1/productsHeaders
http
X-API-Key: sk_live_xxxxxxxxxxxxxxxxx
Accept: application/jsonStep 2 : Send Request
ตัวอย่างด้วย cURL
bash
curl -X GET \
"https://app.sisahygo.online/api/v1/products" \
-H "X-API-Key: sk_live_xxxxxxxxxxxxxxxxx" \
-H "Accept: application/json"Step 3 : Receive Response
ตัวอย่าง Response
json
{
"success": true,
"code": "200",
"message": "Success",
"data": [
{
"product_code": "P0001",
"product_name": "สินค้าตัวอย่าง 1"
},
{
"product_code": "P0002",
"product_name": "สินค้าตัวอย่าง 2"
}
],
"timestamp": "2026-07-02T10:15:30+07:00",
"version": "1.1"
}Verify the Result
เมื่อเรียก API สำเร็จ ควรตรวจสอบ
| รายการ | Expected Result |
|---|---|
| HTTP Status | 200 OK |
| success | true |
| code | 200 |
| data | มีรายการสินค้า |
| version | 1.1 |
Common Problems
| Problem | Solution |
|---|---|
| 401 Unauthorized | ตรวจสอบ API Key |
| 404 Not Found | ตรวจสอบ Base URL |
| 500 Internal Server Error | ติดต่อทีม SISAHYGO หรือทดลองใหม่ภายหลัง |
| Empty Data | ตรวจสอบสิทธิ์หรือข้อมูลในระบบ |
Key Points
| Item | Value |
|---|---|
| Method | GET |
| Endpoint | /products |
| Authentication | API Key |
| Response | JSON |
| Protocol | HTTPS |
Implementation Notes
- เริ่มทดสอบจาก GET Endpoint ก่อนเสมอ
- ตรวจสอบ HTTP Status Code และ
success - ใช้ข้อมูลจาก
dataเท่านั้น - บันทึก Log หากพบข้อผิดพลาด
Best Practices
- ใช้ Postman หรือ cURL ทดสอบก่อนเขียนโค้ด
- ทดสอบ API Key ก่อนทุกครั้ง
- ตรวจสอบ Header ให้ครบถ้วน
- ใช้ตัวอย่าง Response เป็นต้นแบบในการพัฒนา
Summary
การเรียก GET /products เป็นจุดเริ่มต้นที่ดีที่สุดสำหรับการทดสอบการเชื่อมต่อกับ SISAHYGO API เมื่อสามารถเรียกใช้งานได้สำเร็จ แสดงว่า Development Environment พร้อมสำหรับการพัฒนา API อื่น ๆ
Next Step
➡️ 04.05 Using Postman
