สารบัญหน้านี้ (27)
- ภาพรวม
- การยืนยันตัวตนและ scope
- Workflow (2)
- ค้นหาของเล่นตามวัยลูก → หน้าสินค้า → เช็กสต็อก
- นำเข้าสินค้าคอลเลกชันใหม่ 120 รายการ + รูป + แจ้งตัวแทน
- Objects (3)
- The Product object
- The Variant object
- The Inventory object
- Endpoints (12)
- GETค้นหา/รายการสินค้า
- GETดูสินค้า
- POSTสร้างสินค้า
- PATCHแก้ไขสินค้า
- DELETEเลิกจำหน่าย (archive)
- GETตัวเลือกของสินค้า
- POSTนำเข้าสินค้าแบบ batch
- GETหมวดสินค้า
- GETสต็อกตามคลัง
- POSTปรับสต็อก
- POSTเพิ่มรูปสินค้า
- GETคำแนะนำขณะพิมพ์ค้นหา
- Webhooks (7)
- Errors (16)
- Rate limit
- เวอร์ชันและ Changelog
- เครื่องมือ: ตัวสร้าง query ค้นหาสินค้า
- LEKLEK Toys
- Docs
- E-Commerce API
- Product
LEKLEK Commerce API · โมดูล Product
Product API
แคตตาล็อกของเล่นไม้และของใช้เด็กของ LEKLEK (12 สินค้า 16 SKU ในตัวอย่าง) — สินค้าและตัวเลือกสี/ขนาด หมวด ช่วงอายุแนะนำ มาตรฐานความปลอดภัยของเล่น รูป สต็อกตามคลัง ราคาปลีกและราคาตัวแทน ค้นหาแบบกรองหลายมิติ และนำเข้าแบบ batch
- 12 endpoints
- 2 workflow
- 3 object
- 7 webhook event
- 16 รหัส error
- เวอร์ชัน
2026-08-01

ภาพรวมโมดูล Product
ใช้เมื่อไร
- หน้ารวมสินค้า ช่องค้นหา และ "แนะนำตามวัยลูก"
- หน้าสินค้า: เลือกสี/ขนาด เห็นสต็อกและคำเตือนความปลอดภัย
- ทีมสินค้านำเข้าคอลเลกชันใหม่จากไฟล์ซัพพลายเออร์
- ระบบตัวแทนจำหน่ายดึงแคตตาล็อกพร้อมราคาตัวแทน
Base path
/v2/products/v2/products/{product_id}/variants/v2/categories/v2/inventory
Base URL: https://api.leklek.example (Production) · https://sandbox.api.leklek.example (Sandbox — ข้อมูลทดสอบแยกชุด)
การยืนยันตัวตน
ทุกคำขอส่ง Authorization: Bearer <key> ผ่าน TLS 1.2 ขึ้นไป · key ทดสอบขึ้นต้น lk_test_ key จริงขึ้นต้น lk_live_ · แอป/เว็บใช้ publishable key คู่กับ access token ของลูกค้า (OAuth 2.0) ส่วนระบบหลังบ้านและตัวแทนจำหน่าย 40 รายใช้ secret key ของตัวเอง · ระบุเวอร์ชันด้วยหัว LekLek-Version
GET https://sandbox.api.leklek.example/v2/products/prd_TRN003
Authorization: Bearer lk_test_51HcQ2xT8bWm4
LekLek-Version: 2026-08-01
Accept: application/json
Accept-Language: thScope ของโมดูลนี้
| scope | อนุญาตให้ | ใช้โดย | endpoint ที่ต้องใช้ |
|---|---|---|---|
products:read | ค้นหาและดูสินค้า หมวด ตัวเลือก | แอป/เว็บ (publishable key) · ตัวแทน | GETค้นหา/รายการสินค้าGETดูสินค้าGETตัวเลือกของสินค้าGETหมวดสินค้าGETคำแนะนำขณะพิมพ์ค้นหา |
products:read_dealer | เห็น dealer_price จริง (key อื่นได้ null) | ตัวแทนจำหน่าย 40 ราย | ใช้ในโมดูลอื่น |
products:write | สร้าง แก้ เลิกจำหน่าย นำเข้า batch เพิ่มรูป | หลังบ้าน · ทีมสินค้า | POSTสร้างสินค้าPATCHแก้ไขสินค้าDELETEเลิกจำหน่าย (archive)POSTนำเข้าสินค้าแบบ batchPOSTเพิ่มรูปสินค้า |
inventory:read | สต็อกแยกคลังและของที่กำลังเข้า | แอป/เว็บ (เฉพาะ available) · หลังบ้าน | GETสต็อกตามคลัง |
inventory:write | ปรับสต็อก (รับเข้า ตัดเสีย ตรวจนับ) | ระบบคลังสินค้า | POSTปรับสต็อก |
Object หลัก
Productสินค้า 1 รายการ — ตัวอย่างคือรถไฟไม้ที่อยู่ในตะกร้า cart_7Hq2 และคำสั่งซื้อ ord_2610_004724 ฟิลด์ระดับบน · 21 ฟิลด์ย่อยVariantตัวเลือกของสินค้า (SKU) — หน่วยที่ใช้ในตะกร้า/คำสั่งซื้อจริง · ตัวอย่างกระติกน้ำสีมิ้นต์ (มีในตะกร้า 2 ใบ)10 ฟิลด์ระดับบน · 4 ฟิลด์ย่อยInventoryสต็อกของ SKU แยกคลัง — ตัวอย่างตุ๊กตากระต่าย 45 ซม. ที่หมดและมีของเข้า8 ฟิลด์ระดับบน · 6 ฟิลด์ย่อย
ความสัมพันธ์กับโมดูลอื่น
- Productหน้านี้
- Cartหยิบ SKU ใส่ตะกร้า — ระบบจองสต็อก 15 นาทีจาก available
- Promotionโปรเลือกสินค้าด้วย category หรือ sku_prefix (เช่น กระติก LK-BTL-*)
- Orderคำสั่งซื้อเก็บสำเนาชื่อ/ราคา ณ เวลาสั่ง — แก้สินค้าภายหลังไม่กระทบ
- Userรายการโปรด + แจ้งเตือนของเข้า (wishlist.back_in_stock)
- Paymentราคารวม VAT ที่นี่คือฐานของยอดชำระ
ข้อควรรู้
-
ราคาเป็นสตางค์รวม VAT
price 89000 = ฿890 · dealer_price เห็นเฉพาะ key ตัวแทน · ตัวกรอง price_min/price_max ก็เป็นสตางค์
-
ช่วงอายุเป็นเดือน
age_min_months/age_max_months (null = ไม่มีขั้นบน) · ค้นด้วย age_months=24 ได้สินค้าที่ครอบคลุมเด็ก 2 ขวบ
-
คำเตือนความปลอดภัย
safety.small_parts=true ต้องแสดงคำเตือน "ไม่เหมาะกับเด็กต่ำกว่า 3 ปี" ในหน้าสินค้าและตะกร้า (เลขมาตรฐานในตัวอย่างเป็นเลขสมมติ)
-
available ไม่ใช่ on_hand
available = คงเหลือ − จองในตะกร้า · แสดง "เหลือ n ชิ้น" จาก available เสมอ
-
ไม่ลบจริง
DELETE = archived · ลิงก์เดิมและคำสั่งซื้อเก่ายังอ้างถึงได้ · แนะนำ replacement_id
-
Cursor + แคช
รายการใช้ limit + starting_after · GET สินค้าแคช 60 วินาที (สต็อกจริงใช้ /variants หรือ /inventory)
Workflow — ขั้นตอนการเรียกใช้จริง (2 เรื่อง)
แต่ละเรื่องดูได้ 2 แบบ: ภาพรวม อธิบายภาษาคนทั่วไปทีละขั้น และ Sequence กดเล่นทีละขั้น (หรือคลิกลูกศร) เพื่อดูคำขอ/ผลลัพธ์ HTTP จริงของขั้นนั้น · ลูกศรประ = ส่งแบบไม่รอผล (webhook/คิว)
ค้นหาของเล่นตามวัยลูก → หน้าสินค้า → เช็กสต็อก
คุณพิมพ์ชนกหาของเล่นไม้สำหรับน้องขนมปัง (2 ขวบ) งบไม่เกิน ฿600 แอปส่ง sort ผิดค่าหนึ่งครั้ง แล้วแก้เอง
- คุณพิมพ์ชนกลูกค้า cus_P3k9
- แอป LEKLEKiOS / Android
- Commerce APIapi.leklek.example
- Search indexดัชนีค้นหา
- Inventoryสต็อก 2 คลัง
- ที่เก็บรูป + CDNfiles.leklek.example
- 1
คุณพิมพ์ชนก → แอป LEKLEK
ลูกค้าเลือกตัวกรองวัยลูกและงบ แล้วพิมพ์คำว่า "ไม้"
- 2
แอป LEKLEK → Commerce API
แอปเวอร์ชันเก่าส่งค่า sort ที่ไม่มีในระบบ
GET /v2/products?q=ไม้&age_months=24&price_max=60000&sort=cheapest - 3
Commerce API → แอป LEKLEK
ตอบ 400 พร้อมบอกค่าที่รับได้
- 4
แอป LEKLEK → Commerce API
ส่งใหม่ด้วย sort=best_selling
GET /v2/products?q=ไม้&category=wooden-toys&age_months=24&price_max=60000&sort=best_selling - 5
Commerce API → Search index
ค้นคำในชื่อ ป้าย วัสดุ กรองหมวด (รวมหมวดย่อย) อายุ ราคา แล้วเรียงตามยอดขาย 30 วัน
- 6
Commerce API → แอป LEKLEK
ได้ 4 สินค้า พร้อม facets จำนวนต่อหมวด
- 7
แอป LEKLEK → ที่เก็บรูป + CDN
โหลดรูปขนาดการ์ดจาก CDN (webp ~4 KB ต่อรูป)
- 8
คุณพิมพ์ชนก → แอป LEKLEK
เปิดหน้าสินค้า เลือกแบบ 24 ชิ้น
- 9
แอป LEKLEK → Commerce API
ดึงรายละเอียดเต็ม มาตรฐานความปลอดภัย และ variant
GET /v2/products/prd_BLK012 - 10
Commerce API → Inventory
คำนวณขายได้ = คงเหลือ − ที่ตะกร้าอื่นจองอยู่
ได้ 4 สินค้าที่ตรงวัยและงบใน 1 คำขอ (≈ 90 ms) · การ์ดสินค้าพร้อมรูปจาก CDN · ข้อผิดพลาด sort ไม่ทำให้หน้าว่าง
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 คุณพิมพ์ชนก แอป LEKLEK
เลือก "วัย 1–2 ปี · ไม่เกิน ฿600"
ลูกค้าเลือกตัวกรองวัยลูกและงบ แล้วพิมพ์คำว่า "ไม้"
2 แอป LEKLEK Commerce API
GET /v2/products?sort=cheapest
แอปเวอร์ชันเก่าส่งค่า sort ที่ไม่มีในระบบ
GET /v2/products?q=ไม้&age_months=24&price_max=60000&sort=cheapest HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm43 Commerce API แอป LEKLEK
400 invalid_request
ตอบ 400 พร้อมบอกค่าที่รับได้
จัดการผิดพลาด: แอปตัด sort ที่ไม่รู้จักออกแล้วใช้ค่าเริ่มต้น พร้อมส่ง log ให้ทีมแอป — ผู้ใช้ไม่เห็นหน้าว่าง
HTTP/1.1 400 Bad Request
{
"error": {
"code": "invalid_request",
"param": "sort",
"message": "sort ต้องเป็นหนึ่งใน relevance, best_selling, price_asc, price_desc, newest, rating"
}
}4 แอป LEKLEK Commerce API
GET /v2/products (แก้แล้ว)
ส่งใหม่ด้วย sort=best_selling
GET /v2/products?q=ไม้&category=wooden-toys&age_months=24&price_max=60000&sort=best_selling HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm45 Commerce API Search index
query ดัชนี
ค้นคำในชื่อ ป้าย วัสดุ กรองหมวด (รวมหมวดย่อย) อายุ ราคา แล้วเรียงตามยอดขาย 30 วัน
6 Commerce API แอป LEKLEK
200 OK
ได้ 4 สินค้า พร้อม facets จำนวนต่อหมวด
HTTP/1.1 200 OK
{
"object": "list",
"has_more": false,
"data": [
{
"id": "prd_BLK012",
"name": "บล็อกไม้ต่อตึกสีพาสเทล",
"price_range": {
"min": 59000,
"max": 99000
}
},
{
"id": "prd_PZL009",
"name": "พัซเซิลไม้รูปทรง 9 ชิ้น",
"price_range": {
"min": 45000,
"max": 45000
}
},
{
"id": "prd_STK005",
"name": "ห่วงเรียงซ้อนไม้ 5 ชั้น",
"price_range": {
"min": 32000,
"max": 32000
}
},
{
"id": "prd_XYL008",
"name": "ระนาดไม้ 8 เสียง",
"price_range": {
"min": 52000,
"max": 52000
}
}
],
"facets": [
{
"category": "wooden-toys",
"name": "ของเล่นไม้",
"count": 2
},
{
"category": "puzzle",
"name": "พัซเซิลและฝึกสมอง",
"count": 1
},
{
"category": "music",
"name": "เครื่องดนตรีของเล่น",
"count": 1
}
]
}7 แอป LEKLEK ที่เก็บรูป + CDN
GET รูป ?w=320
โหลดรูปขนาดการ์ดจาก CDN (webp ~4 KB ต่อรูป)
8 คุณพิมพ์ชนก แอป LEKLEK
แตะบล็อกไม้พาสเทล
เปิดหน้าสินค้า เลือกแบบ 24 ชิ้น
9 แอป LEKLEK Commerce API
GET /v2/products/prd_BLK012
ดึงรายละเอียดเต็ม มาตรฐานความปลอดภัย และ variant
GET /v2/products/prd_BLK012 HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm410 Commerce API Inventory
available ต่อ SKU
คำนวณขายได้ = คงเหลือ − ที่ตะกร้าอื่นจองอยู่
HTTP/1.1 200 OK
{
"sku": "LK-BLK-024",
"available": 23,
"status": "in_stock"
}ได้ 4 สินค้าที่ตรงวัยและงบใน 1 คำขอ (≈ 90 ms) · การ์ดสินค้าพร้อมรูปจาก CDN · ข้อผิดพลาด sort ไม่ทำให้หน้าว่าง
นำเข้าสินค้าคอลเลกชันใหม่ 120 รายการ + รูป + แจ้งตัวแทน
ทีมสินค้าแปลงไฟล์ CSV จากซัพพลายเออร์เป็น JSON แล้วส่ง batch — 2 รายการผิด ระบบรายงานรายตัว แก้แล้วส่งเฉพาะที่ผิด จากนั้นรูปถูกประมวลผลเบื้องหลังและตัวแทน 40 รายได้ webhook
- แอดมินร้านหลังบ้าน LEKLEK
- Commerce APIapi.leklek.example
- ฐานข้อมูลPostgreSQL
- ที่เก็บรูป + CDNfiles.leklek.example
- Event busคิว + webhook
- ระบบตัวแทนdlr_014 (ขอนแก่น)
- 1
แอดมินร้าน → Commerce API
ส่ง 120 รายการแบบ upsert (สร้างใหม่ + อัปเดตราคาของเดิม)
POST /v2/products/batch - 2
Commerce API → ฐานข้อมูล
ตรวจ schema SKU ซ้ำ ช่วงอายุ มาตรฐานความปลอดภัย แล้วบันทึกเป็น draft
- 3
Commerce API → แอดมินร้าน
สำเร็จ 118 · ผิด 2 (SKU ซ้ำ / ช่วงอายุกลับด้าน)
- 4
แอดมินร้าน → Commerce API
แก้ SKU เป็น LK-BLK-012-V2 และอายุ 36–48 เดือน แล้วส่งเฉพาะ 2 รายการ
POST /v2/products/batch - 5
แอดมินร้าน → Commerce API
เพิ่มรูปหลักให้สินค้าใหม่จาก URL ที่อัปโหลดไว้
POST /v2/products/prd_ABA010/images - 6
Commerce API → ที่เก็บรูป + CDN
สร้าง 3 ขนาด (320/640/1600) แล้วส่งขึ้น CDN
ไม่รอผล (async) - 7
แอดมินร้าน → Commerce API
ตรวจหน้าตาครบแล้วเปิดขาย
PATCH /v2/products/prd_ABA010 - 8
Commerce API → Event bus
ส่ง event ทีละสินค้า (รวมเป็นชุดละ 50)
ไม่รอผล (async) - 9
Event bus → ระบบตัวแทน
ระบบตัวแทนรับ webhook แล้วดึงราคาตัวแทนด้วย key ของตัวเอง
ไม่รอผล (async) - 10
ระบบตัวแทน → Commerce API
ตัวแทนเห็น dealer_price (key มี products:read_dealer)
GET /v2/products/prd_ABA010
120 สินค้าเข้าระบบใน 3 คำขอ (≈ 4 วินาที) · รายการผิดไม่ทำให้ทั้งไฟล์ล้ม · ตัวแทน 40 รายอัปเดตแคตตาล็อกเองจาก webhook ภายใน 1 นาที
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 แอดมินร้าน Commerce API
POST /v2/products/batch
ส่ง 120 รายการแบบ upsert (สร้างใหม่ + อัปเดตราคาของเดิม)
ตัวอย่างแสดง 2 จาก 120 รายการในคำขอจริง
POST /v2/products/batch HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
Idempotency-Key: 9d0e…
{
"mode": "upsert",
"items": [
{
"slug": "wooden-abacus-10",
"name": "ลูกคิดไม้ 10 แถว",
"category": "learning",
"variants": [
{
"sku": "LK-ABA-010",
"price": 42000
}
]
},
{
"slug": "wooden-train-3",
"variants": [
{
"sku": "LK-TRN-003",
"price": 89000
}
]
}
]
}2 Commerce API ฐานข้อมูล
บันทึกทีละรายการ
ตรวจ schema SKU ซ้ำ ช่วงอายุ มาตรฐานความปลอดภัย แล้วบันทึกเป็น draft
3 Commerce API แอดมินร้าน
207 Multi-Status
สำเร็จ 118 · ผิด 2 (SKU ซ้ำ / ช่วงอายุกลับด้าน)
จัดการผิดพลาด: อ่าน results[].index เพื่อไฮไลต์แถวในไฟล์ต้นฉบับ — ไม่ต้องส่งทั้ง 120 ใหม่
HTTP/1.1 207
{
"total": 120,
"succeeded": 118,
"failed": 2,
"results": [
{
"index": 37,
"status": 409,
"error": {
"code": "sku_already_exists",
"message": "SKU LK-BLK-012 เป็นของ prd_BLK012",
"param": "variants[0].sku"
}
},
{
"index": 81,
"status": 422,
"error": {
"code": "invalid_age_range",
"message": "age_min_months (48) มากกว่า age_max_months (36)",
"param": "age_min_months"
}
}
]
}4 แอดมินร้าน Commerce API
POST …/batch (2 รายการ)
แก้ SKU เป็น LK-BLK-012-V2 และอายุ 36–48 เดือน แล้วส่งเฉพาะ 2 รายการ
POST /v2/products/batch HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
{
"mode": "upsert",
"items": [
{
"slug": "pastel-blocks-v2",
"variants": [
{
"sku": "LK-BLK-012-V2"
}
]
},
{
"slug": "memory-cards",
"age_min_months": 36,
"age_max_months": 48
}
]
}HTTP/1.1 207
{
"total": 2,
"succeeded": 2,
"failed": 0
}5 แอดมินร้าน Commerce API
POST …/images
เพิ่มรูปหลักให้สินค้าใหม่จาก URL ที่อัปโหลดไว้
POST /v2/products/prd_ABA010/images HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
{
"source_url": "https://files.leklek.example/uploads/abacus.jpg",
"alt": "ลูกคิดไม้ 10 แถว",
"position": 1
}HTTP/1.1 201 Created
{
"id": "img_ABA0101",
"status": "processing"
}6 Commerce API ที่เก็บรูป + CDNasync
ย่อรูป + webp
สร้าง 3 ขนาด (320/640/1600) แล้วส่งขึ้น CDN
7 แอดมินร้าน Commerce API
PATCH status=active
ตรวจหน้าตาครบแล้วเปิดขาย
PATCH /v2/products/prd_ABA010 HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
{
"status": "active"
}HTTP/1.1 200 OK
{
"id": "prd_ABA010",
"status": "active"
}8 Commerce API Event busasync
product.created × 120
ส่ง event ทีละสินค้า (รวมเป็นชุดละ 50)
9 Event bus ระบบตัวแทนasync
webhook product.created
ระบบตัวแทนรับ webhook แล้วดึงราคาตัวแทนด้วย key ของตัวเอง
10 ระบบตัวแทน Commerce API
GET /v2/products/{id}
ตัวแทนเห็น dealer_price (key มี products:read_dealer)
GET /v2/products/prd_ABA010 HTTP/1.1
Authorization: Bearer lk_live_dlr014_…
LekLek-Account: dlr_014HTTP/1.1 200 OK
{
"id": "prd_ABA010",
"variants": [
{
"sku": "LK-ABA-010",
"price": 42000,
"dealer_price": 29400
}
]
}120 สินค้าเข้าระบบใน 3 คำขอ (≈ 4 วินาที) · รายการผิดไม่ทำให้ทั้งไฟล์ล้ม · ตัวแทน 40 รายอัปเดตแคตตาล็อกเองจาก webhook ภายใน 1 นาที
Objects
โครงข้อมูลที่ endpoint ในหน้านี้รับ-ส่ง · ฟิลด์ อ่านอย่างเดียว ระบบสร้างให้ (ส่งมาจะถูกละเว้น) · เงินเป็นสตางค์ · เวลาเป็น ISO 8601 +07:00
The Product object
สินค้า 1 รายการ — ตัวอย่างคือรถไฟไม้ที่อยู่ในตะกร้า cart_7Hq2 และคำสั่งซื้อ ord_2610_0047
idstringไม่บังคับอ่านอย่างเดียวรหัสสินค้า ขึ้นต้น prd_
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
slugstringจำเป็นใช้ใน URL หน้าสินค้า (ไม่ซ้ำ · a-z 0-9 -)
namestringจำเป็นชื่อสินค้าภาษาไทย
name_enstringไม่บังคับชื่อภาษาอังกฤษ (ใช้ในเว็บภาษาอังกฤษและฉลาก)
descriptionstringไม่บังคับรายละเอียดสินค้า (Markdown แบบจำกัด)
categorystringจำเป็นslug ของหมวด (ดู GET /v2/categories)
age_min_monthsintegerจำเป็นอายุแนะนำขั้นต่ำ (เดือน)
age_max_monthsintegerไม่บังคับอายุแนะนำสูงสุด (เดือน) — null = ไม่มีขั้นบน
age_labelstringไม่บังคับอ่านอย่างเดียวข้อความช่วงอายุพร้อมแสดง
materialstringไม่บังคับวัสดุ
safetyobjectไม่บังคับมาตรฐานความปลอดภัยของเล่นและคำเตือน (บังคับสำหรับหมวดของเล่น)
ฟิลด์ย่อยของ
safety(5)standardstringไม่บังคับมาตรฐานความปลอดภัยของเล่นที่ผ่าน (ตัวอย่างนี้ใช้เลขมาตรฐานสมมติ)
cert_nostringไม่บังคับเลขใบรับรองผลทดสอบของล็อตปัจจุบัน
tested_atstring · dateไม่บังคับวันที่ทดสอบ
small_partsbooleanไม่บังคับมีชิ้นส่วนเล็ก (แอปต้องแสดงคำเตือนสำหรับเด็กต่ำกว่า 3 ปี)
warningstringไม่บังคับคำเตือนที่ต้องแสดงในหน้าสินค้า
imagesarray<object>ไม่บังคับอ่านอย่างเดียวรูปสินค้า (เพิ่มผ่าน POST …/images) เรียงตาม position
ฟิลด์ย่อยของ
images(6)idstringไม่บังคับรหัสรูป
urlstring · uriไม่บังคับURL บน CDN (ปรับขนาดได้ด้วย ?w=320)
altstringไม่บังคับข้อความแทนรูป (การเข้าถึง)
positionintegerไม่บังคับลำดับ (1 = รูปหลัก)
widthintegerไม่บังคับกว้าง (px)
heightintegerไม่บังคับสูง (px)
variantsarray<object>จำเป็นตัวเลือก (สี/ขนาด) — ทุกสินค้ามีอย่างน้อย 1 variant
ฟิลด์ย่อยของ
variants(10)skustringจำเป็นรหัส SKU ไม่ซ้ำทั้งร้าน (ใช้ในตะกร้า/คำสั่งซื้อ)
titlestringจำเป็นชื่อตัวเลือกที่แสดง
optionsobjectไม่บังคับคู่ตัวเลือก เช่น { color, size } (สูงสุด 3 มิติ)
priceintegerจำเป็นราคาขายปลีก (สตางค์ รวม VAT)
dealer_priceintegerไม่บังคับราคาตัวแทน — แสดงค่าเฉพาะ key ที่มี products:read_dealer (key อื่นได้ null)
compare_at_priceintegerไม่บังคับราคาก่อนลด (ขีดฆ่า) — null ถ้าไม่ลดราคา
barcodestringไม่บังคับบาร์โค้ด EAN-13
weight_gintegerไม่บังคับน้ำหนักรวมบรรจุภัณฑ์ (กรัม) ใช้คิดค่าส่งตัวแทน
inventoryobjectไม่บังคับอ่านอย่างเดียวสต็อกของ variant นี้ (อ่านอย่างเดียว — ปรับผ่าน /inventory)
ฟิลด์ย่อยของ
inventory(4)availableintegerไม่บังคับอ่านอย่างเดียวขายได้ = on_hand − reserved (ตะกร้าที่จองอยู่)
on_handintegerไม่บังคับอ่านอย่างเดียวคงเหลือจริงทุกคลัง
reservedintegerไม่บังคับอ่านอย่างเดียวถูกจองในตะกร้า (15 นาที)
by_warehousearray<object>ไม่บังคับอ่านอย่างเดียวคงเหลือแยกคลัง
ฟิลด์ย่อยของ
by_warehouse(2)warehouse_idstringไม่บังคับคลัง
on_handintegerไม่บังคับคงเหลือในคลังนี้
statusenumไม่บังคับอ่านอย่างเดียวสถานะการขาย (low_stock = เหลือ ≤ 5)
price_rangeobjectไม่บังคับอ่านอย่างเดียวราคาต่ำสุด-สูงสุดของ variant (สตางค์)
ratingnumberไม่บังคับอ่านอย่างเดียวคะแนนรีวิวเฉลี่ย 1–5
reviews_countintegerไม่บังคับอ่านอย่างเดียวจำนวนรีวิว
sold_30dintegerไม่บังคับอ่านอย่างเดียวขายได้ 30 วันล่าสุด (ชิ้น) ใช้เรียง best_selling
statusenumไม่บังคับactive = ขายอยู่ · draft = ยังไม่แสดง · archived = เลิกจำหน่าย (ดูได้ด้วย id)
tagsarray<string>ไม่บังคับป้าย เช่น bestseller montessori gift
replacement_idstringไม่บังคับสินค้าทดแทนเมื่อ archived
createdstring · date-timeไม่บังคับอ่านอย่างเดียวเวลาสร้าง
updatedstring · date-timeไม่บังคับอ่านอย่างเดียวแก้ล่าสุด
metadataobjectไม่บังคับข้อมูลของคุณเอง (เช่น รหัสใน ERP)
{
"id": "prd_TRN003",
"object": "product",
"slug": "wooden-train-3",
"name": "รถไฟไม้หัวรถจักร + 2 ตู้",
"name_en": "Wooden Train Set (3 cars)",
"description": "ต่อพ่วงด้วยแม่เหล็ก ล้อหมุนลื่น ขอบมนทุกด้าน",
"category": "wooden-toys",
"age_min_months": 24,
"age_max_months": 72,
"age_label": "2 ปี–6 ปี",
"material": "ไม้ยางพาราสวนป่า สีน้ำปลอดสารตะกั่ว",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0412",
"tested_at": "2026-04-02",
"small_parts": true,
"warning": "ไม่เหมาะกับเด็กต่ำกว่า 3 ปี มีชิ้นส่วนเล็ก (ล้อ)"
},
"images": [
{
"id": "img_TRN0031",
"url": "https://files.leklek.example/products/wooden-train-3-1.webp",
"alt": "รถไฟไม้หัวรถจักร + 2 ตู้",
"position": 1,
"width": 1024,
"height": 1024
}
],
"variants": [
{
"sku": "LK-TRN-003",
"title": "ชุดคลาสสิก 3 ตู้",
"options": {
"set": "classic"
},
"price": 89000,
"dealer_price": null,
"compare_at_price": null,
"barcode": "8850890000003",
"weight_g": 820,
"inventory": {
"available": 55,
"on_hand": 58,
"reserved": 3,
"by_warehouse": [
{
"warehouse_id": "wh_bkk1",
"on_hand": 46
},
{
"warehouse_id": "wh_cnx1",
"on_hand": 12
}
]
},
"status": "in_stock"
}
],
"price_range": {
"min": 89000,
"max": 89000
},
"rating": 4.8,
"reviews_count": 214,
"sold_30d": 132,
"status": "active",
"tags": [
"bestseller",
"gift"
],
"replacement_id": null,
"created": "2025-02-10T09:00:00+07:00",
"updated": "2026-10-01T09:00:00+07:00",
"metadata": {}
}
The Variant object
ตัวเลือกของสินค้า (SKU) — หน่วยที่ใช้ในตะกร้า/คำสั่งซื้อจริง · ตัวอย่างกระติกน้ำสีมิ้นต์ (มีในตะกร้า 2 ใบ)
skustringจำเป็นรหัส SKU ไม่ซ้ำทั้งร้าน (ใช้ในตะกร้า/คำสั่งซื้อ)
titlestringจำเป็นชื่อตัวเลือกที่แสดง
optionsobjectไม่บังคับคู่ตัวเลือก เช่น { color, size } (สูงสุด 3 มิติ)
priceintegerจำเป็นราคาขายปลีก (สตางค์ รวม VAT)
dealer_priceintegerไม่บังคับราคาตัวแทน — แสดงค่าเฉพาะ key ที่มี products:read_dealer (key อื่นได้ null)
compare_at_priceintegerไม่บังคับราคาก่อนลด (ขีดฆ่า) — null ถ้าไม่ลดราคา
barcodestringไม่บังคับบาร์โค้ด EAN-13
weight_gintegerไม่บังคับน้ำหนักรวมบรรจุภัณฑ์ (กรัม) ใช้คิดค่าส่งตัวแทน
inventoryobjectไม่บังคับอ่านอย่างเดียวสต็อกของ variant นี้ (อ่านอย่างเดียว — ปรับผ่าน /inventory)
ฟิลด์ย่อยของ
inventory(4)availableintegerไม่บังคับอ่านอย่างเดียวขายได้ = on_hand − reserved (ตะกร้าที่จองอยู่)
on_handintegerไม่บังคับอ่านอย่างเดียวคงเหลือจริงทุกคลัง
reservedintegerไม่บังคับอ่านอย่างเดียวถูกจองในตะกร้า (15 นาที)
by_warehousearray<object>ไม่บังคับอ่านอย่างเดียวคงเหลือแยกคลัง
ฟิลด์ย่อยของ
by_warehouse(2)warehouse_idstringไม่บังคับคลัง
on_handintegerไม่บังคับคงเหลือในคลังนี้
statusenumไม่บังคับอ่านอย่างเดียวสถานะการขาย (low_stock = เหลือ ≤ 5)
{
"sku": "LK-BTL-450-MT",
"title": "สีมิ้นต์",
"options": {
"color": "mint"
},
"price": 39000,
"dealer_price": null,
"compare_at_price": null,
"barcode": "8850390000450",
"weight_g": 320,
"inventory": {
"available": 146,
"on_hand": 150,
"reserved": 4,
"by_warehouse": [
{
"warehouse_id": "wh_bkk1",
"on_hand": 120
},
{
"warehouse_id": "wh_cnx1",
"on_hand": 30
}
]
},
"status": "in_stock"
}
The Inventory object
สต็อกของ SKU แยกคลัง — ตัวอย่างตุ๊กตากระต่าย 45 ซม. ที่หมดและมีของเข้า
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
skustringไม่บังคับSKU
availableintegerไม่บังคับขายได้รวมทุกคลัง
on_handintegerไม่บังคับคงเหลือจริงรวม
reservedintegerไม่บังคับจองในตะกร้า
levelsarray<object>ไม่บังคับแยกตามคลัง
ฟิลด์ย่อยของ
levels(6)warehouse_idstringไม่บังคับรหัสคลัง
warehousestringไม่บังคับชื่อคลัง
on_handintegerไม่บังคับคงเหลือ
reservedintegerไม่บังคับจอง
availableintegerไม่บังคับขายได้
incomingarray<object>ไม่บังคับของที่กำลังเข้า (จากใบสั่งซื้อ)
ฟิลด์ย่อยของ
incoming(3)quantityintegerไม่บังคับจำนวน
etastring · dateไม่บังคับวันที่คาดว่าเข้า
postringไม่บังคับเลขใบสั่งซื้อ
reorder_pointintegerไม่บังคับจุดสั่งซื้อซ้ำ (แจ้ง inventory.low_stock)
updatedstring · date-timeไม่บังคับอ่านอย่างเดียวอัปเดตล่าสุด
{
"object": "inventory",
"sku": "LK-BNY-045-CR",
"available": 0,
"on_hand": 0,
"reserved": 0,
"levels": [
{
"warehouse_id": "wh_bkk1",
"warehouse": "คลังกรุงเทพฯ (รามอินทรา — สมมติ)",
"on_hand": 0,
"reserved": 0,
"available": 0,
"incoming": [
{
"quantity": 24,
"eta": "2026-10-19",
"po": "PO-2610-018"
}
]
},
{
"warehouse_id": "wh_cnx1",
"warehouse": "คลังเชียงใหม่ (สมมติ)",
"on_hand": 0,
"reserved": 0,
"available": 0,
"incoming": []
}
],
"reorder_point": 10,
"updated": "2026-10-12T10:24:02+07:00"
}Endpoints (12)
| Method | Path | ทำอะไร | scope |
|---|---|---|---|
| GET | /v2/products | ค้นหา/รายการสินค้า | products:read |
| GET | /v2/products/{product_id} | ดูสินค้า | products:read |
| POST | /v2/products | สร้างสินค้าidempotent | products:write |
| PATCH | /v2/products/{product_id} | แก้ไขสินค้า | products:write |
| DELETE | /v2/products/{product_id} | เลิกจำหน่าย (archive) | products:write |
| GET | /v2/products/{product_id}/variants | ตัวเลือกของสินค้า | products:read |
| POST | /v2/products/batch | นำเข้าสินค้าแบบ batchidempotent | products:write |
| GET | /v2/categories | หมวดสินค้า | products:read |
| GET | /v2/inventory | สต็อกตามคลัง | inventory:read |
| POST | /v2/inventory/adjustments | ปรับสต็อกidempotent | inventory:write |
| POST | /v2/products/{product_id}/images | เพิ่มรูปสินค้าidempotent | products:write |
| GET | /v2/products/suggest | คำแนะนำขณะพิมพ์ค้นหาBeta | products:read |
ค้นหา/รายการสินค้า
ค้นหาด้วยคำค้น (ไทย/อังกฤษ) กรองหมวด อายุเด็ก ช่วงราคา มีของ และเรียงได้ — ใช้กับหน้ารวมสินค้า ช่องค้นหา และ "แนะนำตามวัยลูก" · หมวดแม่รวมหมวดย่อยให้อัตโนมัติ
Query parametersquery
qstringไม่บังคับคำค้น (ชื่อ ชื่ออังกฤษ ป้าย วัสดุ SKU)
categorystringไม่บังคับslug หมวด (หมวดแม่รวมหมวดย่อย)
age_monthsintegerไม่บังคับอายุเด็ก (เดือน) — คืนสินค้าที่ช่วงอายุครอบคลุม
price_minintegerไม่บังคับราคาต่ำสุด (สตางค์)
price_maxintegerไม่บังคับราคาสูงสุด (สตางค์)
in_stockbooleanไม่บังคับเฉพาะที่มีของ
tagsarray<string>ไม่บังคับป้าย (ต้องมีทุกป้าย)
sortenumไม่บังคับการเรียง
limitintegerไม่บังคับจำนวนรายการต่อหน้า
starting_afterstringไม่บังคับcursor — id ของรายการสุดท้ายในหน้าก่อน (ใช้ค่า next_cursor ที่ได้)
ending_beforestringไม่บังคับcursor ย้อนกลับ — id ของรายการแรกในหน้าปัจจุบัน
expand[]array<string>ไม่บังคับขยาย object ที่อ้างถึงให้มาในคำตอบเดียว (ลดจำนวนคำขอ)
ผลลัพธ์
- 200พบ 4 รายการ (ตัวอย่าง: คำว่า "ไม้" ในหมวดของเล่นไม้ เด็ก 24 เดือน ไม่เกิน ฿600 เรียงขายดี)
- 400ค่ากรองผิด เช่น sort ไม่รู้จัก หรือ price_min > price_max
- 400
invalid_requestคำขอไม่ถูกต้อง - 429
rate_limitedเรียกเกินโควตา
- ราคาในตัวกรองเป็นสตางค์ (60000 = ฿600)
- สินค้า archived ไม่ขึ้นในผลค้นหา แต่ GET ด้วย id ยังได้ (ลิงก์เก่าไม่พัง)
- ลองประกอบ query และดูผลจริงได้ในเครื่องมือท้ายหน้า
curl -X GET "https://sandbox.api.leklek.example/v2/products?q=%E0%B9%84%E0%B8%A1%E0%B9%89&category=wooden-toys&age_months=24&price_max=60000" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "LekLek-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/products?q=%E0%B9%84%E0%B8%A1%E0%B9%89&category=wooden-toys&age_months=24&price_max=60000', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'LekLek-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.get(
"https://sandbox.api.leklek.example/v2/products?q=%E0%B9%84%E0%B8%A1%E0%B9%89&category=wooden-toys&age_months=24&price_max=60000",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v2/products",
"has_more": false,
"next_cursor": null,
"data": [
{
"id": "prd_BLK012",
"object": "product",
"slug": "pastel-blocks",
"name": "บล็อกไม้ต่อตึกสีพาสเทล",
"category": "wooden-toys",
"age_label": "1 ปี–4 ปี",
"price_range": {
"min": 59000,
"max": 99000
},
"image": {
"url": "https://files.leklek.example/products/pastel-blocks-1.webp",
"alt": "บล็อกไม้ต่อตึกสีพาสเทล"
},
"in_stock": true,
"rating": 4.7,
"reviews_count": 168,
"sold_30d": 97,
"status": "active"
},
{
"id": "prd_PZL009",
"object": "product",
"slug": "shape-puzzle",
"name": "พัซเซิลไม้รูปทรง 9 ชิ้น",
"category": "puzzle",
"age_label": "1 ปี 6 เดือน–4 ปี",
"price_range": {
"min": 45000,
"max": 45000
},
"image": {
"url": "https://files.leklek.example/products/shape-puzzle-1.webp",
"alt": "พัซเซิลไม้รูปทรง 9 ชิ้น"
},
"in_stock": true,
"rating": 4.6,
"reviews_count": 91,
"sold_30d": 64,
"status": "active"
},
{
"id": "prd_STK005",
"object": "product",
"slug": "stacking-rings",
"name": "ห่วงเรียงซ้อนไม้ 5 ชั้น",
"category": "wooden-toys",
"age_label": "6 เดือน–2 ปี",
"price_range": {
"min": 32000,
"max": 32000
},
"image": null,
"in_stock": true,
"rating": 4.6,
"reviews_count": 112,
"sold_30d": 58,
"status": "active"
},
{
"id": "prd_XYL008",
"object": "product",
"slug": "xylophone-8",
"name": "ระนาดไม้ 8 เสียง",
"category": "music",
"age_label": "1 ปี 6 เดือน–5 ปี",
"price_range": {
"min": 52000,
"max": 52000
},
"image": null,
"in_stock": true,
"rating": 4.5,
"reviews_count": 58,
"sold_30d": 31,
"status": "active"
}
],
"total_estimate": 4,
"facets": [
{
"category": "wooden-toys",
"name": "ของเล่นไม้",
"count": 2
},
{
"category": "puzzle",
"name": "พัซเซิลและฝึกสมอง",
"count": 1
},
{
"category": "music",
"name": "เครื่องดนตรีของเล่น",
"count": 1
}
]
}{
"error": {
"code": "invalid_request",
"message": "sort ต้องเป็นหนึ่งใน relevance, best_selling, price_asc, price_desc, newest, rating",
"param": "sort",
"request_id": "req_6Rt3Yq8M"
}
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_request"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#rate_limited"
}
}ดูสินค้า
รายละเอียดสินค้าเต็มรวม variant สต็อก มาตรฐานความปลอดภัย และรูป — ระบุด้วย id หรือ slug ก็ได้
Path parameterspath
product_idstringจำเป็นรหัสสินค้า (prd_…) หรือ slug
Query parametersquery
expand[]array<string>ไม่บังคับขยาย object ที่อ้างถึงให้มาในคำตอบเดียว (ลดจำนวนคำขอ)
Headersheader
LekLek-Accountstringไม่บังคับเฉพาะตัวแทนจำหน่าย: รหัสตัวแทน (ระบบตรวจว่าตรงกับ key)
ผลลัพธ์
- 200สินค้า (key ทั่วไป dealer_price = null)
- 404
product_not_foundไม่พบสินค้า - 401
authentication_requiredไม่ได้ส่งข้อมูลยืนยันตัวตน
- ตัวแทน (dlr_014) เรียกด้วย key ตัวเองจะเห็น dealer_price จริง เช่น รถไฟไม้หัวรถจักร + 2 ตู้ ฿623
curl -X GET "https://sandbox.api.leklek.example/v2/products/prd_TRN003" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "LekLek-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/products/prd_TRN003', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'LekLek-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.get(
"https://sandbox.api.leklek.example/v2/products/prd_TRN003",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "prd_TRN003",
"object": "product",
"slug": "wooden-train-3",
"name": "รถไฟไม้หัวรถจักร + 2 ตู้",
"name_en": "Wooden Train Set (3 cars)",
"description": "ต่อพ่วงด้วยแม่เหล็ก ล้อหมุนลื่น ขอบมนทุกด้าน",
"category": "wooden-toys",
"age_min_months": 24,
"age_max_months": 72,
"age_label": "2 ปี–6 ปี",
"material": "ไม้ยางพาราสวนป่า สีน้ำปลอดสารตะกั่ว",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0412",
"tested_at": "2026-04-02",
"small_parts": true,
"warning": "ไม่เหมาะกับเด็กต่ำกว่า 3 ปี มีชิ้นส่วนเล็ก (ล้อ)"
},
"images": [
{
"id": "img_TRN0031",
"url": "https://files.leklek.example/products/wooden-train-3-1.webp",
"alt": "รถไฟไม้หัวรถจักร + 2 ตู้",
"position": 1,
"width": 1024,
"height": 1024
}
],
"variants": [
{
"sku": "LK-TRN-003",
"title": "ชุดคลาสสิก 3 ตู้",
"options": {
"set": "classic"
},
"price": 89000,
"dealer_price": null,
"compare_at_price": null,
"barcode": "8850890000003",
"weight_g": 820,
"inventory": {
"available": 55,
"on_hand": 58,
"reserved": 3,
"by_warehouse": [
{
"warehouse_id": "wh_bkk1",
"on_hand": 46
},
{
"warehouse_id": "wh_cnx1",
"on_hand": 12
}
]
},
"status": "in_stock"
}
],
"price_range": {
"min": 89000,
"max": 89000
},
"rating": 4.8,
"reviews_count": 214,
"sold_30d": 132,
"status": "active",
"tags": [
"bestseller",
"gift"
],
"replacement_id": null,
"created": "2025-02-10T09:00:00+07:00",
"updated": "2026-10-01T09:00:00+07:00",
"metadata": {}
}{
"error": {
"code": "product_not_found",
"message": "ไม่พบสินค้า",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#product_not_found"
}
}{
"error": {
"code": "authentication_required",
"message": "ไม่ได้ส่งข้อมูลยืนยันตัวตน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#authentication_required"
}
}สร้างสินค้า
เพิ่มสินค้าใหม่พร้อม variant (สร้างเป็น draft ก่อนแล้วค่อยเปิดขาย) — หมวดของเล่นต้องมี safety · SKU ต้องไม่ซ้ำ
Headersheader
Idempotency-Keystring · uuidไม่บังคับUUID ที่ไม่ซ้ำต่อการกระทำ — ส่งซ้ำด้วยค่าเดิมภายใน 24 ชม. จะได้ผลเดิมโดยไม่สร้างรายการซ้ำ
Request bodyapplication/json
slugstringจำเป็นใช้ใน URL หน้าสินค้า (ไม่ซ้ำ · a-z 0-9 -)
namestringจำเป็นชื่อสินค้าภาษาไทย
name_enstringไม่บังคับชื่อภาษาอังกฤษ (ใช้ในเว็บภาษาอังกฤษและฉลาก)
descriptionstringไม่บังคับรายละเอียดสินค้า (Markdown แบบจำกัด)
categorystringจำเป็นslug ของหมวด (ดู GET /v2/categories)
age_min_monthsintegerจำเป็นอายุแนะนำขั้นต่ำ (เดือน)
age_max_monthsintegerไม่บังคับอายุแนะนำสูงสุด (เดือน) — null = ไม่มีขั้นบน
materialstringไม่บังคับวัสดุ
safetyobjectไม่บังคับมาตรฐานความปลอดภัยของเล่นและคำเตือน (บังคับสำหรับหมวดของเล่น)
ฟิลด์ย่อยของ
safety(5)standardstringไม่บังคับมาตรฐานความปลอดภัยของเล่นที่ผ่าน (ตัวอย่างนี้ใช้เลขมาตรฐานสมมติ)
cert_nostringไม่บังคับเลขใบรับรองผลทดสอบของล็อตปัจจุบัน
tested_atstring · dateไม่บังคับวันที่ทดสอบ
small_partsbooleanไม่บังคับมีชิ้นส่วนเล็ก (แอปต้องแสดงคำเตือนสำหรับเด็กต่ำกว่า 3 ปี)
warningstringไม่บังคับคำเตือนที่ต้องแสดงในหน้าสินค้า
variantsarray<object>จำเป็นตัวเลือก (สี/ขนาด) — ทุกสินค้ามีอย่างน้อย 1 variant
ฟิลด์ย่อยของ
variants(8)skustringจำเป็นรหัส SKU ไม่ซ้ำทั้งร้าน (ใช้ในตะกร้า/คำสั่งซื้อ)
titlestringจำเป็นชื่อตัวเลือกที่แสดง
optionsobjectไม่บังคับคู่ตัวเลือก เช่น { color, size } (สูงสุด 3 มิติ)
priceintegerจำเป็นราคาขายปลีก (สตางค์ รวม VAT)
dealer_priceintegerไม่บังคับราคาตัวแทน — แสดงค่าเฉพาะ key ที่มี products:read_dealer (key อื่นได้ null)
compare_at_priceintegerไม่บังคับราคาก่อนลด (ขีดฆ่า) — null ถ้าไม่ลดราคา
barcodestringไม่บังคับบาร์โค้ด EAN-13
weight_gintegerไม่บังคับน้ำหนักรวมบรรจุภัณฑ์ (กรัม) ใช้คิดค่าส่งตัวแทน
statusenumไม่บังคับactive = ขายอยู่ · draft = ยังไม่แสดง · archived = เลิกจำหน่าย (ดูได้ด้วย id)
tagsarray<string>ไม่บังคับป้าย เช่น bestseller montessori gift
replacement_idstringไม่บังคับสินค้าทดแทนเมื่อ archived
metadataobjectไม่บังคับข้อมูลของคุณเอง (เช่น รหัสใน ERP)
ผลลัพธ์
- 201สร้างแล้ว (draft)
- 409
sku_already_existsSKU ซ้ำ - 422
invalid_age_rangeช่วงอายุไม่ถูกต้อง - 422
validation_failedข้อมูลไม่ผ่านการตรวจ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่ body ต่าง - 403
insufficient_scopeสิทธิ์ไม่พอ
- เปิดขายด้วย PATCH status=active หลังเพิ่มรูปและสต็อก
- ราคาเป็นสตางค์รวม VAT
curl -X POST "https://sandbox.api.leklek.example/v2/products" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "LekLek-Version: 2026-08-01" \
-d '{
"slug": "wooden-abacus-10",
"name": "ลูกคิดไม้ 10 แถว",
"name_en": "Wooden Abacus 10 rows",
"description": "ฝึกนับเลข 1–100 ลูกปัดไม้สีพาสเทล",
"category": "learning",
"age_min_months": 36,
"age_max_months": 96,
"material": "ไม้บีช สีน้ำ",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0440",
"tested_at": "2026-09-22",
"small_parts": false,
"warning": "ควรเล่นภายใต้การดูแลของผู้ใหญ่"
},
"variants": [
{
"sku": "LK-ABA-010",
"title": "สีพาสเทล",
"options": {
"color": "pastel"
},
"price": 42000,
"barcode": "8850420000010",
"weight_g": 650
}
],
"status": "draft",
"tags": [
"learning",
"new"
]
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/products', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'LekLek-Version': '2026-08-01',
},
body: JSON.stringify({
"slug": "wooden-abacus-10",
"name": "ลูกคิดไม้ 10 แถว",
"name_en": "Wooden Abacus 10 rows",
"description": "ฝึกนับเลข 1–100 ลูกปัดไม้สีพาสเทล",
"category": "learning",
"age_min_months": 36,
"age_max_months": 96,
"material": "ไม้บีช สีน้ำ",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0440",
"tested_at": "2026-09-22",
"small_parts": false,
"warning": "ควรเล่นภายใต้การดูแลของผู้ใหญ่"
},
"variants": [
{
"sku": "LK-ABA-010",
"title": "สีพาสเทล",
"options": {
"color": "pastel"
},
"price": 42000,
"barcode": "8850420000010",
"weight_g": 650
}
],
"status": "draft",
"tags": [
"learning",
"new"
]
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.post(
"https://sandbox.api.leklek.example/v2/products",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"LekLek-Version": "2026-08-01",
},
json={
"slug": "wooden-abacus-10",
"name": "ลูกคิดไม้ 10 แถว",
"name_en": "Wooden Abacus 10 rows",
"description": "ฝึกนับเลข 1–100 ลูกปัดไม้สีพาสเทล",
"category": "learning",
"age_min_months": 36,
"age_max_months": 96,
"material": "ไม้บีช สีน้ำ",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0440",
"tested_at": "2026-09-22",
"small_parts": False,
"warning": "ควรเล่นภายใต้การดูแลของผู้ใหญ่"
},
"variants": [
{
"sku": "LK-ABA-010",
"title": "สีพาสเทล",
"options": {
"color": "pastel"
},
"price": 42000,
"barcode": "8850420000010",
"weight_g": 650
}
],
"status": "draft",
"tags": [
"learning",
"new"
]
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "prd_ABA010",
"object": "product",
"slug": "wooden-abacus-10",
"name": "ลูกคิดไม้ 10 แถว",
"name_en": "Wooden Abacus 10 rows",
"description": "ฝึกนับเลข 1–100 ลูกปัดไม้สีพาสเทล",
"category": "learning",
"age_min_months": 36,
"age_max_months": 96,
"material": "ไม้บีช สีน้ำ",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0440",
"tested_at": "2026-09-22",
"small_parts": false,
"warning": "ควรเล่นภายใต้การดูแลของผู้ใหญ่"
},
"variants": [
{
"sku": "LK-ABA-010",
"title": "สีพาสเทล",
"options": {
"color": "pastel"
},
"price": 42000,
"barcode": "8850420000010",
"weight_g": 650,
"dealer_price": null,
"compare_at_price": null,
"inventory": {
"available": 0,
"on_hand": 0,
"reserved": 0,
"by_warehouse": []
},
"status": "out_of_stock"
}
],
"status": "draft",
"tags": [
"learning",
"new"
],
"age_label": "3 ปี–8 ปี",
"images": [],
"price_range": {
"min": 42000,
"max": 42000
},
"rating": 0,
"reviews_count": 0,
"sold_30d": 0,
"replacement_id": null,
"created": "2026-10-12T11:05:00+07:00",
"updated": "2026-10-12T11:05:00+07:00",
"metadata": {}
}{
"error": {
"code": "sku_already_exists",
"message": "SKU ซ้ำ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#sku_already_exists"
}
}{
"error": {
"code": "invalid_age_range",
"message": "ช่วงอายุไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_age_range"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านการตรวจ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#validation_failed"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่ body ต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#idempotency_conflict"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#insufficient_scope"
}
}แก้ไขสินค้า
PATCH/v2/products/{product_id}
แก้ชื่อ ราคา ช่วงอายุ ป้าย สถานะ หรือ variant — เปลี่ยนราคาแล้วตะกร้าที่มีสินค้านี้จะได้ warnings price_changed ครั้งถัดไปที่เปิด
Path parameterspath
product_idstringจำเป็นรหัสสินค้า (prd_…) หรือ slug
Request bodyapplication/json
slugstringไม่บังคับใช้ใน URL หน้าสินค้า (ไม่ซ้ำ · a-z 0-9 -)
namestringไม่บังคับชื่อสินค้าภาษาไทย
name_enstringไม่บังคับชื่อภาษาอังกฤษ (ใช้ในเว็บภาษาอังกฤษและฉลาก)
descriptionstringไม่บังคับรายละเอียดสินค้า (Markdown แบบจำกัด)
categorystringไม่บังคับslug ของหมวด (ดู GET /v2/categories)
age_min_monthsintegerไม่บังคับอายุแนะนำขั้นต่ำ (เดือน)
age_max_monthsintegerไม่บังคับอายุแนะนำสูงสุด (เดือน) — null = ไม่มีขั้นบน
materialstringไม่บังคับวัสดุ
safetyobjectไม่บังคับมาตรฐานความปลอดภัยของเล่นและคำเตือน (บังคับสำหรับหมวดของเล่น)
ฟิลด์ย่อยของ
safety(5)standardstringไม่บังคับมาตรฐานความปลอดภัยของเล่นที่ผ่าน (ตัวอย่างนี้ใช้เลขมาตรฐานสมมติ)
cert_nostringไม่บังคับเลขใบรับรองผลทดสอบของล็อตปัจจุบัน
tested_atstring · dateไม่บังคับวันที่ทดสอบ
small_partsbooleanไม่บังคับมีชิ้นส่วนเล็ก (แอปต้องแสดงคำเตือนสำหรับเด็กต่ำกว่า 3 ปี)
warningstringไม่บังคับคำเตือนที่ต้องแสดงในหน้าสินค้า
variantsarray<object>ไม่บังคับตัวเลือก (สี/ขนาด) — ทุกสินค้ามีอย่างน้อย 1 variant
ฟิลด์ย่อยของ
variants(8)skustringไม่บังคับรหัส SKU ไม่ซ้ำทั้งร้าน (ใช้ในตะกร้า/คำสั่งซื้อ)
titlestringไม่บังคับชื่อตัวเลือกที่แสดง
optionsobjectไม่บังคับคู่ตัวเลือก เช่น { color, size } (สูงสุด 3 มิติ)
priceintegerไม่บังคับราคาขายปลีก (สตางค์ รวม VAT)
dealer_priceintegerไม่บังคับราคาตัวแทน — แสดงค่าเฉพาะ key ที่มี products:read_dealer (key อื่นได้ null)
compare_at_priceintegerไม่บังคับราคาก่อนลด (ขีดฆ่า) — null ถ้าไม่ลดราคา
barcodestringไม่บังคับบาร์โค้ด EAN-13
weight_gintegerไม่บังคับน้ำหนักรวมบรรจุภัณฑ์ (กรัม) ใช้คิดค่าส่งตัวแทน
statusenumไม่บังคับactive = ขายอยู่ · draft = ยังไม่แสดง · archived = เลิกจำหน่าย (ดูได้ด้วย id)
tagsarray<string>ไม่บังคับป้าย เช่น bestseller montessori gift
replacement_idstringไม่บังคับสินค้าทดแทนเมื่อ archived
metadataobjectไม่บังคับข้อมูลของคุณเอง (เช่น รหัสใน ERP)
ผลลัพธ์
- 200สินค้าหลังแก้
- 404
product_not_foundไม่พบสินค้า - 409
product_archivedสินค้าเลิกจำหน่ายแล้ว - 409
sku_already_existsSKU ซ้ำ - 422
invalid_age_rangeช่วงอายุไม่ถูกต้อง - 422
validation_failedข้อมูลไม่ผ่านการตรวจ
- variants[] จับคู่ด้วย sku — ไม่มี sku เดิม = เพิ่ม variant ใหม่ · ลบ variant ใช้ status=discontinued
curl -X PATCH "https://sandbox.api.leklek.example/v2/products/prd_TRN003" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "Content-Type: application/json" \
-H "LekLek-Version: 2026-08-01" \
-d '{
"tags": [
"bestseller",
"gift",
"back-to-school"
],
"variants": [
{
"sku": "LK-TRN-003",
"compare_at_price": 99000
}
]
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/products/prd_TRN003', {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'LekLek-Version': '2026-08-01',
},
body: JSON.stringify({
"tags": [
"bestseller",
"gift",
"back-to-school"
],
"variants": [
{
"sku": "LK-TRN-003",
"compare_at_price": 99000
}
]
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.patch(
"https://sandbox.api.leklek.example/v2/products/prd_TRN003",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"LekLek-Version": "2026-08-01",
},
json={
"tags": [
"bestseller",
"gift",
"back-to-school"
],
"variants": [
{
"sku": "LK-TRN-003",
"compare_at_price": 99000
}
]
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "prd_TRN003",
"object": "product",
"slug": "wooden-train-3",
"name": "รถไฟไม้หัวรถจักร + 2 ตู้",
"name_en": "Wooden Train Set (3 cars)",
"description": "ต่อพ่วงด้วยแม่เหล็ก ล้อหมุนลื่น ขอบมนทุกด้าน",
"category": "wooden-toys",
"age_min_months": 24,
"age_max_months": 72,
"age_label": "2 ปี–6 ปี",
"material": "ไม้ยางพาราสวนป่า สีน้ำปลอดสารตะกั่ว",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0412",
"tested_at": "2026-04-02",
"small_parts": true,
"warning": "ไม่เหมาะกับเด็กต่ำกว่า 3 ปี มีชิ้นส่วนเล็ก (ล้อ)"
},
"images": [
{
"id": "img_TRN0031",
"url": "https://files.leklek.example/products/wooden-train-3-1.webp",
"alt": "รถไฟไม้หัวรถจักร + 2 ตู้",
"position": 1,
"width": 1024,
"height": 1024
}
],
"variants": [
{
"sku": "LK-TRN-003",
"title": "ชุดคลาสสิก 3 ตู้",
"options": {
"set": "classic"
},
"price": 89000,
"dealer_price": null,
"compare_at_price": 99000,
"barcode": "8850890000003",
"weight_g": 820,
"inventory": {
"available": 55,
"on_hand": 58,
"reserved": 3,
"by_warehouse": [
{
"warehouse_id": "wh_bkk1",
"on_hand": 46
},
{
"warehouse_id": "wh_cnx1",
"on_hand": 12
}
]
},
"status": "in_stock"
}
],
"price_range": {
"min": 89000,
"max": 89000
},
"rating": 4.8,
"reviews_count": 214,
"sold_30d": 132,
"status": "active",
"tags": [
"bestseller",
"gift",
"back-to-school"
],
"replacement_id": null,
"created": "2025-02-10T09:00:00+07:00",
"updated": "2026-10-12T11:12:40+07:00",
"metadata": {}
}{
"error": {
"code": "product_not_found",
"message": "ไม่พบสินค้า",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#product_not_found"
}
}{
"error": {
"code": "product_archived",
"message": "สินค้าเลิกจำหน่ายแล้ว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#product_archived"
}
}{
"error": {
"code": "sku_already_exists",
"message": "SKU ซ้ำ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#sku_already_exists"
}
}{
"error": {
"code": "invalid_age_range",
"message": "ช่วงอายุไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_age_range"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านการตรวจ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#validation_failed"
}
}เลิกจำหน่าย (archive)
DELETE/v2/products/{product_id}
ไม่ลบจริง — เปลี่ยนเป็น archived: หายจากผลค้นหาและหยิบใส่ตะกร้าไม่ได้ แต่คำสั่งซื้อเก่าและลิงก์เดิมยังอ้างถึงได้ · กู้คืนด้วย PATCH status=active
Path parameterspath
product_idstringจำเป็นรหัสสินค้า
Query parametersquery
replacement_idstringไม่บังคับสินค้าทดแทนที่จะแนะนำ
ผลลัพธ์
- 200สินค้าที่ archive แล้ว
- 404
product_not_foundไม่พบสินค้า - 409
product_archivedสินค้าเลิกจำหน่ายแล้ว - 403
insufficient_scopeสิทธิ์ไม่พอ
- ตะกร้าที่มีสินค้านี้จะได้ 409 product_archived ตอนเช็กเอาต์ — แอปควรเสนอ replacement_id
curl -X DELETE "https://sandbox.api.leklek.example/v2/products/prd_BAL003?replacement_id=prd_STK005" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "LekLek-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/products/prd_BAL003?replacement_id=prd_STK005', {
method: 'DELETE',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'LekLek-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.delete(
"https://sandbox.api.leklek.example/v2/products/prd_BAL003?replacement_id=prd_STK005",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "prd_BAL003",
"object": "product",
"slug": "soft-balls-3",
"name": "ลูกบอลผ้านุ่ม 3 ลูก",
"name_en": "Soft Fabric Balls (3)",
"description": "เลิกจำหน่ายแล้ว (ยังเรียกดูได้ด้วย id)",
"category": "plush",
"age_min_months": 3,
"age_max_months": 24,
"age_label": "3 เดือน–2 ปี",
"material": "ผ้าฝ้าย ใยสังเคราะห์ มีกระดิ่งข้างใน",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0371",
"tested_at": "2026-04-02",
"small_parts": false,
"warning": "กระดิ่งเย็บปิดสองชั้น"
},
"images": [],
"variants": [
{
"sku": "LK-BAL-003",
"title": "ชุด 3 สี",
"options": {
"set": "3"
},
"price": 35000,
"dealer_price": null,
"compare_at_price": null,
"barcode": "8850350000003",
"weight_g": 210,
"inventory": {
"available": 0,
"on_hand": 0,
"reserved": 0,
"by_warehouse": [
{
"warehouse_id": "wh_bkk1",
"on_hand": 0
},
{
"warehouse_id": "wh_cnx1",
"on_hand": 0
}
]
},
"status": "out_of_stock"
}
],
"price_range": {
"min": 35000,
"max": 35000
},
"rating": 4.5,
"reviews_count": 52,
"sold_30d": 0,
"status": "archived",
"tags": [
"newborn"
],
"replacement_id": "prd_STK005",
"created": "2025-03-03T09:00:00+07:00",
"updated": "2026-09-30T17:00:00+07:00",
"metadata": {}
}{
"error": {
"code": "product_not_found",
"message": "ไม่พบสินค้า",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#product_not_found"
}
}{
"error": {
"code": "product_archived",
"message": "สินค้าเลิกจำหน่ายแล้ว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#product_archived"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#insufficient_scope"
}
}ตัวเลือกของสินค้า
GET/v2/products/{product_id}/variants
รายการ variant ของสินค้าพร้อมสต็อกล่าสุด (ไม่แคช) — ใช้ตอนลูกค้าสลับสี/ขนาดในหน้าสินค้า
Path parameterspath
product_idstringจำเป็นรหัสสินค้า
Query parametersquery
in_stockbooleanไม่บังคับเฉพาะที่มีของ
ผลลัพธ์
- 2003 สี (สีชมพูเหลือน้อย)
- 404
product_not_foundไม่พบสินค้า
- stock และ available อ่านจากคลังสดทุกครั้ง (ไม่แคช) — ใช้ endpoint นี้แทน GET /v2/products/{id} เมื่อต้องการเฉพาะสต็อกล่าสุด
- available = stock รวมทุกคลัง − จำนวนที่ถูกจองในตะกร้า (จอง 15 นาที)
curl -X GET "https://sandbox.api.leklek.example/v2/products/prd_BTL450/variants" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "LekLek-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/products/prd_BTL450/variants', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'LekLek-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.get(
"https://sandbox.api.leklek.example/v2/products/prd_BTL450/variants",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v2/products/prd_BTL450/variants",
"has_more": false,
"next_cursor": null,
"data": [
{
"sku": "LK-BTL-450-MT",
"title": "สีมิ้นต์",
"options": {
"color": "mint"
},
"price": 39000,
"dealer_price": null,
"compare_at_price": null,
"barcode": "8850390000450",
"weight_g": 320,
"inventory": {
"available": 146,
"on_hand": 150,
"reserved": 4,
"by_warehouse": [
{
"warehouse_id": "wh_bkk1",
"on_hand": 120
},
{
"warehouse_id": "wh_cnx1",
"on_hand": 30
}
]
},
"status": "in_stock"
},
{
"sku": "LK-BTL-450-PK",
"title": "สีชมพู",
"options": {
"color": "pink"
},
"price": 39000,
"dealer_price": null,
"compare_at_price": null,
"barcode": "8850390000450",
"weight_g": 320,
"inventory": {
"available": 4,
"on_hand": 4,
"reserved": 0,
"by_warehouse": [
{
"warehouse_id": "wh_bkk1",
"on_hand": 4
},
{
"warehouse_id": "wh_cnx1",
"on_hand": 0
}
]
},
"status": "low_stock"
},
{
"sku": "LK-BTL-450-SK",
"title": "สีฟ้า",
"options": {
"color": "sky"
},
"price": 39000,
"dealer_price": null,
"compare_at_price": null,
"barcode": "8850390000450",
"weight_g": 320,
"inventory": {
"available": 72,
"on_hand": 72,
"reserved": 0,
"by_warehouse": [
{
"warehouse_id": "wh_bkk1",
"on_hand": 58
},
{
"warehouse_id": "wh_cnx1",
"on_hand": 14
}
]
},
"status": "in_stock"
}
]
}{
"error": {
"code": "product_not_found",
"message": "ไม่พบสินค้า",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#product_not_found"
}
}นำเข้าสินค้าแบบ batch
สร้าง/อัปเดต (upsert ด้วย sku) ได้สูงสุด 500 รายการต่อคำขอ — ทำทีละรายการ รายการที่ผิดไม่ทำให้ทั้ง batch ล้ม (207 Multi-Status) · เกิน 100 รายการทำแบบ async ได้ 202 + webhook
Query parametersquery
asyncbooleanไม่บังคับทำเบื้องหลังแล้วแจ้งผลผ่าน webhook product.batch_completed
Headersheader
Idempotency-Keystring · uuidไม่บังคับUUID ที่ไม่ซ้ำต่อการกระทำ — ส่งซ้ำด้วยค่าเดิมภายใน 24 ชม. จะได้ผลเดิมโดยไม่สร้างรายการซ้ำ
Request bodyapplication/json
modeenumไม่บังคับupsert = สร้างหรือแก้ตาม sku · create_only = ซ้ำถือว่าผิด
itemsarray<object>จำเป็นสินค้า (โครงเดียวกับ POST /v2/products) สูงสุด 500
ฟิลด์ย่อยของ
items(6)slugstringจำเป็นใช้ใน URL หน้าสินค้า (ไม่ซ้ำ · a-z 0-9 -)
namestringจำเป็นชื่อสินค้าภาษาไทย
name_enstringไม่บังคับชื่อภาษาอังกฤษ (ใช้ในเว็บภาษาอังกฤษและฉลาก)
descriptionstringไม่บังคับรายละเอียดสินค้า (Markdown แบบจำกัด)
categorystringจำเป็นslug ของหมวด (ดู GET /v2/categories)
age_min_monthsintegerจำเป็นอายุแนะนำขั้นต่ำ (เดือน)
ผลลัพธ์
- 207ผลรายตัว (สำเร็จ 118 / ผิด 2)
- 202async=true: รับงานแล้ว
- 422
batch_too_largebatch ใหญ่เกิน - 400
invalid_jsonJSON อ่านไม่ได้ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่ body ต่าง - 403
insufficient_scopeสิทธิ์ไม่พอ
- ตัวอย่าง body แสดง 2 จาก 120 รายการ
- รายการที่ผิดแก้แล้วส่งเฉพาะรายการนั้นซ้ำได้ (ใช้ Idempotency-Key ใหม่)
- นำเข้าจาก CSV: แปลงเป็น JSON ฝั่งคุณ (หัวคอลัมน์ตรงกับชื่อฟิลด์) — ตัวอย่างไฟล์ใน docs.leklek.example/import
curl -X POST "https://sandbox.api.leklek.example/v2/products/batch" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "LekLek-Version: 2026-08-01" \
-d '{
"mode": "upsert",
"items": [
{
"slug": "wooden-abacus-10",
"name": "ลูกคิดไม้ 10 แถว",
"name_en": "Wooden Abacus 10 rows",
"description": "ฝึกนับเลข 1–100 ลูกปัดไม้สีพาสเทล",
"category": "learning",
"age_min_months": 36,
"age_max_months": 96,
"material": "ไม้บีช สีน้ำ",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0440",
"tested_at": "2026-09-22",
"small_parts": false,
"warning": "ควรเล่นภายใต้การดูแลของผู้ใหญ่"
},
"variants": [
{
"sku": "LK-ABA-010",
"title": "สีพาสเทล",
"options": {
"color": "pastel"
},
"price": 42000,
"barcode": "8850420000010",
"weight_g": 650
}
],
"status": "draft",
"tags": [
"learning",
"new"
]
},
{
"slug": "wooden-train-3",
"variants": [
{
"sku": "LK-TRN-003",
"price": 89000
}
]
}
]
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/products/batch', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'LekLek-Version': '2026-08-01',
},
body: JSON.stringify({
"mode": "upsert",
"items": [
{
"slug": "wooden-abacus-10",
"name": "ลูกคิดไม้ 10 แถว",
"name_en": "Wooden Abacus 10 rows",
"description": "ฝึกนับเลข 1–100 ลูกปัดไม้สีพาสเทล",
"category": "learning",
"age_min_months": 36,
"age_max_months": 96,
"material": "ไม้บีช สีน้ำ",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0440",
"tested_at": "2026-09-22",
"small_parts": false,
"warning": "ควรเล่นภายใต้การดูแลของผู้ใหญ่"
},
"variants": [
{
"sku": "LK-ABA-010",
"title": "สีพาสเทล",
"options": {
"color": "pastel"
},
"price": 42000,
"barcode": "8850420000010",
"weight_g": 650
}
],
"status": "draft",
"tags": [
"learning",
"new"
]
},
{
"slug": "wooden-train-3",
"variants": [
{
"sku": "LK-TRN-003",
"price": 89000
}
]
}
]
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.post(
"https://sandbox.api.leklek.example/v2/products/batch",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"LekLek-Version": "2026-08-01",
},
json={
"mode": "upsert",
"items": [
{
"slug": "wooden-abacus-10",
"name": "ลูกคิดไม้ 10 แถว",
"name_en": "Wooden Abacus 10 rows",
"description": "ฝึกนับเลข 1–100 ลูกปัดไม้สีพาสเทล",
"category": "learning",
"age_min_months": 36,
"age_max_months": 96,
"material": "ไม้บีช สีน้ำ",
"safety": {
"standard": "มอก. 6851-2568 (เลขมาตรฐานสมมติ)",
"cert_no": "LK-SAFE-26-0440",
"tested_at": "2026-09-22",
"small_parts": False,
"warning": "ควรเล่นภายใต้การดูแลของผู้ใหญ่"
},
"variants": [
{
"sku": "LK-ABA-010",
"title": "สีพาสเทล",
"options": {
"color": "pastel"
},
"price": 42000,
"barcode": "8850420000010",
"weight_g": 650
}
],
"status": "draft",
"tags": [
"learning",
"new"
]
},
{
"slug": "wooden-train-3",
"variants": [
{
"sku": "LK-TRN-003",
"price": 89000
}
]
}
]
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "batch_result",
"id": "bat_3Pk7",
"total": 120,
"succeeded": 118,
"failed": 2,
"results": [
{
"index": 0,
"status": 201,
"id": "prd_ABA010",
"sku": "LK-ABA-010"
},
{
"index": 1,
"status": 200,
"id": "prd_TRN003",
"sku": "LK-TRN-003",
"note": "อัปเดตราคา (upsert)"
},
{
"index": 37,
"status": 409,
"error": {
"code": "sku_already_exists",
"message": "SKU LK-BLK-012 เป็นของ prd_BLK012",
"param": "variants[0].sku"
}
},
{
"index": 81,
"status": 422,
"error": {
"code": "invalid_age_range",
"message": "age_min_months (48) มากกว่า age_max_months (36)",
"param": "age_min_months"
}
}
]
}{
"object": "batch_job",
"id": "bat_3Pk7",
"status": "processing",
"total": 120,
"status_url": "/v2/batch-jobs/bat_3Pk7"
}{
"error": {
"code": "batch_too_large",
"message": "batch ใหญ่เกิน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#batch_too_large"
}
}{
"error": {
"code": "invalid_json",
"message": "JSON อ่านไม่ได้",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_json"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่ body ต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#idempotency_conflict"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#insufficient_scope"
}
}หมวดสินค้า
หมวดทั้งหมดแบบต้นไม้ (parent) พร้อมจำนวนสินค้าที่ขายอยู่ — ใช้สร้างเมนูหมวดในเว็บ/แอป
Query parametersquery
parentstringไม่บังคับเฉพาะหมวดลูกของหมวดนี้ (id)
include_emptybooleanไม่บังคับรวมหมวดที่ไม่มีสินค้า
ผลลัพธ์
- 2007 หมวด
- 400
invalid_requestคำขอไม่ถูกต้อง
- ผลลัพธ์แคช 10 นาที (หัว Cache-Control: max-age=600) — แอปเก็บไว้ในเครื่องได้ ไม่ต้องเรียกทุกหน้า
- product_count นับเฉพาะสินค้า status=active ในหมวดนั้นโดยตรง (ไม่รวมหมวดลูก)
curl -X GET "https://sandbox.api.leklek.example/v2/categories" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "LekLek-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/categories', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'LekLek-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.get(
"https://sandbox.api.leklek.example/v2/categories",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v2/categories",
"has_more": false,
"next_cursor": null,
"data": [
{
"id": "cat_wood",
"slug": "wooden-toys",
"name": "ของเล่นไม้",
"parent": null,
"sort": 1,
"object": "category",
"product_count": 3
},
{
"id": "cat_plush",
"slug": "plush",
"name": "ตุ๊กตาผ้า",
"parent": null,
"sort": 2,
"object": "category",
"product_count": 1
},
{
"id": "cat_puzzle",
"slug": "puzzle",
"name": "พัซเซิลและฝึกสมอง",
"parent": "cat_wood",
"sort": 3,
"object": "category",
"product_count": 1
},
{
"id": "cat_music",
"slug": "music",
"name": "เครื่องดนตรีของเล่น",
"parent": "cat_wood",
"sort": 4,
"object": "category",
"product_count": 1
},
{
"id": "cat_learn",
"slug": "learning",
"name": "สื่อการเรียนรู้",
"parent": null,
"sort": 5,
"object": "category",
"product_count": 1
},
{
"id": "cat_pretend",
"slug": "pretend-play",
"name": "บทบาทสมมติ",
"parent": "cat_wood",
"sort": 6,
"object": "category",
"product_count": 1
},
{
"id": "cat_baby",
"slug": "baby-gear",
"name": "ของใช้เด็ก",
"parent": null,
"sort": 7,
"object": "category",
"product_count": 3
}
]
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_request"
}
}สต็อกตามคลัง
สต็อกของ SKU แยกตามคลัง (กรุงเทพฯ / เชียงใหม่) พร้อมของที่กำลังเข้า — ใช้แสดง "เหลือ n ชิ้น" และวันที่ของเข้าสำหรับสินค้าหมด
Query parametersquery
skustringจำเป็นSKU (คั่นด้วย , ได้ถึง 50)
warehouse_idstringไม่บังคับเฉพาะคลัง
ผลลัพธ์
- 200ของหมด มีของเข้า 24 ชิ้น 19 ต.ค.
- 400
invalid_requestคำขอไม่ถูกต้อง - 404
resource_not_foundไม่พบข้อมูล - 403
insufficient_scopeสิทธิ์ไม่พอ
- ตัวแทนเห็นเฉพาะ available (ไม่เห็นจำนวนต่อคลัง) — ส่วนที่ซ่อนได้ null
curl -X GET "https://sandbox.api.leklek.example/v2/inventory?sku=LK-BNY-045-CR" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "LekLek-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/inventory?sku=LK-BNY-045-CR', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'LekLek-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.get(
"https://sandbox.api.leklek.example/v2/inventory?sku=LK-BNY-045-CR",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v2/inventory",
"has_more": false,
"next_cursor": null,
"data": [
{
"object": "inventory",
"sku": "LK-BNY-045-CR",
"available": 0,
"on_hand": 0,
"reserved": 0,
"levels": [
{
"warehouse_id": "wh_bkk1",
"warehouse": "คลังกรุงเทพฯ (รามอินทรา — สมมติ)",
"on_hand": 0,
"reserved": 0,
"available": 0,
"incoming": [
{
"quantity": 24,
"eta": "2026-10-19",
"po": "PO-2610-018"
}
]
},
{
"warehouse_id": "wh_cnx1",
"warehouse": "คลังเชียงใหม่ (สมมติ)",
"on_hand": 0,
"reserved": 0,
"available": 0,
"incoming": []
}
],
"reorder_point": 10,
"updated": "2026-10-12T10:24:02+07:00"
}
]
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_request"
}
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#resource_not_found"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#insufficient_scope"
}
}ปรับสต็อก
รับของเข้า ตัดของเสีย หรือตรวจนับแล้วปรับยอด — บันทึกเหตุผลทุกครั้ง (ตรวจสอบย้อนหลังได้) และยิง inventory.restocked เมื่อของกลับมามี
Headersheader
Idempotency-Keystring · uuidไม่บังคับUUID ที่ไม่ซ้ำต่อการกระทำ — ส่งซ้ำด้วยค่าเดิมภายใน 24 ชม. จะได้ผลเดิมโดยไม่สร้างรายการซ้ำ
Request bodyapplication/json
skustringจำเป็นSKU
warehouse_idstringจำเป็นคลัง
deltaintegerจำเป็นจำนวนที่เพิ่ม (+) หรือลด (−)
reasonenumจำเป็นเหตุผล
referencestringไม่บังคับเอกสารอ้างอิง เช่น เลขใบสั่งซื้อ/RMA
ผลลัพธ์
- 201ปรับแล้ว
- 404
resource_not_foundไม่พบข้อมูล - 422
validation_failedข้อมูลไม่ผ่านการตรวจ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่ body ต่าง - 403
insufficient_scopeสิทธิ์ไม่พอ
- ลดจนติดลบไม่ได้ (422 validation_failed) — ยกเว้น reason=count_correction
curl -X POST "https://sandbox.api.leklek.example/v2/inventory/adjustments" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "LekLek-Version: 2026-08-01" \
-d '{
"sku": "LK-BNY-045-CR",
"warehouse_id": "wh_bkk1",
"delta": 24,
"reason": "received",
"reference": "PO-2610-018"
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/inventory/adjustments', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'LekLek-Version': '2026-08-01',
},
body: JSON.stringify({
"sku": "LK-BNY-045-CR",
"warehouse_id": "wh_bkk1",
"delta": 24,
"reason": "received",
"reference": "PO-2610-018"
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.post(
"https://sandbox.api.leklek.example/v2/inventory/adjustments",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"LekLek-Version": "2026-08-01",
},
json={
"sku": "LK-BNY-045-CR",
"warehouse_id": "wh_bkk1",
"delta": 24,
"reason": "received",
"reference": "PO-2610-018"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "inventory_adjustment",
"id": "iadj_9Qw1",
"sku": "LK-BNY-045-CR",
"warehouse_id": "wh_bkk1",
"delta": 24,
"reason": "received",
"reference": "PO-2610-018",
"on_hand_after": 24,
"created": "2026-10-19T09:30:00+07:00",
"created_by": "staff:wh_bkk1"
}{
"error": {
"code": "resource_not_found",
"message": "ไม่พบข้อมูล",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#resource_not_found"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านการตรวจ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#validation_failed"
}
}{
"error": {
"code": "idempotency_conflict",
"message": "Idempotency-Key ซ้ำแต่ body ต่าง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#idempotency_conflict"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#insufficient_scope"
}
}เพิ่มรูปสินค้า
POST/v2/products/{product_id}/images
เพิ่มรูปจาก URL ที่เข้าถึงได้ หรือจาก upload_token (อัปโหลดตรงไปที่เก็บไฟล์ก่อน) — ระบบย่อเป็นหลายขนาด แปลง webp และส่งขึ้น CDN แบบเบื้องหลัง
Path parameterspath
product_idstringจำเป็นรหัสสินค้า (prd_…) หรือ slug
Headersheader
Idempotency-Keystring · uuidไม่บังคับUUID ที่ไม่ซ้ำต่อการกระทำ — ส่งซ้ำด้วยค่าเดิมภายใน 24 ชม. จะได้ผลเดิมโดยไม่สร้างรายการซ้ำ
Request bodyapplication/json
source_urlstring · uriไม่บังคับURL รูปต้นฉบับ (https) — ใช้อย่างใดอย่างหนึ่งกับ upload_token
upload_tokenstringไม่บังคับtoken จาก POST /v2/uploads (ไฟล์ ≤ 8 MB · jpeg png webp)
altstringจำเป็นข้อความแทนรูป (จำเป็นเพื่อการเข้าถึง)
positionintegerไม่บังคับลำดับ (1 = รูปหลัก — รูปเดิมเลื่อนถัดไป)
ผลลัพธ์
- 201รับรูปแล้ว กำลังประมวลผล (status=processing ~5 วินาที)
- 413
image_too_largeไฟล์รูปใหญ่เกิน - 415
unsupported_media_typeชนิดไฟล์ไม่รองรับ - 404
product_not_foundไม่พบสินค้า - 422
validation_failedข้อมูลไม่ผ่านการตรวจ
- รูปที่มีข้อความ/โลโก้แบรนด์อื่นถูกตีกลับโดยทีมตรวจ (status=rejected + เหตุผล)
curl -X POST "https://sandbox.api.leklek.example/v2/products/prd_TRN003/images" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: 7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f" \
-H "LekLek-Version: 2026-08-01" \
-d '{
"source_url": "https://files.leklek.example/uploads/train-side.jpg",
"upload_token": "",
"alt": "รถไฟไม้มุมข้าง เห็นล้อและแม่เหล็กต่อพ่วง",
"position": 2
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/products/prd_TRN003/images', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'Idempotency-Key': '7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f',
'LekLek-Version': '2026-08-01',
},
body: JSON.stringify({
"source_url": "https://files.leklek.example/uploads/train-side.jpg",
"upload_token": "",
"alt": "รถไฟไม้มุมข้าง เห็นล้อและแม่เหล็กต่อพ่วง",
"position": 2
}),
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.post(
"https://sandbox.api.leklek.example/v2/products/prd_TRN003/images",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"LekLek-Version": "2026-08-01",
},
json={
"source_url": "https://files.leklek.example/uploads/train-side.jpg",
"upload_token": "",
"alt": "รถไฟไม้มุมข้าง เห็นล้อและแม่เหล็กต่อพ่วง",
"position": 2
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "img_TRN0032",
"object": "product_image",
"product_id": "prd_TRN003",
"url": "https://files.leklek.example/products/wooden-train-3-2.webp",
"alt": "รถไฟไม้มุมข้าง เห็นล้อและแม่เหล็กต่อพ่วง",
"position": 2,
"width": null,
"height": null,
"status": "processing",
"variants": {
"thumb": "?w=320",
"card": "?w=640",
"zoom": "?w=1600"
},
"created": "2026-10-12T11:20:00+07:00"
}{
"error": {
"code": "image_too_large",
"message": "ไฟล์รูปใหญ่เกิน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#image_too_large"
}
}{
"error": {
"code": "unsupported_media_type",
"message": "ชนิดไฟล์ไม่รองรับ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#unsupported_media_type"
}
}{
"error": {
"code": "product_not_found",
"message": "ไม่พบสินค้า",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#product_not_found"
}
}{
"error": {
"code": "validation_failed",
"message": "ข้อมูลไม่ผ่านการตรวจ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#validation_failed"
}
}คำแนะนำขณะพิมพ์ค้นหาBeta
คืนคำค้นแนะนำและสินค้า 5 อันดับแรกขณะผู้ใช้พิมพ์ (ตอบภายใน ~40 ms) — เรียกหลังผู้ใช้หยุดพิมพ์ 200 ms
Query parametersquery
qstringจำเป็นคำที่พิมพ์ (≥ 1 ตัวอักษร)
limitintegerไม่บังคับจำนวนสินค้า
ผลลัพธ์
- 200คำแนะนำ
- 400
invalid_requestคำขอไม่ถูกต้อง - 429
rate_limitedเรียกเกินโควตา
- คำค้นสั้นกว่า 2 ตัวอักษรได้ผลว่าง (200 data: []) ไม่ใช่ error
- รองรับพิมพ์ไทยผิดแป้น/ไม่มีวรรณยุกต์ (เช่น "รถไฟไม" → รถไฟไม้) — อย่าเรียกทุกตัวอักษร ให้หน่วง 200 ms
curl -X GET "https://sandbox.api.leklek.example/v2/products/suggest?q=%E0%B8%A3%E0%B8%96" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "LekLek-Version: 2026-08-01"const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/products/suggest?q=%E0%B8%A3%E0%B8%96', {
method: 'GET',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'LekLek-Version': '2026-08-01',
},
});
if (!res.ok) throw new Error((await res.json()).error.code);
const data = await res.json();
console.log(data);import os
import requests
API_KEY = os.environ["API_KEY"] # lk_test_51HcQ2xT8bWm4
res = requests.get(
"https://sandbox.api.leklek.example/v2/products/suggest?q=%E0%B8%A3%E0%B8%96",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "suggestion",
"q": "รถ",
"terms": [
"รถไฟไม้",
"รถไฟไม้ 3 ตู้"
],
"products": [
{
"id": "prd_TRN003",
"name": "รถไฟไม้หัวรถจักร + 2 ตู้",
"price_from": 89000,
"image": "https://files.leklek.example/products/wooden-train-3-1.webp?w=160"
}
]
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_request"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#rate_limited"
}
}Webhooks — แจ้งเหตุการณ์ไปที่ระบบของคุณ
ลงทะเบียน URL ปลายทาง แล้วระบบจะส่ง POST พร้อม JSON ทุกครั้งที่เกิดเหตุการณ์ด้านล่าง · ตอบกลับ 2xx ภายใน 10 วินาที ไม่งั้นจะส่งซ้ำตามตาราง · ทุกคำขอมีหัว LekLek-Signature ให้ตรวจว่ามาจากเราจริง · event อาจมาซ้ำหรือสลับลำดับ ให้ใช้ id กันประมวลผลซ้ำ
product.createdสร้างสินค้าใหม่
ส่งเมื่อ: POST /v2/products หรือรายการ batch สำเร็จ
{
"id": "evt_01JB7Q00",
"type": "product.created",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "prd_ABA010",
"slug": "wooden-abacus-10",
"status": "draft",
"variants": [
"LK-ABA-010"
]
}
}product.updatedข้อมูลสินค้าเปลี่ยน
ส่งเมื่อ: PATCH สินค้า/variant (ไม่รวมสต็อก)
{
"id": "evt_01JB7Q01",
"type": "product.updated",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "prd_TRN003",
"changed": [
"tags",
"variants[0].compare_at_price"
],
"updated": "2026-10-12T11:12:40+07:00"
}
}product.archivedเลิกจำหน่าย
ส่งเมื่อ: DELETE /v2/products/{id}
{
"id": "evt_01JB7Q02",
"type": "product.archived",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "prd_BAL003",
"replacement_id": "prd_STK005"
}
}price.changedราคาเปลี่ยน
ส่งเมื่อ: price หรือ dealer_price ของ SKU เปลี่ยน (ตัวแทนใช้ปรับราคาหน้าร้าน)
{
"id": "evt_01JB7Q03",
"type": "price.changed",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"sku": "LK-KIT-021",
"price": {
"from": 199000,
"to": 189000
},
"dealer_price": {
"from": 139300,
"to": 132300
},
"effective_at": "2026-10-01T00:00:00+07:00"
}
}inventory.low_stockสต็อกต่ำกว่าจุดสั่งซื้อ
ส่งเมื่อ: available ≤ reorder_point
{
"id": "evt_01JB7Q04",
"type": "inventory.low_stock",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"sku": "LK-BTL-450-PK",
"available": 4,
"reorder_point": 10,
"warehouse_id": "wh_bkk1"
}
}inventory.out_of_stockของหมด
ส่งเมื่อ: available เป็น 0
{
"id": "evt_01JB7Q05",
"type": "inventory.out_of_stock",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"sku": "LK-BNY-045-CR",
"available": 0,
"incoming": [
{
"quantity": 24,
"eta": "2026-10-19"
}
]
}
}inventory.restockedของกลับมามี
ส่งเมื่อ: available จาก 0 เป็นมากกว่า 0 (ระบบใช้ส่งแจ้งเตือนรายการโปรด)
{
"id": "evt_01JB7Q06",
"type": "inventory.restocked",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"sku": "LK-BNY-045-CR",
"available": 24,
"adjustment_id": "iadj_9Qw1"
}
}ส่งซ้ำเมื่อปลายทางไม่ตอบ
- 1ทันที
- 21 นาที
- 35 นาที
- 430 นาที
- 52 ชั่วโมง
- 66 ชั่วโมง
- 724 ชั่วโมง (ครั้งสุดท้าย)
ครบทุกครั้งแล้วยังล้มเหลว → ปิด endpoint อัตโนมัติและส่งอีเมลแจ้งผู้ดูแล · ดูประวัติการส่งและกดส่งซ้ำได้ในแดชบอร์ด
ตรวจลายเซ็น
# ลายเซ็นอยู่ในหัว LekLek-Signature: t=<unix>,v1=<hex>
# คำนวณ HMAC-SHA256(secret, "<t>.<raw body>") แล้วเทียบกับ v1
printf '%s' "$T.$BODY" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET"import crypto from 'node:crypto';
// ใช้ raw body (ยังไม่ parse JSON) เท่านั้น
export function verify(rawBody, sigHeader, secret) {
const parts = Object.fromEntries(sigHeader.split(',').map((p) => p.split('=')));
const age = Math.abs(Date.now() / 1000 - Number(parts.t));
if (age > 300) return false; // เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
const expected = crypto.createHmac('sha256', secret).update(parts.t + '.' + rawBody).digest('hex');
return crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}import hmac, hashlib, time
def verify(raw_body: bytes, sig_header: str, secret: str) -> bool:
parts = dict(p.split("=", 1) for p in sig_header.split(","))
if abs(time.time() - int(parts["t"])) > 300:
return False # เก่ากว่า 5 นาที = ปฏิเสธ (กัน replay)
msg = parts["t"].encode() + b"." + raw_body
expected = hmac.new(secret.encode(), msg, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts["v1"])Errors — รหัสข้อผิดพลาด
ทุก error ตอบกลับเป็น JSON รูปแบบเดียวกัน พร้อม request_id สำหรับแจ้งทีมสนับสนุน · รหัส HTTP บอกกลุ่มของปัญหา ส่วน error.code บอกสาเหตุที่แน่นอน (ใช้เขียนเงื่อนไขในโค้ดได้ เพราะไม่เปลี่ยนตามภาษา)
- 4xx คำขอไม่ถูกต้อง — แก้ที่ฝั่งผู้เรียก ส่งซ้ำแบบเดิมจะได้ผลเดิม
- 5xx ปัญหาฝั่งระบบ — ลองใหม่แบบเว้นระยะ (exponential backoff) พร้อม Idempotency-Key
{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"param": "items[0].quantity",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_request"
}
}| HTTP | code | ความหมาย | วิธีแก้ |
|---|---|---|---|
| 400 | invalid_request | คำขอไม่ถูกต้อง ฟิลด์ขาด ชนิดข้อมูลผิด หรือค่าที่ส่งมาขัดกันเอง — ดู error.param ว่าเป็นฟิลด์ไหน | ตรวจ body/query ตาม schema ของ endpoint · ใช้ตัวอย่างในหน้านี้เป็นแม่แบบ |
| 400 | invalid_json | JSON อ่านไม่ได้ body ไม่ใช่ JSON ที่ถูกต้อง หรือไม่ได้ส่งหัว Content-Type: application/json | ส่ง Content-Type: application/json และตรวจ JSON ด้วยตัว parse ก่อนส่ง |
| 401 | authentication_required | ไม่ได้ส่งข้อมูลยืนยันตัวตน ไม่มีหัว Authorization หรือรูปแบบไม่ใช่ Bearer | ส่ง Authorization: Bearer <API key หรือ access token> |
| 403 | insufficient_scope | สิทธิ์ไม่พอ key/token นี้ไม่มี scope ที่ endpoint ต้องการ (ดูช่อง "สิทธิ์" ของแต่ละ endpoint) | เพิ่ม scope ให้ key ในแดชบอร์ด หรือขอ token ใหม่พร้อม scope ที่ต้องการ |
| 404 | resource_not_found | ไม่พบข้อมูล id ไม่มีอยู่ ถูกลบ หรือเป็นของบัญชี/ตัวแทนอื่น | ตรวจ id และสภาพแวดล้อม (sandbox กับ production เป็นข้อมูลคนละชุด) |
| 409 | idempotency_conflict | Idempotency-Key ซ้ำแต่ body ต่าง เคยใช้ Idempotency-Key นี้กับ body อื่นภายใน 24 ชม. | สร้าง key ใหม่ (UUID v4) ทุกการกระทำใหม่ · ใช้ key เดิมเฉพาะตอนส่งซ้ำของเดิม |
| 422 | validation_failed | ข้อมูลไม่ผ่านการตรวจ รูปแบบถูกแต่ค่าผิดกติกาทางธุรกิจ (เช่น จำนวนติดลบ ช่วงวันที่กลับด้าน) — มี error.details[] ทีละฟิลด์ | แสดง details[].message ใต้ช่องที่เกี่ยวข้อง แล้วให้ผู้ใช้แก้ |
| 404 | product_not_found | ไม่พบสินค้า product id หรือ slug ไม่มีอยู่ | ค้นด้วย GET /v2/products?q= แทนการเดา id |
| 409 | sku_already_exists | SKU ซ้ำ มี variant อื่นใช้ SKU นี้แล้ว (SKU ไม่ซ้ำทั้งร้าน) | ใช้ SKU ใหม่ หรือแก้ variant เดิมด้วย PATCH |
| 409 | product_archived | สินค้าเลิกจำหน่ายแล้ว สินค้าถูก archive — ยังเรียกดูได้แต่เพิ่มลงตะกร้า/แก้ราคาไม่ได้ | แนะนำสินค้าทดแทน (ฟิลด์ replacement_id) หรือกู้คืนด้วย PATCH status=active |
| 422 | invalid_age_range | ช่วงอายุไม่ถูกต้อง age_min_months มากกว่า age_max_months หรือเกิน 144 เดือน | ส่งเป็นเดือน 0–144 · ไม่มีขั้นบนให้ส่ง null |
| 413 | image_too_large | ไฟล์รูปใหญ่เกิน รูปเกิน 8 MB หรือด้านยาวเกิน 6000 px | ย่อรูปเป็นด้านยาว ≤ 3000 px คุณภาพ 85 ก่อนอัปโหลด |
| 415 | unsupported_media_type | ชนิดไฟล์ไม่รองรับ รับเฉพาะ image/jpeg image/png image/webp | แปลงไฟล์เป็น webp หรือ jpeg |
| 422 | batch_too_large | batch ใหญ่เกิน ส่งรายการเกินจำนวนสูงสุดต่อคำขอ (สินค้า 500 · คูปอง 10,000) | แบ่งเป็นหลาย batch แล้วส่งทีละชุด (ใช้ Idempotency-Key ต่อชุด) |
| 429 | rate_limited | เรียกเกินโควตา จำนวนคำขอเกินโควตาของ key ในช่วงเวลา (ดูหัว RateLimit-*) | รอตาม Retry-After แล้วลองใหม่แบบเว้นระยะเพิ่มขึ้น + jitter · รวมคำขอด้วย endpoint แบบ batch |
| 503 | service_unavailable | ปิดปรับปรุงชั่วคราว บริการย่อยบางตัวไม่พร้อม (เช่น ระหว่างย้ายฐานข้อมูล) — ดูหน้า status | ลองใหม่หลัง Retry-After · คำสั่งซื้อที่ส่งด้วย Idempotency-Key จะไม่ซ้ำ |
ไม่พบรหัสที่ค้นหา
Rate limit — โควตาการเรียก
| ขอบเขต | โควตา | Burst | หมายเหตุ |
|---|---|---|---|
| อ่านสินค้า/ค้นหา (ต่อ key) | 600 ครั้ง/นาที | 100 | แคช 60 วินาที · ใช้ ETag ลดการโหลดซ้ำ |
| คำแนะนำขณะพิมพ์ | 1,200 ครั้ง/นาที | 200 | debounce 200 ms ฝั่งแอป |
| เขียนสินค้า (ต่อ key) | 60–120 ครั้ง/นาที | — | หลังบ้าน |
| นำเข้า batch | 10 คำขอ/นาที · 500 รายการ/คำขอ | — | เกิน 100 รายการแนะนำ async=true |
| ตัวแทน (ต่อ key) | 300 ครั้ง/นาที | 50 | ใช้ webhook แทนการดึงทั้งแคตตาล็อกถี่ ๆ |
RateLimit-Limitโควตาของช่วงเวลาRateLimit-Remainingครั้งที่เหลือRateLimit-Resetวินาทีจนโควตาเริ่มใหม่- เกินโควตา → 429 พร้อม
Retry-After· แนะนำลองใหม่แบบเว้นระยะเพิ่มขึ้น + สุ่มเล็กน้อย (jitter)
HTTP/1.1 429 Too Many Requests
RateLimit-Limit: 100
RateLimit-Remaining: 0
RateLimit-Reset: 23
Retry-After: 23
{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา ลองใหม่ใน 23 วินาที",
"request_id": "req_2Kd9QwZ1"
}
}เวอร์ชันและ Changelog
เลือกเวอร์ชันด้วยหัว LekLek-Version (ไม่ส่ง = เวอร์ชันที่ผูกกับ API key) · การเปลี่ยนที่ไม่ทำให้โค้ดเดิมพัง (เพิ่มฟิลด์/endpoint) ออกในเวอร์ชันเดิมได้ · การเปลี่ยนที่ทำให้พังออกเป็นเวอร์ชันใหม่เสมอ และแจ้งล่วงหน้าอย่างน้อย 6 เดือนก่อนปิดเวอร์ชันเก่า
| เวอร์ชัน | สถานะ | รองรับถึง |
|---|---|---|
2026-08-01 ล่าสุด | ปัจจุบัน | — |
2025-11-15 | ยังรองรับ | 30 ก.ย. 2570 |
2024-06-01 | เลิกใช้แล้ว | 31 ธ.ค. 2569 |
- เพิ่ม
2026-08-01เพิ่ม GET /v2/products/suggest (Beta) คำแนะนำขณะพิมพ์
- เพิ่ม
2026-08-01ผลค้นหามี facets (จำนวนต่อหมวด) สำหรับสร้างตัวกรอง
- เปลี่ยน
2026-08-01กรองหมวดแม่รวมหมวดย่อยอัตโนมัติ (เดิมต้องส่งทุกหมวด)
- แก้ไข
2025-11-15sold_30d ไม่นับคำสั่งซื้อที่ยกเลิก
- ความปลอดภัย
2025-11-15dealer_price คืน null สำหรับ key ที่ไม่มี products:read_dealer (เดิมซ่อนทั้งฟิลด์ ทำให้ตัวแทนแยกไม่ออก)
- เพิ่ม
2025-11-15เพิ่ม POST /v2/products/batch (207 Multi-Status) และ /v2/inventory/adjustments
- เปลี่ยน
2025-11-15อายุแนะนำเปลี่ยนจากปี (age_years) เป็นเดือน (age_min_months/age_max_months)
- เลิกใช้
2025-11-15age_years เลิกใช้ — เวอร์ชัน 2024-06-01 ยังได้ค่าเดิม (ปัดลง)
- เพิ่ม
2024-06-01เพิ่ม safety (มาตรฐานความปลอดภัยของเล่น + คำเตือนชิ้นส่วนเล็ก)
- แก้ไข
2024-06-01รูปที่อัปโหลดเป็น png โปร่งใสได้พื้นดำเมื่อแปลง webp
เครื่องมือ: ตัวสร้าง query ค้นหาสินค้า
เลือกตัวกรอง (คำค้น หมวด อายุลูก ช่วงราคา มีของ การเรียง) → เห็น URL ที่ต้องเรียก ผลลัพธ์จากข้อมูลตัวอย่างจริง การ์ดสินค้าพร้อมรูป และ JSON response
เครื่องมือนี้คำนวณในเบราว์เซอร์ด้วยกฎและข้อมูลชุดเดียวกับตัวอย่างในหน้า — ไม่ได้เรียก API จริง (แบรนด์สมมติ)
…