Skip to content

04.04 Your First API Call


📌 At a Glance

รายการรายละเอียด
TopicYour First API Call
Difficulty⭐ Beginner
Reading Time8 นาที
TargetDeveloper

🎯 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

Figure 4-4 แสดงลำดับการเรียก API ตั้งแต่ Client ส่ง HTTP Request ผ่าน HTTPS พร้อม API Key ไปยัง SISAHYGO Integration Platform และได้รับ JSON Response กลับมา


Step 1 : Prepare Request

Method

http
GET

Endpoint

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

Headers

http
X-API-Key: sk_live_xxxxxxxxxxxxxxxxx

Accept: application/json

Step 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 Status200 OK
successtrue
code200
dataมีรายการสินค้า
version1.1

Common Problems

ProblemSolution
401 Unauthorizedตรวจสอบ API Key
404 Not Foundตรวจสอบ Base URL
500 Internal Server Errorติดต่อทีม SISAHYGO หรือทดลองใหม่ภายหลัง
Empty Dataตรวจสอบสิทธิ์หรือข้อมูลในระบบ

Key Points

ItemValue
MethodGET
Endpoint/products
AuthenticationAPI Key
ResponseJSON
ProtocolHTTPS

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

SISAHYGO API Integration Guide