Authentication

Paano i-authenticate ang mga TCG Price Lookup API request gamit ang API key.


API Key Authentication

Gumagamit ang TCG Price Lookup API ng API key-based authentication. Kailangang isama ang API key sa lahat ng requests.

Header Authentication (Inirerekomenda)

Ipasa ang API key sa X-API-Key header:

curl https://api.tcgpricelookup.com/v1/search?q=charizard \
  -H "X-API-Key: your-api-key"

Query Parameter Authentication

Bilang alternatibo, maaari itong ipasa bilang query parameter:

curl "https://api.tcgpricelookup.com/v1/search?q=charizard&api_key=your-api-key"

Tandaan: Mas ligtas ang header authentication. Kapag ipinasa bilang query parameter, maaaring maitala ang iyong API key sa server logs.

Authentication gamit ang SDK

Awtomatikong hinahawakan ng mga SDK ang lahat ng 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'])

Seguridad ng API Key

  • Huwag i-commit ang API key sa version control
  • Gumamit ng environment variables (TCG_API_KEY)
  • Huwag ilantad ang API key sa client-side code o frontend
  • Kapag na-leak ang key, agad itong i-rotate mula sa dashboard

Error Response

Ang mga authentication error ay nagbabalik ng 401 Unauthorized:

{
  "error": {
    "code": "unauthorized",
    "message": "Invalid or missing API key"
  }
}