Skip to content

สร้าง Access Token (x-api-key)

ส่วนนี้จะอธิบายวิธีการสร้าง x-api-key อย่างปลอดภัย ซึ่งจะใช้สำหรับยืนยันตัวตนในการเรียกใช้ API

🟢 x-api-key คืออะไร?

x-api-key เป็นโทเคนสำหรับความปลอดภัย ซึ่งสร้างโดยการแฮชค่า systemId และ systemSecret ด้วย HMAC-SHA256 จำเป็นต้องใช้เพื่อยืนยันตัวตนกับ ZIGNAL External API

🔐 ตัวอย่างการสร้าง x-api-key (ด้วย Node.js)

js
import crypto from "crypto";

const systemId = "example-system-id";
const systemSecret = "example-secret-key";

const xApiKey = crypto
  .createHmac("sha256", systemSecret)
  .update(systemId)
  .digest("hex");

console.log(xApiKey);

⚠️ ห้ามเปิดเผย systemSecret ในฝั่ง client

🧾 Header ที่ต้องใช้ในการยืนยันตัวตน

Headerคำอธิบาย
X-System-IdSystem ID you received from Home menu
X-Api-KeyHMAC-SHA256 hash from the script

หลังจากได้ access token แล้ว คุณสามารถใช้กับ API ต่างๆ เช่น Send Notify External