ดึงรายการคำสั่งขาย (Sales Orders) ที่ผู้ใช้งานมีสิทธิ์เข้าถึง
Endpoint นี้เหมาะสำหรับ:
read:sales
Access Token ต้องได้รับ Scope read:sales มิฉะนั้นระบบจะปฏิเสธคำขอ
GET /api/partner/v1/sales
Authorization: Bearer <access_token>
| Parameter | Type | Required | Description |
|---|---|---|---|
| from | string (YYYY-MM-DD) | No | ดึงรายการที่มี order_date ตั้งแต่วันที่กำหนด — ค่าเริ่มต้น: 30 วันก่อน to — ย้อนหลังได้สูงสุด 30 วันจากวันปัจจุบัน |
| to | string (YYYY-MM-DD) | No | ดึงรายการที่มี order_date ไม่เกินวันที่กำหนด — ค่าเริ่มต้น: วันและเวลาปัจจุบัน (UTC) |
| branch_id | string (UUID) | No | กรองตามสาขา สามารถส่งหลายค่าได้ |
| status | string | No | กรองตามสถานะรายการขาย |
| limit | integer | No | จำนวนรายการต่อหน้า (1–200) ค่าเริ่มต้น 50 |
| cursor | string | No | Cursor สำหรับดึงหน้าถัดไป |
ใช้ from และ to เพื่อจำกัดช่วงเวลาที่ต้องการดึงข้อมูล
from ที่เก่ากว่านี้จะได้รับ 400 invalid_requestfrom ถึง to ต้องไม่เกิน 30 วัน — หากส่ง range เกินนี้จะได้รับ 400 invalid_requestfrom: ระบบใช้ 30 วันก่อนหน้า to อัตโนมัติto: ระบบใช้วันและเวลาปัจจุบัน (UTC) อัตโนมัติตัวอย่าง:
GET /api/partner/v1/sales?from=2026-06-01&to=2026-06-15
จะคืนรายการที่มี order_date อยู่ในช่วงวันที่ 1–15 มิถุนายน 2026
สามารถระบุหลายสาขาได้
ตัวอย่าง:
GET /api/partner/v1/sales?branch_id=uuid1&branch_id=uuid2
ระบบจะคืนเฉพาะรายการที่อยู่ในสาขาที่ระบุ
ทุก Access Token จะมีรายการสาขาที่ได้รับอนุญาต (allowed_branch_ids)
หากส่ง branch_id ที่ไม่มีสิทธิ์เข้าถึง ระบบจะไม่คืนข้อมูลของสาขาดังกล่าว
ผลลัพธ์สุดท้ายจะเป็น Intersection ระหว่าง:
Requested Branches
Allowed Branches in Token
ตัวอย่าง:
Token Allowed:
- Branch A
- Branch B
Request:
- Branch B
- Branch C
Result:
- Branch B
รองรับสถานะดังต่อไปนี้
| Status | Description |
|---|---|
| DRAFT | ร่างรายการขาย |
| HELD | พักบิล |
| ACTIVE | กำลังดำเนินการ |
| READY_FOR_PAYMENT | พร้อมชำระเงิน |
| COMPLETED | ขายสำเร็จ |
| REFUNDED | คืนเงินทั้งหมด |
| PARTIAL_REFUNDED | คืนเงินบางส่วน |
| CANCELLED | ยกเลิกรายการ |
| EXCHANGED | เปลี่ยนสินค้า |
| VOIDED | Void รายการ |
ตัวอย่าง:
GET /api/partner/v1/sales?status=COMPLETED
Endpoint นี้ใช้ Cursor-based Pagination เพื่อรองรับข้อมูลจำนวนมาก
ตัวอย่าง Request:
GET /api/partner/v1/sales?limit=100
ตัวอย่าง Response:
{
"pagination": {
"next_cursor": "eyJpZCI6IjEyMyJ9",
"has_more": true,
"limit": 100
}
}
หาก has_more เป็น true ให้เรียก Request ถัดไปโดยใช้ next_cursor
GET /api/partner/v1/sales?cursor=eyJpZCI6IjEyMyJ9
ค่า Cursor เป็น Opaque Value
Partner ไม่ควรอ่าน แก้ไข หรือสร้าง Cursor เอง
ควรส่งค่าที่ได้รับจาก API กลับมาตรง ๆ เท่านั้น
curl -X GET \
"https://<host>/api/partner/v1/sales?from=2026-06-01&to=2026-06-30&limit=50" \
-H "Authorization: Bearer <access_token>"
{
"data": [
{
"id": "4e3509ea-6e79-4243-b861-2d6d96e22af3",
"order_number": "ORD493736",
"branch_id": "b1f85720-71cf-420e-a584-e36b75d3fd20",
"customer_id": null,
"order_date": "2026-06-15T03:22:16.709Z",
"status": "COMPLETED",
"order_type": "DINE_IN",
"subtotal": "120",
"discount_amount": "0",
"tax_amount": "7.85",
"service_charge_amount": "0",
"total_amount": "120",
"paid_amount": "120",
"refunded_amount": "0",
"payment_status": "PAID",
"created_at": "2026-06-15T03:22:16.709Z",
"updated_at": "2026-06-15T03:22:16.709Z"
}
],
"pagination": {
"next_cursor": "...",
"has_more": true,
"limit": 50
}
}
| Field | Type | Description |
|---|---|---|
| id | string (UUID) | Sales Order ID |
| order_number | string | เลขที่คำสั่งขาย เช่น ORD493736 |
| branch_id | string (UUID) | สาขาที่ออกรายการ |
| customer_id | string (UUID) | null | ลูกค้าที่ผูกกับรายการ (ถ้ามี) |
| order_date | string (ISO 8601) | วันและเวลาที่สร้างรายการ |
| status | string | สถานะรายการขาย ดู Status ด้านบน |
| order_type | string | ประเภทการสั่งซื้อ ดู Order Types ด้านล่าง |
| subtotal | string (decimal) | ยอดรวมก่อนหักส่วนลดและภาษี |
| discount_amount | string (decimal) | ส่วนลดรวม |
| tax_amount | string (decimal) | ภาษีรวม |
| service_charge_amount | string (decimal) | ค่าบริการ |
| total_amount | string (decimal) | ยอดรวมสุทธิ |
| paid_amount | string (decimal) | ยอดที่ชำระแล้ว |
| refunded_amount | string (decimal) | ยอดที่คืนเงินแล้ว |
| payment_status | string | สถานะการชำระเงิน ดู Payment Status ด้านล่าง |
| created_at | string (ISO 8601) | เวลาที่สร้าง record |
| updated_at | string (ISO 8601) | เวลาที่แก้ไขล่าสุด |
ฟิลด์เกี่ยวกับจำนวนเงินทั้งหมดถูกส่งกลับในรูปแบบ Decimal String
ตัวอย่าง:
{
"subtotal": "120",
"tax_amount": "7.85",
"total_amount": "127.85"
}
เหตุผลที่ใช้ String แทน Number คือเพื่อป้องกันปัญหาความคลาดเคลื่อนของ Floating Point ในแต่ละภาษาโปรแกรม
Partner ควรใช้ Decimal Library หรือ Big Number Library ในการคำนวณทางการเงิน
| Value | Description |
|---|---|
| DINE_IN | รับประทานที่ร้าน |
| TAKEAWAY | ซื้อกลับบ้าน |
| DELIVERY | จัดส่ง |
| Value | Description |
|---|---|
| UNPAID | ยังไม่ชำระเงิน |
| PARTIAL | ชำระบางส่วน |
| PAID | ชำระครบแล้ว |
| REFUNDED | คืนเงินแล้ว |
ฟิลด์วันที่และเวลาใช้มาตรฐาน ISO 8601 (UTC)
ตัวอย่าง:
2026-06-15T03:22:16.709Z
Partner ควรแปลงเป็น Time Zone ที่ต้องการก่อนนำไปแสดงผล
สำหรับการดึงข้อมูลจำนวนมาก แนะนำให้:
from และ to ไม่เกิน 30 วันต่อ requestlimit=200 ซึ่งเป็นค่าสูงสุดที่รองรับ เพื่อลดจำนวน requesthas_more จะเป็น falsesales.order.created, sales.order.completed ฯลฯ) แทนการ Poll ซ้ำ เนื่องจาก API ไม่รองรับ filter ด้วย updated_atวิธีนี้ช่วยลดปริมาณข้อมูลที่ต้องดึงซ้ำและเพิ่มประสิทธิภาพในการซิงค์ข้อมูลระยะยาว