🔐 Authentication
ใช้ JWT Bearer Token สำหรับ API requests ที่ต้องการ authentication
Token มีอายุ 15 นาที ต่ออายุด้วย Refresh Token (7 วัน)
Token มีอายุ 15 นาที ต่ออายุด้วย Refresh Token (7 วัน)
🔑 การใช้ Bearer Token
// ใส่ header ทุก request ที่ต้องการ auth
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Content-Type: application/json
Accept-Language: th // หรือ en
POST
/auth/register
สมัครสมาชิกใหม่
▼
Authentication
ไม่ต้อง login
Request Body
JSON{
"email": "user@example.com", // required
"password": "SecurePass123!", // required · min 8 chars
"first_name": "สมชาย", // required
"last_name": "ใจดี", // required
"phone": "0812345678", // optional
"role": "buyer" // "buyer" | "seller"
}
Response 201
JSON{
"success": true,
"data": {
"user": {
"id": "uuid",
"email": "user@example.com",
"role": "buyer",
"loyalty_level": "silver"
},
"access_token": "eyJ...",
"refresh_token": "eyJ...",
"expires_in": 900
}
}
POST
/auth/login
เข้าสู่ระบบ
▼
Request Body
JSON{
"email": "user@example.com",
"password": "SecurePass123!"
}
Response 200
JSON{
"success": true,
"data": {
"access_token": "eyJ...",
"refresh_token": "eyJ...",
"user": { /* user object */ }
}
}
📦 Products
จัดการสินค้าบน platform — ทั้ง read (public) และ write (ต้องเป็น seller/admin)
GET
/products
ดึงรายการสินค้า (paginated)
▼
Authentication
PublicQuery Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| page | integer | optional | หน้าที่ (default: 1) |
| limit | integer | optional | จำนวนต่อหน้า (default: 20, max: 100) |
| category_id | uuid | optional | กรองตาม category |
| seller_id | uuid | optional | กรองตาม seller |
| sort | string | optional | price_asc · price_desc · rating · newest · bestseller |
| min_price | number | optional | ราคาต่ำสุด (฿) |
| max_price | number | optional | ราคาสูงสุด (฿) |
| in_stock | boolean | optional | แสดงเฉพาะมีสต็อก |
| flash_sale | boolean | optional | แสดงเฉพาะ Flash Sale |
Response 200
JSON{
"success": true,
"data": {
"products": [
{
"id": "uuid",
"name": "Samsung 55\" QLED 4K",
"base_price": 12900,
"compare_price": 22900,
"is_flash_sale": true,
"flash_sale_price": 10900,
"rating": 4.8,
"total_reviews": 2847,
"images": ["https://cdn.thailandmarket.th/..."],
"seller": { "id": "uuid", "shop_name": "Samsung Official" },
"category": { "id": "uuid", "name_th": "Tech & Gadgets" }
}
],
"pagination": {
"page": 1, "limit": 20,
"total": 15248, "total_pages": 763
}
}
}
POST
/products
สร้างสินค้าใหม่ (seller only)
▼
Authentication
🔐 Seller RequiredRequest Body
JSON{
"category_id": "uuid", // required
"name": "ชื่อสินค้า", // required
"description": "รายละเอียด", // optional
"base_price": 1990, // required
"compare_price": 2990, // optional (ราคาเดิม)
"sku": "SKU001", // optional
"weight_kg": 0.5, // required for shipping
"variants": [ // optional
{ "option1_name": "สี", "option1_value": "แดง", "price": 1990, "stock": 100 }
],
"status": "active" // "draft" | "active"
}
🛒 Orders
สร้างและจัดการออเดอร์ — ต้อง login สำหรับทุก endpoint
POST
/orders
สร้างออเดอร์ใหม่
▼
Authentication
🔐 Buyer RequiredRequest Body
JSON{
"items": [
{ "product_id": "uuid", "variant_id": "uuid", "quantity": 1 }
],
"shipping_address_id": "uuid",
"payment_method": "credit_card", // credit_card | promptpay | installment | counter
"coupon_code": "FLASH10", // optional
"points_to_use": 1000 // optional (แลก 1000 แต้ม = ฿100)
}
Response 201
JSON{
"success": true,
"data": {
"order_id": "uuid",
"order_number": "ZM-2604-000001",
"total_amount": 14290,
"payment_url": "https://pay.omise.co/...",
"qr_code_url": "https://api.thailandmarket.th/qr/..."
}
}
🔍 Search
Full-text search ด้วย Elasticsearch — รองรับ Thai tokenization
GET
/search
ค้นหาสินค้า
▼
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| q | string | required | คำค้นหา (Thai + English) |
| category | string | optional | category slug เพื่อ filter |
| brand | string | optional | ชื่อแบรนด์ |
| page | integer | optional | หน้าที่ (default: 1) |
Example
// ค้นหาทีวี Samsung
GET /search?q=ทีวี samsung&category=tech-gadgets&page=1
// Response includes AI-powered suggestions
{
"query": "ทีวี samsung",
"total": 284,
"suggestions": ["samsung qled", "samsung oled"],
"products": [/* ... */],
"facets": {
"brands": [{"name": "Samsung", "count": 180}],
"price_ranges": [{"label": "฿5,000–฿20,000", "count": 142}]
}
}
👤 Users
GET/users/meข้อมูลผู้ใช้ปัจจุบัน▼
Authentication
🔐 RequiredResponse 200
JSON{
"id": "uuid",
"email": "user@example.com",
"first_name": "สมชาย",
"loyalty_level": "gold",
"loyalty_points": 6249,
"total_orders": 48
}
💳 Payments
รองรับ Omise, 2C2P, PromptPay, ผ่อนชำระ
POST/payments/webhookรับ webhook จาก payment gateway▼
Security
ยืนยัน signature ด้วย HMAC-SHA256 ก่อนประมวลผล webhook ทุกครั้ง
Webhook Headers
X-Thailand Market-Signature: sha256=abc123...
X-Gateway: omise // omise | 2c2p | promptpay
🎟️ Promotions
POST/coupons/validateตรวจสอบและคำนวณส่วนลดคูปอง▼
Request Body
JSON{
"code": "FLASH10",
"order_amount": 14290,
"items": [{ "product_id": "uuid", "quantity": 1 }]
}
Response 200
JSON{
"valid": true,
"discount_amount": 1429,
"final_amount": 12861,
"coupon": { "code": "FLASH10", "type": "percentage", "value": 10 }
}
🏪 Sellers
GET/seller/dashboardข้อมูล dashboard ผู้ขาย▼
Authentication
🔐 Seller RequiredQuery Parameters
| Parameter | Type | Description |
|---|---|---|
| period | string | today · week · month · year |
| category_id | uuid | กรองตาม category |
Response 200
JSON{
"gmv": 284520,
"orders": 72,
"pending_orders": 12,
"rating": 4.8,
"revenue_net": 266648,
"commission_paid": 17872,
"top_products": [/* ... */],
"sales_chart": [/* daily GMV array */]
}
⚠️ Error Codes
| Status | Code | Description |
|---|---|---|
| 400 | VALIDATION_ERROR | ข้อมูลที่ส่งมาไม่ถูกต้อง |
| 401 | UNAUTHORIZED | ไม่มี token หรือ token หมดอายุ |
| 404 | NOT_FOUND | ไม่พบข้อมูลที่ต้องการ |
| 409 | CONFLICT | ข้อมูลซ้ำ (เช่น email ซ้ำ) |
| 422 | OUT_OF_STOCK | สินค้าหมดสต็อก |
| 429 | RATE_LIMIT | เกินจำนวน request ที่อนุญาต (100/min) |
| 500 | INTERNAL_ERROR | เกิดข้อผิดพลาดในระบบ |