สารบัญหน้านี้ (25)
- ภาพรวม
- การยืนยันตัวตนและ scope
- Workflow (2)
- ตั้งแคมเปญ 11.11 ล่วงหน้า: สร้าง → จำลอง → แจกโค้ด → เปิดเองตามเวลา
- ลูกค้าใส่ 2 คูปอง: ระบบคิดตามลำดับและบอกเหตุผลที่ไม่ผ่าน
- Objects (3)
- The Promotion object
- The Coupon object
- The Simulation object
- Endpoints (10)
- GETรายการโปรโมชัน
- POSTสร้างโปรโมชัน
- GETดูโปรโมชัน
- PATCHแก้โปรโมชัน
- POSTเปิดใช้โปรโมชัน
- POSTปิดโปรโมชัน
- POSTสร้างโค้ดคูปองหลายใบ
- GETตรวจโค้ดคูปอง
- POSTจำลองการคิดโปร
- GETประวัติการใช้สิทธิ์
- Webhooks (7)
- Errors (22)
- Rate limit
- เวอร์ชันและ Changelog
- เครื่องมือ: ตัวจำลองกฎโปรโมชัน
- LEKLEK Toys
- Docs
- E-Commerce API
- Promotion
LEKLEK Commerce API · โมดูล Promotion
Promotion API
โปรโมชันของ LEKLEK — คูปองส่วนลด %/บาท พร้อมขั้นต่ำ สิทธิ์ต่อคน ช่วงเวลา และหมวดที่ร่วม · โปรอัตโนมัติ (ซื้อ 2 แถม 1 · ส่งฟรีเมื่อครบ ฿1,500) · กติกาลำดับการคิดและการใช้ร่วมกัน · โปรเฉพาะตัวแทน · จำลองผลก่อนเปิดจริง
- 10 endpoints
- 2 workflow
- 3 object
- 7 webhook event
- 22 รหัส error
- เวอร์ชัน
2026-08-01

ภาพรวมโมดูล Promotion
ใช้เมื่อไร
- ทีมการตลาดสร้าง/ตั้งเวลา/ปิดแคมเปญ
- แอปแสดง "คูปองที่ใช้ได้" และแนะนำใบที่คุ้มที่สุด
- แจกโค้ดเฉพาะบุคคลจำนวนมาก
- ตัวแทนจำหน่ายได้ส่วนลดตามยอดสั่ง
Base path
/v2/promotions/v2/promotions/simulate/v2/coupons/{code}/v2/coupons/batch
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/promotions/promo_KIDS10
Authorization: Bearer lk_test_51HcQ2xT8bWm4
LekLek-Version: 2026-08-01
Accept: application/json
Accept-Language: thScope ของโมดูลนี้
| scope | อนุญาตให้ | ใช้โดย | endpoint ที่ต้องใช้ |
|---|---|---|---|
promotions:read | ดูโปร จำลองผล ดูประวัติการใช้ | หลังบ้าน · แอป/เว็บ (เฉพาะ applicable_to และ simulate) | GETรายการโปรโมชันGETดูโปรโมชันPOSTจำลองการคิดโปรGETประวัติการใช้สิทธิ์ |
promotions:write | สร้าง แก้ เปิด/ปิดโปร สร้างโค้ดหลายใบ | ทีมการตลาด (secret key) | POSTสร้างโปรโมชันPATCHแก้โปรโมชันPOSTเปิดใช้โปรโมชันPOSTปิดโปรโมชันPOSTสร้างโค้ดคูปองหลายใบ |
coupons:read | ตรวจโค้ดคูปอง | แอป/เว็บ (publishable key) | GETตรวจโค้ดคูปอง |
Object หลัก
Promotionโปรโมชัน 1 รายการ — ตัวอย่างคือ KIDS10 ที่คุณพิมพ์ชนกใช้ในคำสั่งซื้อ ord_2610_004718 ฟิลด์ระดับบน · 15 ฟิลด์ย่อยCouponโค้ดคูปอง 1 ใบ (โค้ดหลักของโปร หรือโค้ดเฉพาะบุคคลจาก batch)16 ฟิลด์ระดับบน · 0 ฟิลด์ย่อยSimulationผลการคิดโปรทีละขั้น (จาก POST /simulate) — ใช้ตัวคิดเดียวกับตะกร้าและคำสั่งซื้อ7 ฟิลด์ระดับบน · 13 ฟิลด์ย่อย
ความสัมพันธ์กับโมดูลอื่น
- Promotionหน้านี้
- Cartใส่คูปองในตะกร้าใช้ตัวคิดเดียวกัน (ผลตรงกับ simulate)
- Orderส่วนลดล็อกตอนเช็กเอาต์ · ยกเลิกคำสั่งซื้อคืนสิทธิ์คูปอง
- Paymentนับสิทธิ์ (used_count) เมื่อชำระสำเร็จเท่านั้น
- Productเลือกสินค้าที่ร่วมด้วยหมวด (categories) หรือต้นรหัส SKU
- Userแจกโค้ดเฉพาะลูกค้าที่ยินยอมรับข่าว (PDPA)
ข้อควรรู้
-
ลำดับการคิด
item (ซื้อ X แถม Y) → order (โปรอัตโนมัติ แล้วคูปองตามลำดับที่ใส่) → shipping (ส่งฟรี) · ขั้นหลังคิดจากยอดหลังขั้นก่อน
-
ใช้ร่วมกัน
1 คำสั่งซื้อ 1 คูปอง ยกเว้นทุกใบ stackable=true · โปรอัตโนมัติใช้ร่วมกับคูปองได้เสมอ
-
โปรตัวแทน
ตัวแทนใช้ราคาตัวแทน — คูปองผู้บริโภคใช้ไม่ได้ · มีโปรเฉพาะตัวแทน (สั่งครบ ฿20,000 ลดเพิ่ม 3%) เช่น ร้านของเล่นบ้านหนูน้อย (ตัวแทน — สมมติ) ได้ ฿919.80
-
แก้ส่วนลดหลังมีคนใช้ไม่ได้
ป้องกันข้อพิพาท — ปิดโปรเดิมแล้วสร้างใหม่ · ขยายวันสิ้นสุด/สิทธิ์รวมได้
-
สตางค์ + ปัดเศษ
percent ปัดเป็นสตางค์ใกล้สุด แล้วจำกัดด้วย max · fixed ไม่เกินยอดที่ร่วม · ส่วนลดรวมไม่ทำให้ยอดติดลบ
-
เวลา ISO 8601 +07:00
starts_at/ends_at เป็นเวลาไทย · simulate ส่ง at เพื่อทดสอบโปรที่ตั้งเวลาไว้
Workflow — ขั้นตอนการเรียกใช้จริง (2 เรื่อง)
แต่ละเรื่องดูได้ 2 แบบ: ภาพรวม อธิบายภาษาคนทั่วไปทีละขั้น และ Sequence กดเล่นทีละขั้น (หรือคลิกลูกศร) เพื่อดูคำขอ/ผลลัพธ์ HTTP จริงของขั้นนั้น · ลูกศรประ = ส่งแบบไม่รอผล (webhook/คิว)
ตั้งแคมเปญ 11.11 ล่วงหน้า: สร้าง → จำลอง → แจกโค้ด → เปิดเองตามเวลา
ทีมการตลาดสร้าง LEK1111 วันที่ 12 ต.ค. พิมพ์วันที่สิ้นสุดผิดหนึ่งครั้ง จำลองกับตะกร้าตัวอย่าง แล้วสร้างโค้ดเฉพาะบุคคล 1,111 ใบ ระบบเปิดโปรเองเวลา 00:00 ของวันที่ 11 พ.ย.
- แอดมินร้านหลังบ้าน LEKLEK
- Commerce APIapi.leklek.example
- Promotion engineคิดส่วนลด
- ฐานข้อมูลPostgreSQL
- Event busคิว + webhook
- ระบบ CRM/อีเมลภายใน
- 1
แอดมินร้าน → Commerce API
สร้าง LEK1111 แต่พิมพ์ ends_at เป็นวันที่ 10 พ.ย. (ก่อนวันเริ่ม)
POST /v2/promotions - 2
Commerce API → แอดมินร้าน
ปฏิเสธพร้อมบอกช่องที่ผิด
- 3
แอดมินร้าน → Commerce API
ส่งใหม่ด้วย ends_at 12 พ.ย. 23:59
POST /v2/promotions - 4
แอดมินร้าน → Commerce API
จำลองกับตะกร้าของคุณพิมพ์ชนก ณ วันที่ 11 พ.ย.
POST /v2/promotions/simulate - 5
Commerce API → Promotion engine
ยอด ฿2,360 ถึงขั้นต่ำ ฿1,111 → ลด 11% = ฿259.60
- 6
Commerce API → แอดมินร้าน
ยอดสุทธิ ฿2,100.40 ส่งฟรี
- 7
แอดมินร้าน → Commerce API
สร้างโค้ดเฉพาะบุคคล 1,111 ใบ
POST /v2/coupons/batch - 8
Commerce API → ฐานข้อมูล
สุ่มโค้ดโดยตัดตัวอักษรที่สับสนออก ตรวจไม่ซ้ำทั้งระบบ
ไม่รอผล (async) - 9
Commerce API → Event bus
แจ้งทีม CRM ให้ดาวน์โหลด CSV ไปแจกเฉพาะลูกค้าที่ยินยอมรับข่าว
ไม่รอผล (async) - 10
Commerce API → Commerce API
scheduled → active ตามเวลา
- 11
Commerce API → Event bus
แอปและตัวแทนรับ webhook เพื่อแสดงแบนเนอร์
ไม่รอผล (async) - 12
Event bus → ระบบ CRM/อีเมล
ส่งโค้ดทางอีเมล/LINE ตามความยินยอมของแต่ละคน
ไม่รอผล (async)
ตั้งแคมเปญเสร็จใน 5 คำขอ · จำลองแล้วรู้ยอดก่อนเปิดจริง (ตะกร้าตัวอย่าง ฿2,100.40) · โค้ด 1,111 ใบพร้อมแจก · เปิดตรงเวลาโดยไม่ต้องมีคนเฝ้า
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 แอดมินร้าน Commerce API
POST /v2/promotions
สร้าง LEK1111 แต่พิมพ์ ends_at เป็นวันที่ 10 พ.ย. (ก่อนวันเริ่ม)
POST /v2/promotions HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
{
"name": "LEK1111 ลด 11% วัน 11.11",
"type": "coupon",
"code": "LEK1111",
"description": "ตั้งเวลาไว้ล่วงหน้า",
"discount": {
"kind": "percent",
"value": 11,
"max": 111100
},
"stage": "order",
"conditions": {
"min_subtotal": 111100,
"customer_types": [
"guest",
"member"
],
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 1111
},
"starts_at": "2026-11-11T00:00:00+07:00",
"ends_at": "2026-11-10T23:59:59+07:00",
"priority": 30,
"stackable": false,
"metadata": {
"campaign": "1111-2026"
}
}2 Commerce API แอดมินร้าน
422 promotion_window_invalid
ปฏิเสธพร้อมบอกช่องที่ผิด
จัดการผิดพลาด: หลังบ้านไฮไลต์ช่องวันที่สิ้นสุด — ไม่สร้างโปรครึ่ง ๆ กลาง ๆ
HTTP/1.1 422 Unprocessable Entity
{
"error": {
"code": "promotion_window_invalid",
"param": "ends_at"
}
}3 แอดมินร้าน Commerce API
POST /v2/promotions (แก้แล้ว)
ส่งใหม่ด้วย ends_at 12 พ.ย. 23:59
POST /v2/promotions HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
Idempotency-Key: 41b2…
{
"name": "LEK1111 ลด 11% วัน 11.11",
"type": "coupon",
"code": "LEK1111",
"description": "ตั้งเวลาไว้ล่วงหน้า",
"discount": {
"kind": "percent",
"value": 11,
"max": 111100
},
"stage": "order",
"conditions": {
"min_subtotal": 111100,
"customer_types": [
"guest",
"member"
],
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 1111
},
"starts_at": "2026-11-11T00:00:00+07:00",
"ends_at": "2026-11-12T23:59:59+07:00",
"priority": 30,
"stackable": false,
"metadata": {
"campaign": "1111-2026"
}
}HTTP/1.1 201 Created
{
"id": "promo_LEK1111",
"status": "scheduled"
}4 แอดมินร้าน Commerce API
POST /v2/promotions/simulate
จำลองกับตะกร้าของคุณพิมพ์ชนก ณ วันที่ 11 พ.ย.
POST /v2/promotions/simulate HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
{
"cart_id": "cart_7Hq2",
"coupons": [
"LEK1111"
],
"at": "2026-11-11T09:00:00+07:00",
"promotion_ids": [
"promo_LEK1111"
]
}5 Commerce API Promotion engine
evaluate ณ 11 พ.ย.
ยอด ฿2,360 ถึงขั้นต่ำ ฿1,111 → ลด 11% = ฿259.60
6 Commerce API แอดมินร้าน
200 simulation
ยอดสุทธิ ฿2,100.40 ส่งฟรี
HTTP/1.1 200 OK
{
"applied": [
"LEK1111",
"promo_FREESHIP"
],
"amounts": {
"subtotal": 236000,
"item_discount": 0,
"order_discount": 25960,
"shipping_fee": 5000,
"shipping_discount": 5000,
"total": 210040,
"vat_included": 13741
}
}7 แอดมินร้าน Commerce API
POST /v2/coupons/batch
สร้างโค้ดเฉพาะบุคคล 1,111 ใบ
POST /v2/coupons/batch HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
{
"promotion_id": "promo_LEK1111",
"count": 1111,
"prefix": "LEK1111-"
}HTTP/1.1 202 Accepted
{
"id": "cbat_1111A",
"status": "processing"
}8 Commerce API ฐานข้อมูลasync
สร้างโค้ดไม่ซ้ำ
สุ่มโค้ดโดยตัดตัวอักษรที่สับสนออก ตรวจไม่ซ้ำทั้งระบบ
9 Commerce API Event busasync
coupon_batch.completed
แจ้งทีม CRM ให้ดาวน์โหลด CSV ไปแจกเฉพาะลูกค้าที่ยินยอมรับข่าว
10 Commerce API Commerce API
11 พ.ย. 00:00 เปิดอัตโนมัติ
scheduled → active ตามเวลา
11 Commerce API Event busasync
promotion.activated
แอปและตัวแทนรับ webhook เพื่อแสดงแบนเนอร์
12 Event bus ระบบ CRM/อีเมลasync
ส่งโค้ด
ส่งโค้ดทางอีเมล/LINE ตามความยินยอมของแต่ละคน
ตั้งแคมเปญเสร็จใน 5 คำขอ · จำลองแล้วรู้ยอดก่อนเปิดจริง (ตะกร้าตัวอย่าง ฿2,100.40) · โค้ด 1,111 ใบพร้อมแจก · เปิดตรงเวลาโดยไม่ต้องมีคนเฝ้า
ลูกค้าใส่ 2 คูปอง: ระบบคิดตามลำดับและบอกเหตุผลที่ไม่ผ่าน
คุณพิมพ์ชนกมี KIDS10 และ WOOD50 ใส่ทั้งคู่ในตะกร้าเดียว — ระบบคิดโปรอัตโนมัติก่อน แล้วคูปองตามลำดับ ใบที่สองใช้ร่วมไม่ได้ จึงได้ warning พร้อมคำแนะนำ
- คุณพิมพ์ชนกลูกค้า cus_P3k9
- แอป LEKLEKiOS / Android
- Commerce APIapi.leklek.example
- Promotion engineคิดส่วนลด
- ฐานข้อมูลPostgreSQL
- Event busคิว + webhook
- 1
คุณพิมพ์ชนก → แอป LEKLEK
ลูกค้าคิดว่าใช้ได้ทั้ง 2 ใบ
- 2
แอป LEKLEK → Commerce API
แอปขอจำลองก่อนใส่จริง (เพื่อแนะนำใบที่คุ้มกว่า)
POST /v2/promotions/simulate - 3
Commerce API → ฐานข้อมูล
ดึงโปรที่ active และประวัติคูปองของ cus_P3k9 (WOOD50 ใช้ไป 1/3)
- 4
Commerce API → Promotion engine
ซื้อ 2 แถม 1 กระติก: มี 2 ใบ ยังไม่ครบ 3 → ไม่ได้ (เก็บเป็น hint)
- 5
Commerce API → Promotion engine
KIDS10: ยอด ฿2,360 ≥ ฿1,000 → ลด ฿236 · WOOD50: ใช้ร่วมกับ KIDS10 ไม่ได้
- 6
Commerce API → Promotion engine
ยอดหลังลด ฿2,124 ≥ ฿1,500 → ส่งฟรี
- 7
Commerce API → แอป LEKLEK
คืนผลทีละโปร พร้อม warnings
- 8
แอป LEKLEK → คุณพิมพ์ชนก
แอปบอกว่า KIDS10 คุ้มกว่า และ WOOD50 เก็บไว้ใช้ครั้งหน้าได้
- 9
แอป LEKLEK → Commerce API
ใส่ KIDS10 ลงตะกร้าจริง
POST /v2/carts/cart_7Hq2/coupons - 10
Commerce API → Event bus
แจ้งระบบวิเคราะห์ว่าใช้คูปองอะไร (ไม่รอผล)
ไม่รอผล (async)
ลูกค้าเห็นทันทีว่า KIDS10 ลด ฿236 คุ้มกว่า WOOD50 (฿50) · ไม่มีคำสั่งซื้อที่ได้ส่วนลดซ้อนผิดกติกา · ตอบภายใน ~60 ms
กด เล่น หรือคลิกลูกศรในแผนภาพ เพื่อดูคำขอและผลลัพธ์ของแต่ละขั้น
1 คุณพิมพ์ชนก แอป LEKLEK
ใส่ KIDS10 แล้วใส่ WOOD50
ลูกค้าคิดว่าใช้ได้ทั้ง 2 ใบ
2 แอป LEKLEK Commerce API
POST /v2/promotions/simulate
แอปขอจำลองก่อนใส่จริง (เพื่อแนะนำใบที่คุ้มกว่า)
POST /v2/promotions/simulate HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
{
"cart_id": "cart_7Hq2",
"coupons": [
"KIDS10",
"WOOD50"
],
"customer_id": "cus_P3k9",
"postal_code": "10900"
}3 Commerce API ฐานข้อมูล
โหลดโปร + สิทธิ์ที่ใช้แล้ว
ดึงโปรที่ active และประวัติคูปองของ cus_P3k9 (WOOD50 ใช้ไป 1/3)
4 Commerce API Promotion engine
stage item
ซื้อ 2 แถม 1 กระติก: มี 2 ใบ ยังไม่ครบ 3 → ไม่ได้ (เก็บเป็น hint)
5 Commerce API Promotion engine
stage order
KIDS10: ยอด ฿2,360 ≥ ฿1,000 → ลด ฿236 · WOOD50: ใช้ร่วมกับ KIDS10 ไม่ได้
6 Commerce API Promotion engine
stage shipping
ยอดหลังลด ฿2,124 ≥ ฿1,500 → ส่งฟรี
7 Commerce API แอป LEKLEK
200 simulation
คืนผลทีละโปร พร้อม warnings
HTTP/1.1 200 OK
{
"applied": [
"KIDS10",
"promo_FREESHIP"
],
"warnings": [
{
"code": "coupon_not_combinable",
"message": "WOOD50: ใช้ร่วมกับ KIDS10 ไม่ได้ (1 คำสั่งซื้อ 1 คูปอง)",
"param": "coupons"
}
],
"hints": [
"เพิ่มกระติกน้ำเด็กหลอดดูด 450 มล.อีก 1 ชิ้น รับฟรี 1 ชิ้น (กระติกน้ำ ซื้อ 2 แถม 1)"
],
"amounts": {
"total": 212400
}
}8 แอป LEKLEK คุณพิมพ์ชนก
แสดง "ใช้ได้ 1 ใบ"
แอปบอกว่า KIDS10 คุ้มกว่า และ WOOD50 เก็บไว้ใช้ครั้งหน้าได้
9 แอป LEKLEK Commerce API
POST /v2/carts/…/coupons
ใส่ KIDS10 ลงตะกร้าจริง
POST /v2/carts/cart_7Hq2/coupons HTTP/1.1
Authorization: Bearer lk_test_51HcQ2xT8bWm4
{
"code": "KIDS10"
}HTTP/1.1 200 OK
{
"coupons": [
"KIDS10"
],
"amounts": {
"total": 212400
}
}10 Commerce API Event busasync
cart.updated
แจ้งระบบวิเคราะห์ว่าใช้คูปองอะไร (ไม่รอผล)
ลูกค้าเห็นทันทีว่า KIDS10 ลด ฿236 คุ้มกว่า WOOD50 (฿50) · ไม่มีคำสั่งซื้อที่ได้ส่วนลดซ้อนผิดกติกา · ตอบภายใน ~60 ms
Objects
โครงข้อมูลที่ endpoint ในหน้านี้รับ-ส่ง · ฟิลด์ อ่านอย่างเดียว ระบบสร้างให้ (ส่งมาจะถูกละเว้น) · เงินเป็นสตางค์ · เวลาเป็น ISO 8601 +07:00
The Promotion object
โปรโมชัน 1 รายการ — ตัวอย่างคือ KIDS10 ที่คุณพิมพ์ชนกใช้ในคำสั่งซื้อ ord_2610_0047
idstringไม่บังคับอ่านอย่างเดียวรหัสโปรโมชัน ขึ้นต้น promo_
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
namestringจำเป็นชื่อที่ลูกค้าเห็น
typeenumจำเป็นcoupon = ต้องกรอกโค้ด · automatic = คิดให้เองเมื่อเข้าเงื่อนไข
codestringไม่บังคับโค้ดคูปอง (A-Z 0-9 4–32 ตัว ไม่สนตัวพิมพ์) — null สำหรับ automatic
descriptionstringไม่บังคับเงื่อนไขแบบย่อสำหรับแสดง
discountobjectจำเป็นรูปแบบส่วนลด
ฟิลด์ย่อยของ
discount(5)kindenumจำเป็นpercent · fixed (สตางค์) · free_shipping · buy_x_get_y
valueintegerไม่บังคับpercent = 1–100 · fixed = สตางค์
maxintegerไม่บังคับส่วนลดสูงสุด (สตางค์) สำหรับ percent
buyintegerไม่บังคับbuy_x_get_y: จำนวนที่ต้องซื้อ
getintegerไม่บังคับbuy_x_get_y: จำนวนที่ได้ฟรี (ชิ้นราคาต่ำสุด)
stageenumจำเป็นลำดับการคิด: item (ระดับสินค้า) → order (ทั้งคำสั่งซื้อ) → shipping (ค่าส่ง)
conditionsobjectไม่บังคับเงื่อนไข
ฟิลด์ย่อยของ
conditions(6)min_subtotalintegerไม่บังคับยอดขั้นต่ำ (สตางค์) — คิดหลังส่วนลดขั้นก่อนหน้า · ถ้ามี categories คิดเฉพาะสินค้าที่ร่วม
categoriesarray<string>ไม่บังคับหมวดที่ร่วม (null = ทุกหมวด)
sku_prefixstringไม่บังคับเลือกสินค้าด้วยต้นรหัส SKU เช่น LK-BTL-
customer_typesarray<string>ไม่บังคับguest member dealer
first_order_onlybooleanไม่บังคับเฉพาะคำสั่งซื้อแรกของบัญชี
channelsarray<string>ไม่บังคับweb app dealer_api
limitsobjectไม่บังคับการจำกัดสิทธิ์
ฟิลด์ย่อยของ
limits(4)per_customerintegerไม่บังคับครั้งต่อบัญชี (null = ไม่จำกัด)
usage_limitintegerไม่บังคับสิทธิ์รวมทั้งหมด
used_countintegerไม่บังคับอ่านอย่างเดียวใช้ไปแล้ว (นับเมื่อชำระสำเร็จ)
remainingintegerไม่บังคับอ่านอย่างเดียวคงเหลือ
starts_atstring · date-timeจำเป็นเริ่ม (ISO 8601 +07:00)
ends_atstring · date-timeจำเป็นสิ้นสุด (ไม่เกิน 366 วันจากเริ่ม)
priorityintegerไม่บังคับลำดับภายใน stage เดียวกัน (น้อยคิดก่อน)
stackablebooleanไม่บังคับใช้ร่วมกับคูปองอื่นได้ (ต้อง true ทุกใบที่ใช้ร่วม) — โปรอัตโนมัติใช้ร่วมกับคูปองได้เสมอ
statusenumไม่บังคับอ่านอย่างเดียวscheduled (รอเวลาเริ่ม) · active · inactive (ปิดเอง) · expired
createdstring · date-timeไม่บังคับอ่านอย่างเดียวสร้างเมื่อ
updatedstring · date-timeไม่บังคับอ่านอย่างเดียวแก้ล่าสุด
metadataobjectไม่บังคับข้อมูลของคุณเอง (เช่น รหัสแคมเปญ)
{
"id": "promo_KIDS10",
"object": "promotion",
"name": "KIDS10 ลด 10% เมื่อครบ ฿1,000",
"type": "coupon",
"code": "KIDS10",
"description": "ลดสูงสุด ฿500 · ใช้ได้ 1 ครั้งต่อบัญชี",
"discount": {
"kind": "percent",
"value": 10,
"max": 50000
},
"stage": "order",
"conditions": {
"min_subtotal": 100000,
"categories": null,
"sku_prefix": null,
"customer_types": [
"guest",
"member"
],
"first_order_only": false,
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 5000,
"used_count": 1873,
"remaining": 3127
},
"starts_at": "2026-10-01T00:00:00+07:00",
"ends_at": "2026-10-31T23:59:59+07:00",
"priority": 30,
"stackable": false,
"status": "active",
"created": "2026-09-25T14:00:00+07:00",
"updated": "2026-10-01T00:00:00+07:00",
"metadata": {}
}
The Coupon object
โค้ดคูปอง 1 ใบ (โค้ดหลักของโปร หรือโค้ดเฉพาะบุคคลจาก batch)
codestringไม่บังคับอ่านอย่างเดียวโค้ด
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
promotion_idstringไม่บังคับอ่านอย่างเดียวโปรที่โค้ดนี้สังกัด
batch_idstringไม่บังคับอ่านอย่างเดียวชุดที่สร้าง (null = โค้ดหลักของโปร)
statusenumไม่บังคับอ่านอย่างเดียวavailable · redeemed · expired · disabled
assigned_tostringไม่บังคับลูกค้าที่ได้รับโค้ด (null = ใครก็ใช้ได้)
redeemed_atstring · date-timeไม่บังคับอ่านอย่างเดียวใช้เมื่อ
order_idstringไม่บังคับอ่านอย่างเดียวคำสั่งซื้อที่ใช้
validbooleanไม่บังคับอ่านอย่างเดียวใช้ได้ ณ ตอนนี้หรือไม่
invalid_reasonstringไม่บังคับอ่านอย่างเดียวเหตุผลถ้าใช้ไม่ได้
conditionsobjectไม่บังคับอ่านอย่างเดียวเงื่อนไขสรุป (สำหรับแสดงในหน้าคูปอง)
max_redemptionsintegerไม่บังคับอ่านอย่างเดียวใช้ได้กี่ครั้งต่อโค้ด (โค้ดเฉพาะบุคคล = 1 · โค้ดหลักของโปร = null ไม่จำกัดต่อโค้ด แต่จำกัดต่อคน)
times_redeemedintegerไม่บังคับอ่านอย่างเดียวใช้ไปแล้วกี่ครั้ง (นับเมื่อชำระสำเร็จ)
starts_atstring · date-timeไม่บังคับอ่านอย่างเดียวเริ่มใช้ได้ (ตามโปร)
expires_atstring · date-timeไม่บังคับอ่านอย่างเดียวหมดอายุ (ตามโปร หรือสั้นกว่าถ้ากำหนดตอนสร้าง batch)
createdstring · date-timeไม่บังคับอ่านอย่างเดียวสร้างเมื่อ (เวลาของ batch)
{
"code": "LEK1111-7QF4MZ",
"object": "coupon",
"promotion_id": "promo_LEK1111",
"batch_id": "cbat_1111A",
"status": "available",
"assigned_to": "cus_P3k9",
"redeemed_at": null,
"order_id": null,
"valid": false,
"invalid_reason": "ยังไม่เริ่ม (เริ่ม 2026-11-11)",
"conditions": {
"min_subtotal": 111100,
"discount": "11% สูงสุด ฿1,111"
},
"max_redemptions": 1,
"times_redeemed": 0,
"starts_at": "2026-11-11T00:00:00+07:00",
"expires_at": "2026-11-12T23:59:59+07:00",
"created": "2026-10-12T14:05:00+07:00"
}
The Simulation object
ผลการคิดโปรทีละขั้น (จาก POST /simulate) — ใช้ตัวคิดเดียวกับตะกร้าและคำสั่งซื้อ
objectstringไม่บังคับอ่านอย่างเดียวชนิด object
linesarray<object>ไม่บังคับรายการหลังคิดส่วนลดระดับสินค้า
ฟิลด์ย่อยของ
lines(6)skustringไม่บังคับSKU
quantityintegerไม่บังคับจำนวน
unit_priceintegerไม่บังคับราคาต่อชิ้น
subtotalintegerไม่บังคับก่อนลด
discountintegerไม่บังคับส่วนลดระดับสินค้า
totalintegerไม่บังคับหลังลด
evaluationarray<object>ไม่บังคับทุกโปรที่ถูกพิจารณาตามลำดับ พร้อมผลและเหตุผล
ฟิลด์ย่อยของ
evaluation(7)promotion_idstringไม่บังคับโปร
codestringไม่บังคับโค้ด
stageenumไม่บังคับขั้น
resultenumไม่บังคับผล
amountintegerไม่บังคับส่วนลดที่ได้
reason_codestringไม่บังคับรหัสเหตุผลเมื่อไม่ผ่าน
reasonstringไม่บังคับเหตุผลภาษาไทย
amountsobjectไม่บังคับยอดสรุป (สตางค์)
appliedarray<string>ไม่บังคับโปรที่ได้จริง
warningsarray<object>ไม่บังคับคูปองที่ไม่ผ่าน (โครงเดียวกับ Cart.warnings)
hintsarray<string>ไม่บังคับข้อความแนะนำ เช่น ซื้อเพิ่มอีกเท่าไร
{
"object": "promotion_simulation",
"currency": "THB",
"lines": [
{
"sku": "LK-TRN-003",
"quantity": 1,
"unit_price": 89000,
"subtotal": 89000,
"discount": 0,
"total": 89000
},
{
"sku": "LK-BTL-450-MT",
"quantity": 2,
"unit_price": 39000,
"subtotal": 78000,
"discount": 0,
"total": 78000
},
{
"sku": "LK-BNY-030-CR",
"quantity": 1,
"unit_price": 69000,
"subtotal": 69000,
"discount": 0,
"total": 69000
}
],
"evaluation": [
{
"promotion_id": "promo_B2G1BTL",
"code": null,
"stage": "item",
"result": "rejected",
"amount": 0,
"reason_code": "min_quantity_not_met",
"reason": "มีสินค้าร่วมรายการ 2 ชิ้น ต้องครบ 3 ชิ้น"
},
{
"promotion_id": "promo_DLRQ4",
"code": null,
"stage": "order",
"result": "rejected",
"amount": 0,
"reason_code": "not_eligible_customer",
"reason": "เฉพาะตัวแทนจำหน่าย"
},
{
"promotion_id": "promo_KIDS10",
"code": "KIDS10",
"stage": "order",
"result": "applied",
"amount": 23600,
"reason_code": null,
"reason": null
},
{
"promotion_id": "promo_FREESHIP",
"code": null,
"stage": "shipping",
"result": "applied",
"amount": 5000,
"reason_code": null,
"reason": null
}
],
"amounts": {
"subtotal": 236000,
"item_discount": 0,
"order_discount": 23600,
"shipping_fee": 5000,
"shipping_discount": 5000,
"total": 212400,
"vat_included": 13895
},
"applied": [
"KIDS10",
"promo_FREESHIP"
],
"warnings": [],
"hints": [
"เพิ่มกระติกน้ำเด็กหลอดดูด 450 มล.อีก 1 ชิ้น รับฟรี 1 ชิ้น (กระติกน้ำ ซื้อ 2 แถม 1)"
]
}Endpoints (10)
| Method | Path | ทำอะไร | scope |
|---|---|---|---|
| GET | /v2/promotions | รายการโปรโมชัน | promotions:read |
| POST | /v2/promotions | สร้างโปรโมชันidempotent | promotions:write |
| GET | /v2/promotions/{promotion_id} | ดูโปรโมชัน | promotions:read |
| PATCH | /v2/promotions/{promotion_id} | แก้โปรโมชัน | promotions:write |
| POST | /v2/promotions/{promotion_id}/activate | เปิดใช้โปรโมชัน | promotions:write |
| POST | /v2/promotions/{promotion_id}/deactivate | ปิดโปรโมชัน | promotions:write |
| POST | /v2/coupons/batch | สร้างโค้ดคูปองหลายใบidempotent | promotions:write |
| GET | /v2/coupons/{code} | ตรวจโค้ดคูปอง | coupons:read |
| POST | /v2/promotions/simulate | จำลองการคิดโปร | promotions:read |
| GET | /v2/promotions/{promotion_id}/redemptions | ประวัติการใช้สิทธิ์ | promotions:read |
รายการโปรโมชัน
โปรทั้งหมดของร้าน (หลังบ้าน) หรือเฉพาะที่ใช้กับตะกร้าได้ (applicable_to=cart_…) สำหรับแสดง "คูปองที่ใช้ได้" ในหน้าตะกร้า
Query parametersquery
limitintegerไม่บังคับจำนวนรายการต่อหน้า
starting_afterstringไม่บังคับcursor — id ของรายการสุดท้ายในหน้าก่อน (ใช้ค่า next_cursor ที่ได้)
ending_beforestringไม่บังคับcursor ย้อนกลับ — id ของรายการแรกในหน้าปัจจุบัน
statusenumไม่บังคับสถานะ
typeenumไม่บังคับชนิด
active_atstring · date-timeไม่บังคับใช้ได้ ณ เวลานี้
applicable_tostringไม่บังคับเฉพาะที่ผ่านเงื่อนไขของตะกร้านี้ (ลูกค้าเรียกได้)
qstringไม่บังคับค้นชื่อ/โค้ด
ผลลัพธ์
- 2009 โปรในระบบตัวอย่าง
- 400
invalid_requestคำขอไม่ถูกต้อง - 403
insufficient_scopeสิทธิ์ไม่พอ - 404
cart_not_foundไม่พบตะกร้า
- applicable_to คืนเฉพาะคูปอง public ที่ผ่านเงื่อนไข ไม่เปิดเผยคูปองเฉพาะบุคคลของคนอื่น
curl -X GET "https://sandbox.api.leklek.example/v2/promotions?limit=20&applicable_to=cart_7Hq2" \
-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/promotions?limit=20&applicable_to=cart_7Hq2', {
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/promotions?limit=20&applicable_to=cart_7Hq2",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v2/promotions",
"has_more": false,
"next_cursor": null,
"data": [
{
"id": "promo_B2G1BTL",
"name": "กระติกน้ำ ซื้อ 2 แถม 1",
"type": "automatic",
"code": null,
"stage": "item",
"status": "active",
"starts_at": "2026-10-01T00:00:00+07:00",
"ends_at": "2026-12-31T23:59:59+07:00",
"used_count": 412
},
{
"id": "promo_DLRQ4",
"name": "ตัวแทน: สั่งครบ ฿20,000 ลดเพิ่ม 3%",
"type": "automatic",
"code": null,
"stage": "order",
"status": "active",
"starts_at": "2026-10-01T00:00:00+07:00",
"ends_at": "2026-12-31T23:59:59+07:00",
"used_count": 57
},
{
"id": "promo_KIDS10",
"name": "KIDS10 ลด 10% เมื่อครบ ฿1,000",
"type": "coupon",
"code": "KIDS10",
"stage": "order",
"status": "active",
"starts_at": "2026-10-01T00:00:00+07:00",
"ends_at": "2026-10-31T23:59:59+07:00",
"used_count": 1873
},
{
"id": "promo_WOOD50",
"name": "WOOD50 ลด ฿50 ของเล่นไม้",
"type": "coupon",
"code": "WOOD50",
"stage": "order",
"status": "active",
"starts_at": "2026-09-01T00:00:00+07:00",
"ends_at": "2026-11-30T23:59:59+07:00",
"used_count": 640
},
{
"id": "promo_NEW100",
"name": "NEW100 ลด ฿100 คำสั่งซื้อแรก",
"type": "coupon",
"code": "NEW100",
"stage": "order",
"status": "active",
"starts_at": "2026-01-01T00:00:00+07:00",
"ends_at": "2026-12-31T23:59:59+07:00",
"used_count": 2210
},
{
"id": "promo_GIFTWRAP",
"name": "GIFTWRAP ห่อของขวัญฟรี (ลด ฿30)",
"type": "coupon",
"code": "GIFTWRAP",
"stage": "order",
"status": "active",
"starts_at": "2026-01-01T00:00:00+07:00",
"ends_at": "2026-12-31T23:59:59+07:00",
"used_count": 905
},
{
"id": "promo_LEK1111",
"name": "LEK1111 ลด 11% วัน 11.11",
"type": "coupon",
"code": "LEK1111",
"stage": "order",
"status": "scheduled",
"starts_at": "2026-11-11T00:00:00+07:00",
"ends_at": "2026-11-12T23:59:59+07:00",
"used_count": 0
},
{
"id": "promo_SUMMER15",
"name": "SUMMER15 ลด 15% หน้าร้อน",
"type": "coupon",
"code": "SUMMER15",
"stage": "order",
"status": "expired",
"starts_at": "2026-04-01T00:00:00+07:00",
"ends_at": "2026-05-31T23:59:59+07:00",
"used_count": 3120
},
{
"id": "promo_FREESHIP",
"name": "ส่งฟรีเมื่อครบ ฿1,500",
"type": "automatic",
"code": null,
"stage": "shipping",
"status": "active",
"starts_at": "2025-01-01T00:00:00+07:00",
"ends_at": "2027-12-31T23:59:59+07:00",
"used_count": 9874
}
]
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_request"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#insufficient_scope"
}
}{
"error": {
"code": "cart_not_found",
"message": "ไม่พบตะกร้า",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#cart_not_found"
}
}สร้างโปรโมชัน
สร้างคูปองหรือโปรอัตโนมัติ — ถ้า starts_at อยู่ในอนาคตจะเป็น scheduled และเปิดเองตามเวลา · ตรวจกติกาขัดกันก่อนบันทึก
Headersheader
Idempotency-Keystring · uuidไม่บังคับUUID ที่ไม่ซ้ำต่อการกระทำ — ส่งซ้ำด้วยค่าเดิมภายใน 24 ชม. จะได้ผลเดิมโดยไม่สร้างรายการซ้ำ
Request bodyapplication/json
namestringจำเป็นชื่อที่ลูกค้าเห็น
typeenumจำเป็นcoupon = ต้องกรอกโค้ด · automatic = คิดให้เองเมื่อเข้าเงื่อนไข
codestringไม่บังคับโค้ดคูปอง (A-Z 0-9 4–32 ตัว ไม่สนตัวพิมพ์) — null สำหรับ automatic
descriptionstringไม่บังคับเงื่อนไขแบบย่อสำหรับแสดง
discountobjectจำเป็นรูปแบบส่วนลด
ฟิลด์ย่อยของ
discount(5)kindenumจำเป็นpercent · fixed (สตางค์) · free_shipping · buy_x_get_y
valueintegerไม่บังคับpercent = 1–100 · fixed = สตางค์
maxintegerไม่บังคับส่วนลดสูงสุด (สตางค์) สำหรับ percent
buyintegerไม่บังคับbuy_x_get_y: จำนวนที่ต้องซื้อ
getintegerไม่บังคับbuy_x_get_y: จำนวนที่ได้ฟรี (ชิ้นราคาต่ำสุด)
stageenumจำเป็นลำดับการคิด: item (ระดับสินค้า) → order (ทั้งคำสั่งซื้อ) → shipping (ค่าส่ง)
conditionsobjectไม่บังคับเงื่อนไข
ฟิลด์ย่อยของ
conditions(6)min_subtotalintegerไม่บังคับยอดขั้นต่ำ (สตางค์) — คิดหลังส่วนลดขั้นก่อนหน้า · ถ้ามี categories คิดเฉพาะสินค้าที่ร่วม
categoriesarray<string>ไม่บังคับหมวดที่ร่วม (null = ทุกหมวด)
sku_prefixstringไม่บังคับเลือกสินค้าด้วยต้นรหัส SKU เช่น LK-BTL-
customer_typesarray<string>ไม่บังคับguest member dealer
first_order_onlybooleanไม่บังคับเฉพาะคำสั่งซื้อแรกของบัญชี
channelsarray<string>ไม่บังคับweb app dealer_api
limitsobjectไม่บังคับการจำกัดสิทธิ์
ฟิลด์ย่อยของ
limits(2)per_customerintegerไม่บังคับครั้งต่อบัญชี (null = ไม่จำกัด)
usage_limitintegerไม่บังคับสิทธิ์รวมทั้งหมด
starts_atstring · date-timeจำเป็นเริ่ม (ISO 8601 +07:00)
ends_atstring · date-timeจำเป็นสิ้นสุด (ไม่เกิน 366 วันจากเริ่ม)
priorityintegerไม่บังคับลำดับภายใน stage เดียวกัน (น้อยคิดก่อน)
stackablebooleanไม่บังคับใช้ร่วมกับคูปองอื่นได้ (ต้อง true ทุกใบที่ใช้ร่วม) — โปรอัตโนมัติใช้ร่วมกับคูปองได้เสมอ
metadataobjectไม่บังคับข้อมูลของคุณเอง (เช่น รหัสแคมเปญ)
ผลลัพธ์
- 201สร้างแล้ว (scheduled)
- 422ช่วงเวลาไม่ถูกต้อง
- 409
promotion_code_existsโค้ดคูปองซ้ำ - 422
invalid_promotion_ruleกติกาโปรโมชันไม่ถูกต้อง - 422
promotion_window_invalidช่วงเวลาไม่ถูกต้อง - 422
validation_failedข้อมูลไม่ผ่านการตรวจ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่ body ต่าง
- percent ต้อง 1–100 และควรมี max · fixed เป็นสตางค์
- โค้ดที่หมดอายุไม่ถึง 12 เดือนยังจองชื่อไว้ (409 promotion_code_exists)
curl -X POST "https://sandbox.api.leklek.example/v2/promotions" \
-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 '{
"name": "LEK1111 ลด 11% วัน 11.11",
"type": "coupon",
"code": "LEK1111",
"description": "ตั้งเวลาไว้ล่วงหน้า",
"discount": {
"kind": "percent",
"value": 11,
"max": 111100
},
"stage": "order",
"conditions": {
"min_subtotal": 111100,
"customer_types": [
"guest",
"member"
],
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 1111
},
"starts_at": "2026-11-11T00:00:00+07:00",
"ends_at": "2026-11-12T23:59:59+07:00",
"priority": 30,
"stackable": false,
"metadata": {
"campaign": "1111-2026"
}
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/promotions', {
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({
"name": "LEK1111 ลด 11% วัน 11.11",
"type": "coupon",
"code": "LEK1111",
"description": "ตั้งเวลาไว้ล่วงหน้า",
"discount": {
"kind": "percent",
"value": 11,
"max": 111100
},
"stage": "order",
"conditions": {
"min_subtotal": 111100,
"customer_types": [
"guest",
"member"
],
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 1111
},
"starts_at": "2026-11-11T00:00:00+07:00",
"ends_at": "2026-11-12T23:59:59+07:00",
"priority": 30,
"stackable": false,
"metadata": {
"campaign": "1111-2026"
}
}),
});
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/promotions",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"LekLek-Version": "2026-08-01",
},
json={
"name": "LEK1111 ลด 11% วัน 11.11",
"type": "coupon",
"code": "LEK1111",
"description": "ตั้งเวลาไว้ล่วงหน้า",
"discount": {
"kind": "percent",
"value": 11,
"max": 111100
},
"stage": "order",
"conditions": {
"min_subtotal": 111100,
"customer_types": [
"guest",
"member"
],
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 1111
},
"starts_at": "2026-11-11T00:00:00+07:00",
"ends_at": "2026-11-12T23:59:59+07:00",
"priority": 30,
"stackable": False,
"metadata": {
"campaign": "1111-2026"
}
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "promo_LEK1111",
"object": "promotion",
"name": "LEK1111 ลด 11% วัน 11.11",
"type": "coupon",
"code": "LEK1111",
"description": "ตั้งเวลาไว้ล่วงหน้า",
"discount": {
"kind": "percent",
"value": 11,
"max": 111100
},
"stage": "order",
"conditions": {
"min_subtotal": 111100,
"categories": null,
"sku_prefix": null,
"customer_types": [
"guest",
"member"
],
"first_order_only": false,
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 1111,
"used_count": 0,
"remaining": 1111
},
"starts_at": "2026-11-11T00:00:00+07:00",
"ends_at": "2026-11-12T23:59:59+07:00",
"priority": 30,
"stackable": false,
"status": "scheduled",
"created": "2026-10-12T14:02:10+07:00",
"updated": "2026-10-12T14:02:10+07:00",
"metadata": {
"campaign": "1111-2026"
}
}{
"error": {
"code": "promotion_window_invalid",
"message": "ends_at ต้องอยู่หลัง starts_at",
"param": "ends_at",
"starts_at": "2026-11-11T00:00:00+07:00",
"ends_at": "2026-11-10T23:59:59+07:00",
"request_id": "req_6Yj2Qe9V"
}
}{
"error": {
"code": "promotion_code_exists",
"message": "โค้ดคูปองซ้ำ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_code_exists"
}
}{
"error": {
"code": "invalid_promotion_rule",
"message": "กติกาโปรโมชันไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_promotion_rule"
}
}{
"error": {
"code": "promotion_window_invalid",
"message": "ช่วงเวลาไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_window_invalid"
}
}{
"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"
}
}ดูโปรโมชัน
GET/v2/promotions/{promotion_id}
รายละเอียดเต็มพร้อมจำนวนสิทธิ์ที่ใช้/คงเหลือ
Path parameterspath
promotion_idstringจำเป็นรหัสโปรโมชัน
ผลลัพธ์
- 200KIDS10
- 404
promotion_not_foundไม่พบโปรโมชัน
- limits.remaining คำนวณสด ณ เวลาที่เรียก (สิทธิ์นับเมื่อชำระสำเร็จ · คำสั่งซื้อที่ยกเลิกคืนสิทธิ์)
- โปรที่หมดอายุแล้วยังเรียกดูได้ตลอด (status=expired) เพื่อใช้อ้างอิงในคำสั่งซื้อเก่า
curl -X GET "https://sandbox.api.leklek.example/v2/promotions/promo_KIDS10" \
-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/promotions/promo_KIDS10', {
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/promotions/promo_KIDS10",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "promo_KIDS10",
"object": "promotion",
"name": "KIDS10 ลด 10% เมื่อครบ ฿1,000",
"type": "coupon",
"code": "KIDS10",
"description": "ลดสูงสุด ฿500 · ใช้ได้ 1 ครั้งต่อบัญชี",
"discount": {
"kind": "percent",
"value": 10,
"max": 50000
},
"stage": "order",
"conditions": {
"min_subtotal": 100000,
"categories": null,
"sku_prefix": null,
"customer_types": [
"guest",
"member"
],
"first_order_only": false,
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 5000,
"used_count": 1873,
"remaining": 3127
},
"starts_at": "2026-10-01T00:00:00+07:00",
"ends_at": "2026-10-31T23:59:59+07:00",
"priority": 30,
"stackable": false,
"status": "active",
"created": "2026-09-25T14:00:00+07:00",
"updated": "2026-10-01T00:00:00+07:00",
"metadata": {}
}{
"error": {
"code": "promotion_not_found",
"message": "ไม่พบโปรโมชัน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_not_found"
}
}แก้โปรโมชัน
PATCH/v2/promotions/{promotion_id}
แก้ชื่อ คำอธิบาย วันสิ้นสุด สิทธิ์รวม หรือลำดับ — โปรที่มีคนใช้แล้วแก้ส่วนลด/ขั้นต่ำ/หมวดไม่ได้ (409 promotion_locked) เพื่อความเป็นธรรมกับลูกค้า
Path parameterspath
promotion_idstringจำเป็นรหัสโปรโมชัน
Request bodyapplication/json
namestringไม่บังคับชื่อที่ลูกค้าเห็น
typeenumไม่บังคับcoupon = ต้องกรอกโค้ด · automatic = คิดให้เองเมื่อเข้าเงื่อนไข
codestringไม่บังคับโค้ดคูปอง (A-Z 0-9 4–32 ตัว ไม่สนตัวพิมพ์) — null สำหรับ automatic
descriptionstringไม่บังคับเงื่อนไขแบบย่อสำหรับแสดง
discountobjectไม่บังคับรูปแบบส่วนลด
ฟิลด์ย่อยของ
discount(5)kindenumไม่บังคับpercent · fixed (สตางค์) · free_shipping · buy_x_get_y
valueintegerไม่บังคับpercent = 1–100 · fixed = สตางค์
maxintegerไม่บังคับส่วนลดสูงสุด (สตางค์) สำหรับ percent
buyintegerไม่บังคับbuy_x_get_y: จำนวนที่ต้องซื้อ
getintegerไม่บังคับbuy_x_get_y: จำนวนที่ได้ฟรี (ชิ้นราคาต่ำสุด)
stageenumไม่บังคับลำดับการคิด: item (ระดับสินค้า) → order (ทั้งคำสั่งซื้อ) → shipping (ค่าส่ง)
conditionsobjectไม่บังคับเงื่อนไข
ฟิลด์ย่อยของ
conditions(6)min_subtotalintegerไม่บังคับยอดขั้นต่ำ (สตางค์) — คิดหลังส่วนลดขั้นก่อนหน้า · ถ้ามี categories คิดเฉพาะสินค้าที่ร่วม
categoriesarray<string>ไม่บังคับหมวดที่ร่วม (null = ทุกหมวด)
sku_prefixstringไม่บังคับเลือกสินค้าด้วยต้นรหัส SKU เช่น LK-BTL-
customer_typesarray<string>ไม่บังคับguest member dealer
first_order_onlybooleanไม่บังคับเฉพาะคำสั่งซื้อแรกของบัญชี
channelsarray<string>ไม่บังคับweb app dealer_api
limitsobjectไม่บังคับการจำกัดสิทธิ์
ฟิลด์ย่อยของ
limits(2)per_customerintegerไม่บังคับครั้งต่อบัญชี (null = ไม่จำกัด)
usage_limitintegerไม่บังคับสิทธิ์รวมทั้งหมด
starts_atstring · date-timeไม่บังคับเริ่ม (ISO 8601 +07:00)
ends_atstring · date-timeไม่บังคับสิ้นสุด (ไม่เกิน 366 วันจากเริ่ม)
priorityintegerไม่บังคับลำดับภายใน stage เดียวกัน (น้อยคิดก่อน)
stackablebooleanไม่บังคับใช้ร่วมกับคูปองอื่นได้ (ต้อง true ทุกใบที่ใช้ร่วม) — โปรอัตโนมัติใช้ร่วมกับคูปองได้เสมอ
metadataobjectไม่บังคับข้อมูลของคุณเอง (เช่น รหัสแคมเปญ)
ผลลัพธ์
- 200ขยายเวลาและสิทธิ์รวม
- 409พยายามแก้ส่วนลดของโปรที่มีคนใช้แล้ว
- 409
promotion_lockedแก้ส่วนลดไม่ได้แล้ว - 422
promotion_window_invalidช่วงเวลาไม่ถูกต้อง - 422
invalid_promotion_ruleกติกาโปรโมชันไม่ถูกต้อง - 404
promotion_not_foundไม่พบโปรโมชัน
- ฟิลด์ที่แก้ไม่ได้บอกใน error.locked_fields — ต้องการเปลี่ยนส่วนลดจริงให้ปิดโปรเดิมแล้วสร้างโปรใหม่
- ขยาย ends_at ได้เสมอ · ย่น ends_at ให้สั้นกว่าเวลาปัจจุบันไม่ได้ (ใช้ /deactivate แทน)
curl -X PATCH "https://sandbox.api.leklek.example/v2/promotions/promo_KIDS10" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "Content-Type: application/json" \
-H "LekLek-Version: 2026-08-01" \
-d '{
"ends_at": "2026-11-07T23:59:59+07:00",
"limits": {
"usage_limit": 6000
}
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/promotions/promo_KIDS10', {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'LekLek-Version': '2026-08-01',
},
body: JSON.stringify({
"ends_at": "2026-11-07T23:59:59+07:00",
"limits": {
"usage_limit": 6000
}
}),
});
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/promotions/promo_KIDS10",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"LekLek-Version": "2026-08-01",
},
json={
"ends_at": "2026-11-07T23:59:59+07:00",
"limits": {
"usage_limit": 6000
}
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "promo_KIDS10",
"object": "promotion",
"name": "KIDS10 ลด 10% เมื่อครบ ฿1,000",
"type": "coupon",
"code": "KIDS10",
"description": "ลดสูงสุด ฿500 · ใช้ได้ 1 ครั้งต่อบัญชี",
"discount": {
"kind": "percent",
"value": 10,
"max": 50000
},
"stage": "order",
"conditions": {
"min_subtotal": 100000,
"categories": null,
"sku_prefix": null,
"customer_types": [
"guest",
"member"
],
"first_order_only": false,
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 6000,
"used_count": 1873,
"remaining": 4127
},
"starts_at": "2026-10-01T00:00:00+07:00",
"ends_at": "2026-11-07T23:59:59+07:00",
"priority": 30,
"stackable": false,
"status": "active",
"created": "2026-09-25T14:00:00+07:00",
"updated": "2026-10-12T15:30:00+07:00",
"metadata": {}
}{
"error": {
"code": "promotion_locked",
"message": "มีการใช้แล้ว 1873 ครั้ง แก้ discount ไม่ได้",
"locked_fields": [
"discount",
"conditions.min_subtotal",
"conditions.categories"
],
"request_id": "req_0Pd7Fw3X"
}
}{
"error": {
"code": "promotion_locked",
"message": "แก้ส่วนลดไม่ได้แล้ว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_locked"
}
}{
"error": {
"code": "promotion_window_invalid",
"message": "ช่วงเวลาไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_window_invalid"
}
}{
"error": {
"code": "invalid_promotion_rule",
"message": "กติกาโปรโมชันไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_promotion_rule"
}
}{
"error": {
"code": "promotion_not_found",
"message": "ไม่พบโปรโมชัน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_not_found"
}
}เปิดใช้โปรโมชัน
POST/v2/promotions/{promotion_id}/activate
เปิดโปรทันที (แม้ตั้งเวลาไว้) หรือเปิดกลับหลังปิดชั่วคราว — ต้องยังไม่เลย ends_at
Path parameterspath
promotion_idstringจำเป็นรหัสโปรโมชัน
ผลลัพธ์
- 200เปิดแล้ว
- 409เปิดอยู่แล้ว
- 409
promotion_already_activeโปรโมชันเปิดอยู่แล้ว - 422
promotion_window_invalidช่วงเวลาไม่ถูกต้อง - 404
promotion_not_foundไม่พบโปรโมชัน
- ไม่มี body — การเรียกซ้ำกับโปรที่เปิดอยู่แล้วได้ 409 promotion_already_active (ไม่มีผลข้างเคียง)
- เปิดแล้วยิง promotion.activated ให้ระบบอื่นล้างแคชราคา/ป้ายโปรภายใน 1 นาที
curl -X POST "https://sandbox.api.leklek.example/v2/promotions/promo_KIDS10/activate" \
-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/promotions/promo_KIDS10/activate', {
method: 'POST',
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.post(
"https://sandbox.api.leklek.example/v2/promotions/promo_KIDS10/activate",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "promo_KIDS10",
"object": "promotion",
"name": "KIDS10 ลด 10% เมื่อครบ ฿1,000",
"type": "coupon",
"code": "KIDS10",
"description": "ลดสูงสุด ฿500 · ใช้ได้ 1 ครั้งต่อบัญชี",
"discount": {
"kind": "percent",
"value": 10,
"max": 50000
},
"stage": "order",
"conditions": {
"min_subtotal": 100000,
"categories": null,
"sku_prefix": null,
"customer_types": [
"guest",
"member"
],
"first_order_only": false,
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 1,
"usage_limit": 5000,
"used_count": 1873,
"remaining": 3127
},
"starts_at": "2026-10-01T00:00:00+07:00",
"ends_at": "2026-10-31T23:59:59+07:00",
"priority": 30,
"stackable": false,
"status": "active",
"created": "2026-09-25T14:00:00+07:00",
"updated": "2026-10-01T00:00:00+07:00",
"metadata": {}
}{
"error": {
"code": "promotion_already_active",
"message": "KIDS10 เปิดใช้อยู่แล้ว",
"request_id": "req_5Hn1Ul8T"
}
}{
"error": {
"code": "promotion_already_active",
"message": "โปรโมชันเปิดอยู่แล้ว",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_already_active"
}
}{
"error": {
"code": "promotion_window_invalid",
"message": "ช่วงเวลาไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_window_invalid"
}
}{
"error": {
"code": "promotion_not_found",
"message": "ไม่พบโปรโมชัน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_not_found"
}
}ปิดโปรโมชัน
POST/v2/promotions/{promotion_id}/deactivate
ปิดทันที — ตะกร้าที่ใส่โค้ดนี้อยู่จะได้ warnings coupon_not_active ครั้งถัดไป คำสั่งซื้อที่สร้างแล้วยังได้ส่วนลดเดิม
Path parameterspath
promotion_idstringจำเป็นรหัสโปรโมชัน
Request bodyapplication/json
reasonstringไม่บังคับเหตุผล (บันทึกใน audit)
ผลลัพธ์
- 200ปิดแล้ว
- 404
promotion_not_foundไม่พบโปรโมชัน - 409
invalid_state_transitionเปลี่ยนสถานะตามลำดับนี้ไม่ได้
- ส่ง reason ได้ (บันทึกใน audit log) เช่น "งบหมด" หรือ "ตั้งค่าผิด"
- ปิดแล้วเปิดกลับได้ด้วย /activate ตราบใดที่ยังไม่เลย ends_at
curl -X POST "https://sandbox.api.leklek.example/v2/promotions/promo_WOOD50/deactivate" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "Content-Type: application/json" \
-H "LekLek-Version: 2026-08-01" \
-d '{
"reason": "สต็อกของเล่นไม้ใกล้หมด"
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/promotions/promo_WOOD50/deactivate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'LekLek-Version': '2026-08-01',
},
body: JSON.stringify({
"reason": "สต็อกของเล่นไม้ใกล้หมด"
}),
});
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/promotions/promo_WOOD50/deactivate",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"LekLek-Version": "2026-08-01",
},
json={
"reason": "สต็อกของเล่นไม้ใกล้หมด"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"id": "promo_WOOD50",
"object": "promotion",
"name": "WOOD50 ลด ฿50 ของเล่นไม้",
"type": "coupon",
"code": "WOOD50",
"description": "คิดขั้นต่ำจากสินค้าหมวดไม้เท่านั้น · สมาชิกเท่านั้น",
"discount": {
"kind": "fixed",
"value": 5000,
"max": null
},
"stage": "order",
"conditions": {
"min_subtotal": 50000,
"categories": [
"wooden-toys",
"puzzle",
"music",
"pretend-play"
],
"sku_prefix": null,
"customer_types": [
"member"
],
"first_order_only": false,
"channels": [
"web",
"app"
]
},
"limits": {
"per_customer": 3,
"usage_limit": null,
"used_count": 640,
"remaining": null
},
"starts_at": "2026-09-01T00:00:00+07:00",
"ends_at": "2026-11-30T23:59:59+07:00",
"priority": 30,
"stackable": false,
"status": "inactive",
"created": "2026-09-25T14:00:00+07:00",
"updated": "2026-10-12T16:00:00+07:00",
"metadata": {}
}{
"error": {
"code": "promotion_not_found",
"message": "ไม่พบโปรโมชัน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_not_found"
}
}{
"error": {
"code": "invalid_state_transition",
"message": "เปลี่ยนสถานะตามลำดับนี้ไม่ได้",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_state_transition"
}
}สร้างโค้ดคูปองหลายใบ
สร้างโค้ดไม่ซ้ำจำนวนมากให้โปร (เช่น แจกเฉพาะบุคคล 1,111 ใบ) — ไม่เกิน 1,000 ใบได้ผลทันที (201) · มากกว่านั้นทำเบื้องหลัง (202) แล้วแจ้ง coupon_batch.completed
Headersheader
Idempotency-Keystring · uuidไม่บังคับUUID ที่ไม่ซ้ำต่อการกระทำ — ส่งซ้ำด้วยค่าเดิมภายใน 24 ชม. จะได้ผลเดิมโดยไม่สร้างรายการซ้ำ
Request bodyapplication/json
promotion_idstringจำเป็นโปรที่โค้ดสังกัด
countintegerจำเป็นจำนวนโค้ด (สูงสุด 10,000)
prefixstringไม่บังคับขึ้นต้นโค้ด
lengthintegerไม่บังคับความยาวส่วนสุ่ม (ตัดตัวที่สับสน 0 O 1 I ออก)
assign_toarray<string>ไม่บังคับผูกโค้ดกับลูกค้าทีละคนตามลำดับ (ไม่บังคับ)
ผลลัพธ์
- 202รับงานแล้ว (เกิน 1,000 ใบ)
- 422
batch_too_largebatch ใหญ่เกิน - 404
promotion_not_foundไม่พบโปรโมชัน - 422
validation_failedข้อมูลไม่ผ่านการตรวจ - 409
idempotency_conflictIdempotency-Key ซ้ำแต่ body ต่าง
- ดาวน์โหลดไฟล์ CSV ของโค้ดได้จาก download_url เมื่อ status=completed (ลิงก์อายุ 1 ชม.)
curl -X POST "https://sandbox.api.leklek.example/v2/coupons/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 '{
"promotion_id": "promo_LEK1111",
"count": 1111,
"prefix": "LEK1111-",
"length": 6
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/coupons/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({
"promotion_id": "promo_LEK1111",
"count": 1111,
"prefix": "LEK1111-",
"length": 6
}),
});
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/coupons/batch",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"Idempotency-Key": "7f3c9a2e-1b4d-4c8e-9f60-2a5d8e1c4b7f",
"LekLek-Version": "2026-08-01",
},
json={
"promotion_id": "promo_LEK1111",
"count": 1111,
"prefix": "LEK1111-",
"length": 6
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "coupon_batch",
"id": "cbat_1111A",
"promotion_id": "promo_LEK1111",
"count": 1111,
"status": "processing",
"sample": [
"LEK1111-7QF4MZ",
"LEK1111-K9W2XT"
],
"download_url": null,
"created": "2026-10-12T14:05:00+07:00"
}{
"error": {
"code": "batch_too_large",
"message": "batch ใหญ่เกิน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#batch_too_large"
}
}{
"error": {
"code": "promotion_not_found",
"message": "ไม่พบโปรโมชัน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_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"
}
}ตรวจโค้ดคูปอง
ตรวจว่าโค้ดใช้ได้ไหมและมีเงื่อนไขอะไร (ไม่ผูกกับตะกร้า) — ใช้แสดงรายละเอียดคูปองในแอป · โค้ดที่ไม่มีได้ 404 โดยไม่บอกโค้ดใกล้เคียง
Path parameterspath
codestringจำเป็นโค้ดคูปอง
ผลลัพธ์
- 200มีอยู่แต่ยังไม่เริ่ม
- 404
coupon_not_foundไม่พบคูปอง - 429
rate_limitedเรียกเกินโควตา
- จำกัด 30 ครั้ง/นาที/คีย์ และล็อก IP ชั่วคราวเมื่อเดาผิดติดกันเกิน 20 ครั้ง (กันสุ่มโค้ด)
- valid=true ไม่ได้รับประกันว่าจะใช้กับตะกร้าได้ — ต้องผ่านขั้นต่ำ/หมวด/สิทธิ์ต่อคนตอน POST /v2/carts/{id}/coupons อีกครั้ง
curl -X GET "https://sandbox.api.leklek.example/v2/coupons/LEK1111-7QF4MZ" \
-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/coupons/LEK1111-7QF4MZ', {
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/coupons/LEK1111-7QF4MZ",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"code": "LEK1111-7QF4MZ",
"object": "coupon",
"promotion_id": "promo_LEK1111",
"batch_id": "cbat_1111A",
"status": "available",
"assigned_to": "cus_P3k9",
"redeemed_at": null,
"order_id": null,
"valid": false,
"invalid_reason": "ยังไม่เริ่ม (เริ่ม 2026-11-11)",
"conditions": {
"min_subtotal": 111100,
"discount": "11% สูงสุด ฿1,111"
},
"max_redemptions": 1,
"times_redeemed": 0,
"starts_at": "2026-11-11T00:00:00+07:00",
"expires_at": "2026-11-12T23:59:59+07:00",
"created": "2026-10-12T14:05:00+07:00"
}{
"error": {
"code": "coupon_not_found",
"message": "ไม่พบคูปอง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#coupon_not_found"
}
}{
"error": {
"code": "rate_limited",
"message": "เรียกเกินโควตา",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#rate_limited"
}
}จำลองการคิดโปร
ส่งรายการสินค้า + คูปอง + ประเภทลูกค้า (+ เวลา) แล้วได้ผลการคิดทีละโปรตามลำดับ พร้อมเหตุผลที่ไม่ผ่าน — ใช้ทดสอบก่อนเปิดแคมเปญ หรือช่วยลูกค้าเลือกคูปองที่คุ้มที่สุด (ไม่จองสต็อก ไม่นับสิทธิ์)
Request bodyapplication/json
itemsarray<object>ไม่บังคับรายการ (หรือส่ง cart_id)
ฟิลด์ย่อยของ
items(2)skustringจำเป็นSKU
quantityintegerจำเป็นจำนวน
cart_idstringไม่บังคับใช้รายการจากตะกร้านี้
couponsarray<string>ไม่บังคับคูปองตามลำดับที่ลูกค้าใส่
customer_typeenumไม่บังคับประเภทลูกค้า
customer_idstringไม่บังคับใช้ตรวจสิทธิ์ต่อคน/คำสั่งซื้อแรก
postal_codestringไม่บังคับสำหรับโปรค่าส่ง
atstring · date-timeไม่บังคับจำลอง ณ เวลา (ทดสอบโปรที่ตั้งเวลาไว้)
promotion_idsarray<string>ไม่บังคับจำกัดเฉพาะโปรเหล่านี้ (รวมที่ scheduled) — ไม่ส่ง = โปรที่ active
ผลลัพธ์
- 200KIDS10 ผ่าน · WOOD50 ใช้ร่วมไม่ได้ · ส่งฟรี — ยอด ฿2,124
- 400
invalid_requestคำขอไม่ถูกต้อง - 404
cart_not_foundไม่พบตะกร้า - 404
resource_not_foundไม่พบข้อมูล - 422
validation_failedข้อมูลไม่ผ่านการตรวจ
- ลำดับการคิด: (1) item: ซื้อ X แถม Y (2) order: โปรอัตโนมัติ → คูปองตามลำดับที่ใส่ (3) shipping: ส่งฟรี — ขั้นหลังคิดจากยอดหลังขั้นก่อน
- ลองปรับเองได้ในเครื่องมือจำลองท้ายหน้า
curl -X POST "https://sandbox.api.leklek.example/v2/promotions/simulate" \
-H "Authorization: Bearer lk_test_51HcQ2xT8bWm4" \
-H "Content-Type: application/json" \
-H "LekLek-Version: 2026-08-01" \
-d '{
"cart_id": "cart_7Hq2",
"coupons": [
"KIDS10",
"WOOD50"
],
"customer_type": "member",
"customer_id": "cus_P3k9",
"postal_code": "10900"
}'const API_KEY = process.env.API_KEY; // lk_test_51HcQ2xT8bWm4
const res = await fetch('https://sandbox.api.leklek.example/v2/promotions/simulate', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
'LekLek-Version': '2026-08-01',
},
body: JSON.stringify({
"cart_id": "cart_7Hq2",
"coupons": [
"KIDS10",
"WOOD50"
],
"customer_type": "member",
"customer_id": "cus_P3k9",
"postal_code": "10900"
}),
});
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/promotions/simulate",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
"LekLek-Version": "2026-08-01",
},
json={
"cart_id": "cart_7Hq2",
"coupons": [
"KIDS10",
"WOOD50"
],
"customer_type": "member",
"customer_id": "cus_P3k9",
"postal_code": "10900"
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "promotion_simulation",
"currency": "THB",
"lines": [
{
"sku": "LK-TRN-003",
"quantity": 1,
"unit_price": 89000,
"subtotal": 89000,
"discount": 0,
"total": 89000
},
{
"sku": "LK-BTL-450-MT",
"quantity": 2,
"unit_price": 39000,
"subtotal": 78000,
"discount": 0,
"total": 78000
},
{
"sku": "LK-BNY-030-CR",
"quantity": 1,
"unit_price": 69000,
"subtotal": 69000,
"discount": 0,
"total": 69000
}
],
"evaluation": [
{
"promotion_id": "promo_B2G1BTL",
"code": null,
"stage": "item",
"result": "rejected",
"amount": 0,
"reason_code": "min_quantity_not_met",
"reason": "มีสินค้าร่วมรายการ 2 ชิ้น ต้องครบ 3 ชิ้น"
},
{
"promotion_id": "promo_DLRQ4",
"code": null,
"stage": "order",
"result": "rejected",
"amount": 0,
"reason_code": "not_eligible_customer",
"reason": "เฉพาะตัวแทนจำหน่าย"
},
{
"promotion_id": "promo_KIDS10",
"code": "KIDS10",
"stage": "order",
"result": "applied",
"amount": 23600,
"reason_code": null,
"reason": null
},
{
"promotion_id": "promo_WOOD50",
"code": "WOOD50",
"stage": "order",
"result": "rejected",
"amount": 0,
"reason_code": "coupon_not_combinable",
"reason": "ใช้ร่วมกับ KIDS10 ไม่ได้ (1 คำสั่งซื้อ 1 คูปอง)"
},
{
"promotion_id": "promo_FREESHIP",
"code": null,
"stage": "shipping",
"result": "applied",
"amount": 5000,
"reason_code": null,
"reason": null
}
],
"amounts": {
"subtotal": 236000,
"item_discount": 0,
"order_discount": 23600,
"shipping_fee": 5000,
"shipping_discount": 5000,
"total": 212400,
"vat_included": 13895
},
"applied": [
"KIDS10",
"promo_FREESHIP"
],
"warnings": [
{
"code": "coupon_not_combinable",
"message": "WOOD50: ใช้ร่วมกับ KIDS10 ไม่ได้ (1 คำสั่งซื้อ 1 คูปอง)",
"param": "coupons"
}
],
"hints": [
"เพิ่มกระติกน้ำเด็กหลอดดูด 450 มล.อีก 1 ชิ้น รับฟรี 1 ชิ้น (กระติกน้ำ ซื้อ 2 แถม 1)"
]
}{
"error": {
"code": "invalid_request",
"message": "คำขอไม่ถูกต้อง",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#invalid_request"
}
}{
"error": {
"code": "cart_not_found",
"message": "ไม่พบตะกร้า",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#cart_not_found"
}
}{
"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"
}
}ประวัติการใช้สิทธิ์
GET/v2/promotions/{promotion_id}/redemptions
คำสั่งซื้อที่ใช้โปรนี้ (นับเมื่อชำระสำเร็จ · ยกเลิกแล้วคืนสิทธิ์) พร้อมยอดส่วนลด — ใช้วัดผลแคมเปญ
Path parameterspath
promotion_idstringจำเป็นรหัสโปรโมชัน
Query parametersquery
limitintegerไม่บังคับจำนวนรายการต่อหน้า
starting_afterstringไม่บังคับcursor — id ของรายการสุดท้ายในหน้าก่อน (ใช้ค่า next_cursor ที่ได้)
ending_beforestringไม่บังคับcursor ย้อนกลับ — id ของรายการแรกในหน้าปัจจุบัน
created_gtestring · date-timeไม่บังคับตั้งแต่
ผลลัพธ์
- 200ใช้แล้ว 1873 ครั้ง (แสดงล่าสุด)
- 404
promotion_not_foundไม่พบโปรโมชัน - 403
insufficient_scopeสิทธิ์ไม่พอ
- นับเฉพาะคำสั่งซื้อที่ชำระสำเร็จ (status=counted) · ใช้ created_gte ดึงเฉพาะช่วงแคมเปญ
- summary.redemptions เป็นยอดรวมทั้งหมดของโปร ไม่ขึ้นกับหน้า (cursor) ที่เรียก
curl -X GET "https://sandbox.api.leklek.example/v2/promotions/promo_KIDS10/redemptions?limit=20" \
-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/promotions/promo_KIDS10/redemptions?limit=20', {
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/promotions/promo_KIDS10/redemptions?limit=20",
headers={
"Authorization": f"Bearer {API_KEY}",
"LekLek-Version": "2026-08-01",
},
timeout=10,
)
res.raise_for_status()
print(res.json()){
"object": "list",
"url": "/v2/promotions/promo_KIDS10/redemptions",
"has_more": true,
"next_cursor": "ord_2610_0047",
"data": [
{
"order_id": "ord_2610_0047",
"customer_id": "cus_P3k9",
"amount": 23600,
"redeemed_at": "2026-10-12T10:26:41+07:00",
"status": "counted"
}
],
"summary": {
"redemptions": 1873,
"discount_total_estimate": null
}
}{
"error": {
"code": "promotion_not_found",
"message": "ไม่พบโปรโมชัน",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#promotion_not_found"
}
}{
"error": {
"code": "insufficient_scope",
"message": "สิทธิ์ไม่พอ",
"request_id": "req_8Fq2LmX0",
"doc_url": "https://docs.leklek.example/errors#insufficient_scope"
}
}Webhooks — แจ้งเหตุการณ์ไปที่ระบบของคุณ
ลงทะเบียน URL ปลายทาง แล้วระบบจะส่ง POST พร้อม JSON ทุกครั้งที่เกิดเหตุการณ์ด้านล่าง · ตอบกลับ 2xx ภายใน 10 วินาที ไม่งั้นจะส่งซ้ำตามตาราง · ทุกคำขอมีหัว LekLek-Signature ให้ตรวจว่ามาจากเราจริง · event อาจมาซ้ำหรือสลับลำดับ ให้ใช้ id กันประมวลผลซ้ำ
promotion.createdสร้างโปรใหม่
ส่งเมื่อ: POST /v2/promotions สำเร็จ
{
"id": "evt_01JB7Q00",
"type": "promotion.created",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "promo_LEK1111",
"code": "LEK1111",
"status": "scheduled",
"starts_at": "2026-11-11T00:00:00+07:00"
}
}promotion.activatedโปรเริ่มใช้งาน
ส่งเมื่อ: ถึง starts_at หรือเรียก /activate
{
"id": "evt_01JB7Q01",
"type": "promotion.activated",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "promo_LEK1111",
"code": "LEK1111",
"activated_at": "2026-11-11T00:00:00+07:00",
"by": "schedule"
}
}promotion.deactivatedปิดโปร
ส่งเมื่อ: เรียก /deactivate
{
"id": "evt_01JB7Q02",
"type": "promotion.deactivated",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "promo_WOOD50",
"reason": "สต็อกของเล่นไม้ใกล้หมด",
"by": "staff:marketing01"
}
}promotion.expiredโปรหมดอายุ
ส่งเมื่อ: เลย ends_at
{
"id": "evt_01JB7Q03",
"type": "promotion.expired",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "promo_SUMMER15",
"expired_at": "2026-05-31T23:59:59+07:00",
"used_count": 3120
}
}promotion.usage_thresholdใช้สิทธิ์ถึง 80%
ส่งเมื่อ: used_count ≥ 80% ของ usage_limit (ทีมตัดสินใจขยายสิทธิ์)
{
"id": "evt_01JB7Q04",
"type": "promotion.usage_threshold",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "promo_KIDS10",
"used_count": 4000,
"usage_limit": 5000,
"percent": 80
}
}coupon.redeemedใช้คูปองสำเร็จ
ส่งเมื่อ: คำสั่งซื้อที่ใช้คูปองชำระสำเร็จ
{
"id": "evt_01JB7Q05",
"type": "coupon.redeemed",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"code": "KIDS10",
"promotion_id": "promo_KIDS10",
"order_id": "ord_2610_0047",
"customer_id": "cus_P3k9",
"amount": 23600
}
}coupon_batch.completedสร้างโค้ดชุดใหญ่เสร็จ
ส่งเมื่อ: งาน /coupons/batch แบบเบื้องหลังเสร็จ
{
"id": "evt_01JB7Q06",
"type": "coupon_batch.completed",
"created": "2026-10-12T10:00:00+07:00",
"livemode": false,
"data": {
"id": "cbat_1111A",
"promotion_id": "promo_LEK1111",
"count": 1111,
"download_url": "https://files.leklek.example/coupons/cbat_1111A.csv"
}
}ส่งซ้ำเมื่อปลายทางไม่ตอบ
- 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 · ใช้ตัวอย่างในหน้านี้เป็นแม่แบบ |
| 401 | authentication_required | ไม่ได้ส่งข้อมูลยืนยันตัวตน ไม่มีหัว Authorization หรือรูปแบบไม่ใช่ Bearer | ส่ง Authorization: Bearer <API key หรือ access token> |
| 403 | insufficient_scope | สิทธิ์ไม่พอ key/token นี้ไม่มี scope ที่ endpoint ต้องการ (ดูช่อง "สิทธิ์" ของแต่ละ endpoint) | เพิ่ม scope ให้ key ในแดชบอร์ด หรือขอ token ใหม่พร้อม scope ที่ต้องการ |
| 409 | idempotency_conflict | Idempotency-Key ซ้ำแต่ body ต่าง เคยใช้ Idempotency-Key นี้กับ body อื่นภายใน 24 ชม. | สร้าง key ใหม่ (UUID v4) ทุกการกระทำใหม่ · ใช้ key เดิมเฉพาะตอนส่งซ้ำของเดิม |
| 422 | validation_failed | ข้อมูลไม่ผ่านการตรวจ รูปแบบถูกแต่ค่าผิดกติกาทางธุรกิจ (เช่น จำนวนติดลบ ช่วงวันที่กลับด้าน) — มี error.details[] ทีละฟิลด์ | แสดง details[].message ใต้ช่องที่เกี่ยวข้อง แล้วให้ผู้ใช้แก้ |
| 404 | promotion_not_found | ไม่พบโปรโมชัน promotion id ไม่มีอยู่ | ตรวจ id จาก GET /v2/promotions |
| 409 | promotion_code_exists | โค้ดคูปองซ้ำ มีคูปองใช้โค้ดนี้แล้ว (รวมที่หมดอายุภายใน 12 เดือน) | ใช้โค้ดใหม่ หรือให้ระบบสุ่มด้วย POST /v2/coupons/batch |
| 409 | promotion_already_active | โปรโมชันเปิดอยู่แล้ว เรียก activate ซ้ำกับโปรที่ active | ไม่ต้องทำอะไร (ถือว่าสำเร็จ) หรือเช็ก status ก่อน |
| 422 | invalid_promotion_rule | กติกาโปรโมชันไม่ถูกต้อง ค่าขัดกัน เช่น percent > 100 · buy_x_get_y ไม่มี buy · fixed เป็นลบ | ดู error.details[] แล้วแก้ทีละช่อง |
| 422 | promotion_window_invalid | ช่วงเวลาไม่ถูกต้อง ends_at ก่อน starts_at หรือยาวเกิน 366 วัน | ตั้งช่วงเวลาใหม่ (ISO 8601 +07:00) |
| 409 | promotion_locked | แก้ส่วนลดไม่ได้แล้ว โปรที่มีคนใช้แล้วแก้มูลค่าส่วนลด/ขั้นต่ำไม่ได้ (กันข้อพิพาท) — แก้ได้เฉพาะชื่อ วันสิ้นสุด และสิทธิ์รวม | ปิดโปรเดิม (deactivate) แล้วสร้างโปรใหม่ |
| 404 | coupon_not_found | ไม่พบคูปอง โค้ดไม่มีอยู่ (ตรวจแบบไม่สนตัวพิมพ์เล็ก-ใหญ่) | ให้ผู้ใช้ตรวจตัวสะกด · อย่าบอกว่าโค้ดใกล้เคียงคืออะไร (กันการสุ่มเดา) |
| 422 | coupon_not_active | คูปองยังไม่เริ่มหรือหมดอายุ อยู่นอกช่วง starts_at–ends_at หรือถูกปิดใช้งาน | แสดงวันที่เริ่ม/สิ้นสุดจาก error.starts_at / ends_at |
| 422 | coupon_min_not_met | ยอดยังไม่ถึงขั้นต่ำ ยอดที่ร่วมรายการยังไม่ถึง min_subtotal (error.shortfall บอกว่าขาดเท่าไร) | แสดง "ซื้อเพิ่มอีก ฿x" พร้อมสินค้าแนะนำ |
| 422 | coupon_not_applicable | คูปองใช้กับตะกร้านี้ไม่ได้ ไม่มีสินค้าในหมวดที่ร่วมรายการ หรือเงื่อนไขเฉพาะ (เช่น คำสั่งซื้อแรก) ไม่ตรง | แสดงเงื่อนไขจาก GET /v2/coupons/{code} |
| 409 | coupon_usage_exceeded | ใช้สิทธิ์ครบแล้ว ครบจำนวนครั้งต่อบัญชี หรือสิทธิ์รวมของคูปองเต็ม | แนะนำคูปองอื่นที่ใช้ได้จาก GET /v2/promotions?applicable_to=cart_… |
| 409 | coupon_not_combinable | ใช้ร่วมกับคูปองอื่นไม่ได้ คำสั่งซื้อละ 1 คูปอง ยกเว้นคูปองที่ stackable=true ทั้งคู่ | ให้ผู้ใช้เลือกคูปองที่คุ้มกว่า (ดูผลจาก POST /v2/promotions/simulate) |
| 422 | batch_too_large | batch ใหญ่เกิน ส่งรายการเกินจำนวนสูงสุดต่อคำขอ (สินค้า 500 · คูปอง 10,000) | แบ่งเป็นหลาย batch แล้วส่งทีละชุด (ใช้ Idempotency-Key ต่อชุด) |
| 409 | invalid_state_transition | เปลี่ยนสถานะตามลำดับนี้ไม่ได้ การกระทำนี้ไม่อนุญาตในสถานะปัจจุบัน (เช่น แพ็กก่อนชำระ) — error.allowed_actions บอกสิ่งที่ทำได้ | อ่าน status ล่าสุดก่อนเรียก · ดูแผนภาพสถานะในหน้า Order |
| 404 | cart_not_found | ไม่พบตะกร้า cart_id ไม่มี หรือเป็นของลูกค้าคนอื่น | สร้างตะกร้าใหม่ด้วย POST /v2/carts |
| 404 | resource_not_found | ไม่พบข้อมูล id ไม่มีอยู่ ถูกลบ หรือเป็นของบัญชี/ตัวแทนอื่น | ตรวจ id และสภาพแวดล้อม (sandbox กับ production เป็นข้อมูลคนละชุด) |
| 429 | rate_limited | เรียกเกินโควตา จำนวนคำขอเกินโควตาของ key ในช่วงเวลา (ดูหัว RateLimit-*) | รอตาม Retry-After แล้วลองใหม่แบบเว้นระยะเพิ่มขึ้น + jitter · รวมคำขอด้วย endpoint แบบ batch |
ไม่พบรหัสที่ค้นหา
Rate limit — โควตาการเรียก
| ขอบเขต | โควตา | Burst | หมายเหตุ |
|---|---|---|---|
| อ่าน/จำลอง (ต่อ key) | 60–120 ครั้ง/นาที | 20 | simulate ไม่จองสต็อก ไม่นับสิทธิ์ |
| ตรวจโค้ดคูปอง (ต่อ key) | 30 ครั้ง/นาที | — | กันสุ่มเดาโค้ด · 404 ไม่บอกโค้ดใกล้เคียง |
| เขียนโปร (ต่อ key) | 30–60 ครั้ง/นาที | — | หลังบ้าน |
| สร้างโค้ดหลายใบ | 5 คำขอ/นาที · 10,000 ใบ/คำขอ | — | เกิน 1,000 ใบทำเบื้องหลัง |
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-01simulate รับ at และ promotion_ids เพื่อทดสอบโปรที่ตั้งเวลาไว้
- เปลี่ยน
2026-08-01evaluation[] คืนทุกโปรที่พิจารณา (รวมที่ไม่ผ่าน) พร้อม reason_code
- เพิ่ม
2026-08-01webhook promotion.usage_threshold (80%)
- แก้ไข
2025-11-15WOOD50 คิดขั้นต่ำจากยอดทั้งตะกร้าแทนยอดสินค้าที่ร่วม
- ความปลอดภัย
2025-11-15GET /v2/coupons/{code} จำกัด 30 ครั้ง/นาที และไม่บอกโค้ดใกล้เคียง
- เพิ่ม
2025-11-15เพิ่ม POST /v2/promotions/simulate และ /v2/coupons/batch
- เพิ่ม
2025-11-15เพิ่ม discount.kind=buy_x_get_y และ stage=item
- เลิกใช้
2025-11-15ฟิลด์ combinable (boolean ระดับโปร) เลิกใช้ ใช้ stackable แทน
- เปลี่ยน
2024-06-01used_count นับเมื่อชำระสำเร็จ (เดิมนับตอนเช็กเอาต์)
- เพิ่ม
2024-06-01โปรเฉพาะตัวแทน (customer_types: dealer)
เครื่องมือ: ตัวจำลองกฎโปรโมชัน
เลือกตะกร้าตัวอย่าง ประเภทลูกค้า วันที่ และเปิด/ปิดโปรแต่ละตัว (9 โปร) → เห็นว่าโปรไหนใช้ได้ ลำดับการคิด ส่วนลดสะสม และเหตุผลที่ไม่ผ่าน — กฎเดียวกับ POST /v2/promotions/simulate
เครื่องมือนี้คำนวณในเบราว์เซอร์ด้วยกฎและข้อมูลชุดเดียวกับตัวอย่างในหน้า — ไม่ได้เรียก API จริง (แบรนด์สมมติ)
โปรที่เปิดใช้ในการจำลอง (9)
ลำดับการคิด
…