v1.0 · REST · JSON · OpenAPI 3.1
Authentication
POST /auth/register
POST /auth/login
POST /auth/refresh
Products
GET /products
GET /products/:id
POST /products
PUT /products/:id
Orders
POST /orders
GET /orders/:id
PATCH /orders/:id/status
Search
GET /search
Users
GET /users/me
PUT /users/me
Sellers
GET /seller/dashboard
GET /seller/analytics
Payments
POST /payments/initiate
POST /payments/webhook
Promotions
POST /coupons/validate
GET /flash-sales/current
API Reference
BASE URL: https://api.thailandmarket.th/v1
🔐 Authentication
ใช้ JWT Bearer Token สำหรับ API requests ที่ต้องการ authentication
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
Public
Query Parameters
ParameterTypeRequiredDescription
pageintegeroptionalหน้าที่ (default: 1)
limitintegeroptionalจำนวนต่อหน้า (default: 20, max: 100)
category_iduuidoptionalกรองตาม category
seller_iduuidoptionalกรองตาม seller
sortstringoptionalprice_asc · price_desc · rating · newest · bestseller
min_pricenumberoptionalราคาต่ำสุด (฿)
max_pricenumberoptionalราคาสูงสุด (฿)
in_stockbooleanoptionalแสดงเฉพาะมีสต็อก
flash_salebooleanoptionalแสดงเฉพาะ 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 Required
Request 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 Required
Request 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/..." } }
👤 Users
GET/users/meข้อมูลผู้ใช้ปัจจุบัน
Authentication
🔐 Required
Response 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 Required
Query Parameters
ParameterTypeDescription
periodstringtoday · week · month · year
category_iduuidกรองตาม 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
StatusCodeDescription
400VALIDATION_ERRORข้อมูลที่ส่งมาไม่ถูกต้อง
401UNAUTHORIZEDไม่มี token หรือ token หมดอายุ
404NOT_FOUNDไม่พบข้อมูลที่ต้องการ
409CONFLICTข้อมูลซ้ำ (เช่น email ซ้ำ)
422OUT_OF_STOCKสินค้าหมดสต็อก
429RATE_LIMITเกินจำนวน request ที่อนุญาต (100/min)
500INTERNAL_ERRORเกิดข้อผิดพลาดในระบบ