Authentication
วิธี authenticate request ไปยัง TCG Price Lookup API ด้วย API key
API Key Authentication
TCG Price Lookup API ใช้การ authentication ด้วย API key ทุก request ต้องมี API key
Header Authentication (แนะนำ)
ส่ง API key ใน header X-API-Key:
curl https://api.tcgpricelookup.com/v1/search?q=charizard \
-H "X-API-Key: your-api-key"
Query Parameter Authentication
หรือส่งเป็น query parameter ได้:
curl "https://api.tcgpricelookup.com/v1/search?q=charizard&api_key=your-api-key"
หมายเหตุ: Header authentication ปลอดภัยกว่า การส่งเป็น query parameter อาจทำให้ API key ถูกบันทึกใน server log
Authentication ด้วย SDK
SDK จัดการ authentication ทั้งหมดโดยอัตโนมัติ:
// JavaScript
import { TCGLookup } from 'tcglookup';
const tcg = new TCGLookup({ apiKey: process.env.TCG_API_KEY });
# Python
from tcglookup import TCGLookup
tcg = TCGLookup(api_key=os.environ['TCG_API_KEY'])
ความปลอดภัยของ API Key
- อย่า commit API key เข้า version control
- ใช้ environment variable (
TCG_API_KEY) - อย่าเปิดเผย API key ใน client-side code หรือ frontend
- หาก key รั่วไหล ให้ rotate ทันทีจาก dashboard
Error Response
Authentication error จะ return 401 Unauthorized:
{
"error": {
"code": "unauthorized",
"message": "Invalid or missing API key"
}
}