{"openapi":"3.0.3","info":{"title":"Ket Bill Open API","description":"Ket Bill Open API","version":"1.0.0"},"tags":[{"name":"Documents","description":"เอกสาร (ใบเสนอราคา/ใบแจ้งหนี้/ใบเสร็จ ฯลฯ)"},{"name":"Clients","description":"ลูกค้า/ผู้ขาย"},{"name":"Products","description":"สินค้า/บริการ"},{"name":"Me","description":"ข้อมูลบริษัทที่ token ผูกอยู่ (สำหรับโชว์สถานะการเชื่อมต่อ)"},{"name":"Share links","description":"ลิงก์แชร์เอกสารแบบสาธารณะ (สร้าง/ดู/เพิกถอน — scope documents:read)"},{"name":"OAuth 2.1","description":"OAuth 2.1 authorization-code + PKCE (hand-authored; flow ผ่าน browser)"}],"paths":{"/v1/documents":{"get":{"parameters":[{"description":"หน้า (เริ่มที่ 1) / page","schema":{"default":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"default":1,"description":"หน้า (เริ่มที่ 1) / page","type":"number"}]},"in":"query","name":"page","required":false},{"description":"จำนวนต่อหน้า / page size","schema":{"default":20,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"default":20,"description":"จำนวนต่อหน้า / page size","type":"number"}]},"in":"query","name":"limit","required":false},{"description":"คำค้น / search term","schema":{"type":"string"},"in":"query","name":"q","required":false},{"description":"กรองตามชนิดเอกสาร","schema":{"type":"string"},"in":"query","name":"type","required":false},{"schema":{"type":"string"},"in":"query","name":"status","required":false},{"description":"กรองด้วยเลขออเดอร์ต้นทาง — ตรงตัวทั้งค่า (คำค้น q ยังหาแบบบางส่วนได้)","schema":{"type":"string","example":"SO-2026-0001"},"in":"query","name":"sourceOrderCode","required":false},{"schema":{"type":"string","enum":["true","false"]},"in":"query","name":"includeTotal","required":false}],"operationId":"getV1Documents","tags":["Documents"],"summary":"รายการเอกสาร (own-company)","description":"**ต้องมี scope `documents:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · `total` เป็นยอดจริงเฉพาะเมื่อส่ง `includeTotal=true` — ถ้าไม่ส่ง จะได้แค่ตัวชี้ว่ามีหน้าถัดไป (`skip + limit + 1` เมื่อยังมีข้อมูลต่อ) ห้ามนำไปคำนวณจำนวนหน้า · แต่ละแถวเป็นโครงย่อ ไม่ใช่เอกสารเต็ม","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"รายการเอกสารแบบแบ่งหน้า","content":{"application/json":{"schema":{"additionalProperties":true,"description":"รายการเอกสาร · ตัวเลขเงินเป็น **string** ทุกตัว (Prisma Decimal) และตัดศูนย์ท้ายทิ้ง — '86000.50' คืนเป็น '86000.5'","type":"object","required":["items","total","page","limit"],"properties":{"items":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","companyId","type","number","status","creationSource","sourceOrderCode","issueDate","dueDate","expiryDate","customerId","vendorId","subtotal","vatAmount","grandTotal","paidAmount","remainingAmount","paymentMethod","parentRefs","customer","vendor","_count"],"properties":{"id":{"multipleOf":1,"example":8,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"type":{"example":"QUOTATION","anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"example":"QT-2026-05-0015","type":"string"},"status":{"example":"WAIT_ACCEPTED","anyOf":[{"const":"DRAFT","type":"string"},{"const":"ISSUED","type":"string"},{"const":"PARTIALLY_ISSUED","type":"string"},{"const":"SUCCESS","type":"string"},{"const":"WAIT_ACCEPTED","type":"string"},{"const":"ACCEPTED","type":"string"},{"const":"REJECTED","type":"string"},{"const":"WAIT_PAID","type":"string"},{"const":"PARTIALLY_PAID","type":"string"},{"const":"PAID","type":"string"},{"const":"OVERDUE","type":"string"},{"const":"CANCELLED","type":"string"},{"const":"CONVERTED","type":"string"}]},"creationSource":{"example":"API","anyOf":[{"const":"BACKOFFICE","type":"string"},{"const":"API","type":"string"}]},"sourceOrderCode":{"anyOf":[{"description":"เลขออเดอร์ต้นทางจากระบบขาย (การ์ด 74)","type":"string"},{"type":"null"}]},"issueDate":{"format":"date-time","description":"วันที่ออกเอกสาร","type":"string"},"dueDate":{"anyOf":[{"format":"date-time","description":"วันครบกำหนดชำระ","type":"string"},{"type":"null"}]},"expiryDate":{"anyOf":[{"format":"date-time","description":"วันหมดอายุ (ใบเสนอราคา)","type":"string"},{"type":"null"}]},"customerId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"vendorId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"subtotal":{"description":"ยอดก่อนภาษี","example":"1354000","type":"string"},"vatAmount":{"description":"ภาษีมูลค่าเพิ่ม","example":"1354000","type":"string"},"grandTotal":{"description":"ยอดรวมสุทธิ","example":"1354000","type":"string"},"paidAmount":{"description":"ยอดที่ชำระแล้ว","example":"1354000","type":"string"},"remainingAmount":{"description":"ยอดคงเหลือ","example":"1354000","type":"string"},"paymentMethod":{"anyOf":[{"type":"string"},{"type":"null"}]},"parentRefs":{"description":"เอกสารต้นทางแบบย่อ (แสดงว่าแปลงมาจากอะไร)","type":"array","items":{"additionalProperties":true,"type":"object","required":["parent"],"properties":{"parent":{"additionalProperties":true,"type":"object","required":["type","number"],"properties":{"type":{"anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"type":"string"}}}}}},"customer":{"anyOf":[{"additionalProperties":true,"type":"object","required":["id","legalName","taxId"],"properties":{"id":{"multipleOf":1,"type":"number"},"legalName":{"example":"บริษัท เคาน์เตอร์เซอร์วิส จำกัด","type":"string"},"taxId":{"anyOf":[{"example":"0105540000456","type":"string"},{"type":"null"}]}}},{"type":"null"}]},"vendor":{"anyOf":[{"additionalProperties":true,"type":"object","required":["id","legalName","taxId"],"properties":{"id":{"multipleOf":1,"type":"number"},"legalName":{"example":"บริษัท เคาน์เตอร์เซอร์วิส จำกัด","type":"string"},"taxId":{"anyOf":[{"example":"0105540000456","type":"string"},{"type":"null"}]}}},{"type":"null"}]},"_count":{"additionalProperties":true,"type":"object","required":["lines"],"properties":{"lines":{"multipleOf":1,"description":"จำนวนบรรทัดในเอกสาร","type":"number"}}}}}},"total":{"multipleOf":1,"description":"ส่ง includeTotal=true → ยอดจริงทั้งหมดที่ตรงเงื่อนไข · ไม่ส่ง → เป็นเพียงตัวชี้ว่ามีหน้าถัดไป (skip + limit + 1 เมื่อยังมีข้อมูลต่อ) **ห้ามใช้คำนวณจำนวนหน้า**","example":16,"type":"number"},"page":{"multipleOf":1,"example":1,"type":"number"},"limit":{"multipleOf":1,"example":20,"type":"number"}}}}}}}},"post":{"parameters":[],"operationId":"postV1Documents","tags":["Documents"],"summary":"สร้างเอกสารฉบับร่าง (เข้าคิว — ตอบ 202)","description":"**ต้องมี scope `documents:create`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · **เป็น asynchronous**: ตอบ `202 Accepted` พร้อม `job_id` และ header `Location: /v1/documents/jobs/{jobId}` ทันที ไม่ได้คืนตัวเอกสาร · 202 **ไม่การันตี**ว่าเอกสารจะเกิด — การตรวจเชิงธุรกิจ (VAT policy, เอกสารแม่, โควตา) เกิดหลังคิว ต้อง poll `GET /v1/documents/jobs/{jobId}` จนได้ `DONE` หรือ `FAILED` · ส่ง header `Idempotency-Key` เพื่อกันสร้างซ้ำเวลา retry (ไม่ส่ง = derive จาก body; หน้าต่างกันซ้ำ 10 นาที) · body ผิดรูปแบบยังตอบ 400/422 ทันทีเหมือนเดิม · คิวไม่พร้อมใช้งาน → 503 `QUEUE_UNAVAILABLE` (retry ด้วย key เดิมได้ทันที ไม่มีเอกสารค้าง)","security":[{"bearerAuth":[]}],"responses":{"202":{"description":"รับงานเข้าคิวแล้ว","headers":{"Location":{"description":"URL ของ job ที่สร้างขึ้น","schema":{"type":"string"}}},"content":{"application/json":{"schema":{"description":"งานถูกรับเข้าคิวแล้ว — ติดตามผลที่ GET /v1/documents/jobs/{jobId}","type":"object","required":["job_id","status"],"properties":{"job_id":{"example":"job_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"status":{"const":"QUEUED","type":"string"}}}}}},"503":{"description":"คิวไม่พร้อมใช้งาน (QUEUE_UNAVAILABLE)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"เอกสารฉบับร่างที่จะสร้าง (ฟิลด์ตรงกับ documentCreateSchema)","type":"object","required":["companyId","type"],"properties":{"companyId":{"description":"จะถูก override เป็นบริษัทของ token เสมอ (own-company)","example":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"description":"จะถูก override เป็นบริษัทของ token เสมอ (own-company)","example":1,"type":"number"}]},"type":{"example":"QUOTATION","anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"customerId":{"example":42,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":42,"type":"number"}]},"vendorId":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"issueDate":{"format":"date-time","type":"string"},"dueDate":{"format":"date-time","type":"string"},"expiryDate":{"format":"date-time","type":"string"},"receiptPayment":{},"vatInclusive":{"default":false,"type":"boolean"},"taxInvoiceCombined":{"type":"boolean"},"vatRate":{"default":7,"type":"number"},"whtMode":{"default":"NONE","anyOf":[{"const":"NONE","type":"string"},{"const":"DOCUMENT_LEVEL","type":"string"},{"const":"LINE_LEVEL","type":"string"}]},"whtRate":{"type":"number"},"whtAmount":{"type":"number"},"whtRateId":{"type":"string"},"discountAmount":{"type":"number"},"discountPercent":{"type":"number"},"paymentTerms":{"type":"string"},"paymentMethod":{"type":"string"},"referenceCode":{"type":"string"},"sourceOrderCode":{"description":"เลขออเดอร์ต้นทางจากระบบขาย (การ์ด 74)","example":"SO-2026-0001","type":"string"},"remark":{"type":"string"},"internalNote":{"type":"string"},"lines":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["lineNo","description","quantity","unit","unitPrice","vatType"],"properties":{"lineNo":{"example":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1,"type":"number"}]},"productId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"sourceLineId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"productSnapshot":{},"description":{"example":"สินค้า A","type":"string"},"note":{"type":"string"},"productDetail":{"type":"string"},"quantity":{"example":2,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":2,"type":"number"}]},"unit":{"example":"ชิ้น","type":"string"},"unitPrice":{"example":150,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":150,"type":"number"}]},"discountAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"discountPercent":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"vatType":{"example":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"whtRate":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtRateId":{"type":"string"},"whtCategory":{"type":"string"},"whtIncomeType":{"description":"WHT_CERT: ประเภทเงินได้ ม.40","anyOf":[{"const":"M40_1","type":"string"},{"const":"M40_2","type":"string"},{"const":"M40_3","type":"string"},{"const":"M40_4A","type":"string"},{"const":"M40_4B","type":"string"},{"const":"M40_5","type":"string"},{"const":"M40_6","type":"string"},{"const":"M40_7","type":"string"},{"const":"M40_8","type":"string"},{"const":"OTHER","type":"string"}]},"whtDividendCase":{"description":"WHT_CERT: กรณีย่อยของข้อ 4(ข) — บังคับเมื่อ whtIncomeType = M40_4B","anyOf":[{"const":"1.1","type":"string"},{"const":"1.2","type":"string"},{"const":"1.3","type":"string"},{"const":"1.4","type":"string"},{"const":"2.1","type":"string"},{"const":"2.2","type":"string"},{"const":"2.3","type":"string"},{"const":"2.4","type":"string"},{"const":"2.5","type":"string"}]},"whtPaidOn":{"format":"date-time","description":"WHT_CERT: วันที่จ่ายเงินได้ของรายการนี้","type":"string"}}}},"whtCertBookNo":{"description":"WHT_CERT: เล่มที่","type":"string"},"whtCertPndForm":{"anyOf":[{"const":"PND1A","type":"string"},{"const":"PND1A_SPECIAL","type":"string"},{"const":"PND2","type":"string"},{"const":"PND3","type":"string"},{"const":"PND2A","type":"string"},{"const":"PND3A","type":"string"},{"const":"PND53","type":"string"}]},"whtCertFormSeqNo":{"description":"WHT_CERT: ลำดับที่ในแบบ","type":"string"},"whtCertRemitMethod":{"anyOf":[{"const":"WITHHELD","type":"string"},{"const":"PAY_FOREVER","type":"string"},{"const":"PAY_ONCE","type":"string"},{"const":"OTHER","type":"string"}]},"whtCertRemitOther":{"type":"string"},"whtCertFundGpf":{"type":"number"},"whtCertFundSso":{"type":"number"},"whtCertFundPvd":{"type":"number"},"whtCertDividendRate":{"description":"WHT_CERT: 4(ข)(1.4) อัตราอื่น ๆ ของกำไรสุทธิ","type":"number"},"whtCertDividendOther":{"description":"WHT_CERT: 4(ข)(2.5) อื่น ๆ (ระบุ)","type":"string"},"parentDocumentId":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"parentDocumentIds":{"type":"array","items":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]}}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"เอกสารฉบับร่างที่จะสร้าง (ฟิลด์ตรงกับ documentCreateSchema)","type":"object","required":["companyId","type"],"properties":{"companyId":{"description":"จะถูก override เป็นบริษัทของ token เสมอ (own-company)","example":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"description":"จะถูก override เป็นบริษัทของ token เสมอ (own-company)","example":1,"type":"number"}]},"type":{"example":"QUOTATION","anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"customerId":{"example":42,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":42,"type":"number"}]},"vendorId":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"issueDate":{"format":"date-time","type":"string"},"dueDate":{"format":"date-time","type":"string"},"expiryDate":{"format":"date-time","type":"string"},"receiptPayment":{},"vatInclusive":{"default":false,"type":"boolean"},"taxInvoiceCombined":{"type":"boolean"},"vatRate":{"default":7,"type":"number"},"whtMode":{"default":"NONE","anyOf":[{"const":"NONE","type":"string"},{"const":"DOCUMENT_LEVEL","type":"string"},{"const":"LINE_LEVEL","type":"string"}]},"whtRate":{"type":"number"},"whtAmount":{"type":"number"},"whtRateId":{"type":"string"},"discountAmount":{"type":"number"},"discountPercent":{"type":"number"},"paymentTerms":{"type":"string"},"paymentMethod":{"type":"string"},"referenceCode":{"type":"string"},"sourceOrderCode":{"description":"เลขออเดอร์ต้นทางจากระบบขาย (การ์ด 74)","example":"SO-2026-0001","type":"string"},"remark":{"type":"string"},"internalNote":{"type":"string"},"lines":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["lineNo","description","quantity","unit","unitPrice","vatType"],"properties":{"lineNo":{"example":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1,"type":"number"}]},"productId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"sourceLineId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"productSnapshot":{},"description":{"example":"สินค้า A","type":"string"},"note":{"type":"string"},"productDetail":{"type":"string"},"quantity":{"example":2,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":2,"type":"number"}]},"unit":{"example":"ชิ้น","type":"string"},"unitPrice":{"example":150,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":150,"type":"number"}]},"discountAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"discountPercent":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"vatType":{"example":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"whtRate":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtRateId":{"type":"string"},"whtCategory":{"type":"string"},"whtIncomeType":{"description":"WHT_CERT: ประเภทเงินได้ ม.40","anyOf":[{"const":"M40_1","type":"string"},{"const":"M40_2","type":"string"},{"const":"M40_3","type":"string"},{"const":"M40_4A","type":"string"},{"const":"M40_4B","type":"string"},{"const":"M40_5","type":"string"},{"const":"M40_6","type":"string"},{"const":"M40_7","type":"string"},{"const":"M40_8","type":"string"},{"const":"OTHER","type":"string"}]},"whtDividendCase":{"description":"WHT_CERT: กรณีย่อยของข้อ 4(ข) — บังคับเมื่อ whtIncomeType = M40_4B","anyOf":[{"const":"1.1","type":"string"},{"const":"1.2","type":"string"},{"const":"1.3","type":"string"},{"const":"1.4","type":"string"},{"const":"2.1","type":"string"},{"const":"2.2","type":"string"},{"const":"2.3","type":"string"},{"const":"2.4","type":"string"},{"const":"2.5","type":"string"}]},"whtPaidOn":{"format":"date-time","description":"WHT_CERT: วันที่จ่ายเงินได้ของรายการนี้","type":"string"}}}},"whtCertBookNo":{"description":"WHT_CERT: เล่มที่","type":"string"},"whtCertPndForm":{"anyOf":[{"const":"PND1A","type":"string"},{"const":"PND1A_SPECIAL","type":"string"},{"const":"PND2","type":"string"},{"const":"PND3","type":"string"},{"const":"PND2A","type":"string"},{"const":"PND3A","type":"string"},{"const":"PND53","type":"string"}]},"whtCertFormSeqNo":{"description":"WHT_CERT: ลำดับที่ในแบบ","type":"string"},"whtCertRemitMethod":{"anyOf":[{"const":"WITHHELD","type":"string"},{"const":"PAY_FOREVER","type":"string"},{"const":"PAY_ONCE","type":"string"},{"const":"OTHER","type":"string"}]},"whtCertRemitOther":{"type":"string"},"whtCertFundGpf":{"type":"number"},"whtCertFundSso":{"type":"number"},"whtCertFundPvd":{"type":"number"},"whtCertDividendRate":{"description":"WHT_CERT: 4(ข)(1.4) อัตราอื่น ๆ ของกำไรสุทธิ","type":"number"},"whtCertDividendOther":{"description":"WHT_CERT: 4(ข)(2.5) อื่น ๆ (ระบุ)","type":"string"},"parentDocumentId":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"parentDocumentIds":{"type":"array","items":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]}}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"เอกสารฉบับร่างที่จะสร้าง (ฟิลด์ตรงกับ documentCreateSchema)","type":"object","required":["companyId","type"],"properties":{"companyId":{"description":"จะถูก override เป็นบริษัทของ token เสมอ (own-company)","example":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"description":"จะถูก override เป็นบริษัทของ token เสมอ (own-company)","example":1,"type":"number"}]},"type":{"example":"QUOTATION","anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"customerId":{"example":42,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":42,"type":"number"}]},"vendorId":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"issueDate":{"format":"date-time","type":"string"},"dueDate":{"format":"date-time","type":"string"},"expiryDate":{"format":"date-time","type":"string"},"receiptPayment":{},"vatInclusive":{"default":false,"type":"boolean"},"taxInvoiceCombined":{"type":"boolean"},"vatRate":{"default":7,"type":"number"},"whtMode":{"default":"NONE","anyOf":[{"const":"NONE","type":"string"},{"const":"DOCUMENT_LEVEL","type":"string"},{"const":"LINE_LEVEL","type":"string"}]},"whtRate":{"type":"number"},"whtAmount":{"type":"number"},"whtRateId":{"type":"string"},"discountAmount":{"type":"number"},"discountPercent":{"type":"number"},"paymentTerms":{"type":"string"},"paymentMethod":{"type":"string"},"referenceCode":{"type":"string"},"sourceOrderCode":{"description":"เลขออเดอร์ต้นทางจากระบบขาย (การ์ด 74)","example":"SO-2026-0001","type":"string"},"remark":{"type":"string"},"internalNote":{"type":"string"},"lines":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["lineNo","description","quantity","unit","unitPrice","vatType"],"properties":{"lineNo":{"example":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1,"type":"number"}]},"productId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"sourceLineId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"productSnapshot":{},"description":{"example":"สินค้า A","type":"string"},"note":{"type":"string"},"productDetail":{"type":"string"},"quantity":{"example":2,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":2,"type":"number"}]},"unit":{"example":"ชิ้น","type":"string"},"unitPrice":{"example":150,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":150,"type":"number"}]},"discountAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"discountPercent":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"vatType":{"example":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"whtRate":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtRateId":{"type":"string"},"whtCategory":{"type":"string"},"whtIncomeType":{"description":"WHT_CERT: ประเภทเงินได้ ม.40","anyOf":[{"const":"M40_1","type":"string"},{"const":"M40_2","type":"string"},{"const":"M40_3","type":"string"},{"const":"M40_4A","type":"string"},{"const":"M40_4B","type":"string"},{"const":"M40_5","type":"string"},{"const":"M40_6","type":"string"},{"const":"M40_7","type":"string"},{"const":"M40_8","type":"string"},{"const":"OTHER","type":"string"}]},"whtDividendCase":{"description":"WHT_CERT: กรณีย่อยของข้อ 4(ข) — บังคับเมื่อ whtIncomeType = M40_4B","anyOf":[{"const":"1.1","type":"string"},{"const":"1.2","type":"string"},{"const":"1.3","type":"string"},{"const":"1.4","type":"string"},{"const":"2.1","type":"string"},{"const":"2.2","type":"string"},{"const":"2.3","type":"string"},{"const":"2.4","type":"string"},{"const":"2.5","type":"string"}]},"whtPaidOn":{"format":"date-time","description":"WHT_CERT: วันที่จ่ายเงินได้ของรายการนี้","type":"string"}}}},"whtCertBookNo":{"description":"WHT_CERT: เล่มที่","type":"string"},"whtCertPndForm":{"anyOf":[{"const":"PND1A","type":"string"},{"const":"PND1A_SPECIAL","type":"string"},{"const":"PND2","type":"string"},{"const":"PND3","type":"string"},{"const":"PND2A","type":"string"},{"const":"PND3A","type":"string"},{"const":"PND53","type":"string"}]},"whtCertFormSeqNo":{"description":"WHT_CERT: ลำดับที่ในแบบ","type":"string"},"whtCertRemitMethod":{"anyOf":[{"const":"WITHHELD","type":"string"},{"const":"PAY_FOREVER","type":"string"},{"const":"PAY_ONCE","type":"string"},{"const":"OTHER","type":"string"}]},"whtCertRemitOther":{"type":"string"},"whtCertFundGpf":{"type":"number"},"whtCertFundSso":{"type":"number"},"whtCertFundPvd":{"type":"number"},"whtCertDividendRate":{"description":"WHT_CERT: 4(ข)(1.4) อัตราอื่น ๆ ของกำไรสุทธิ","type":"number"},"whtCertDividendOther":{"description":"WHT_CERT: 4(ข)(2.5) อื่น ๆ (ระบุ)","type":"string"},"parentDocumentId":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"parentDocumentIds":{"type":"array","items":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]}}}}}}}}},"/v1/documents/{id}":{"get":{"parameters":[{"description":"document id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"document id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"getV1DocumentsById","tags":["Documents"],"summary":"เอกสารรายฉบับ","description":"**ต้องมี scope `documents:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · คืนเอกสารเต็มฉบับ · id ต้องเป็นจำนวนเต็มตั้งแต่ 1 ขึ้นไป ไม่ใช่ → `422` · ไม่พบ/คนละบริษัท → `404 NOT_FOUND`","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"เอกสารรายฉบับ","content":{"application/json":{"schema":{"additionalProperties":true,"description":"เอกสารรายฉบับพร้อมบรรทัด คู่ค้า ความสัมพันธ์ และสิทธิ์การทำงาน · ตัวเลขเงินเป็น **string** ทุกตัว (Prisma Decimal) และตัดศูนย์ท้ายทิ้ง — '86000.50' คืนเป็น '86000.5'","type":"object","required":["id","companyId","type","number","status","creationSource","issueDate","dueDate","expiryDate","referenceCode","sourceOrderCode","customerId","vendorId","issuerSnapshot","partySnapshot","issuerSetting","currency","exchangeRate","vatInclusive","taxInvoiceCombined","vatRate","whtRate","whtRateId","whtMode","whtCertBookNo","whtCertPndForm","whtCertFormSeqNo","whtCertRemitMethod","whtCertRemitOther","whtCertFundGpf","whtCertFundSso","whtCertFundPvd","whtCertDividendRate","whtCertDividendOther","subtotal","discountAmount","discountPercent","taxableAmount","vatAmount","whtAmount","grandTotal","grandTotalText","paidAmount","remainingAmount","paymentDate","paymentBankRef","paymentNote","remark","internalNote","paymentTerms","paymentMethod","receivedDate","chequeNo","chequeDate","chequeBank","voidedAt","voidedReason","createdById","updatedById","createdAt","updatedAt","deletedAt","editingByUserId","editingByName","editingExpiresAt","lines","payments","receiptPayments","parentRefs","childRefs","customer","vendor","attachments","actionPolicy","lineage","relatedDocuments","issuableRemaining"],"properties":{"id":{"multipleOf":1,"example":8,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"type":{"example":"QUOTATION","anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"example":"QT-2026-05-0015","type":"string"},"status":{"example":"WAIT_ACCEPTED","anyOf":[{"const":"DRAFT","type":"string"},{"const":"ISSUED","type":"string"},{"const":"PARTIALLY_ISSUED","type":"string"},{"const":"SUCCESS","type":"string"},{"const":"WAIT_ACCEPTED","type":"string"},{"const":"ACCEPTED","type":"string"},{"const":"REJECTED","type":"string"},{"const":"WAIT_PAID","type":"string"},{"const":"PARTIALLY_PAID","type":"string"},{"const":"PAID","type":"string"},{"const":"OVERDUE","type":"string"},{"const":"CANCELLED","type":"string"},{"const":"CONVERTED","type":"string"}]},"creationSource":{"example":"API","anyOf":[{"const":"BACKOFFICE","type":"string"},{"const":"API","type":"string"}]},"issueDate":{"format":"date-time","description":"วันที่ออกเอกสาร","type":"string"},"dueDate":{"anyOf":[{"format":"date-time","description":"วันครบกำหนดชำระ","type":"string"},{"type":"null"}]},"expiryDate":{"anyOf":[{"format":"date-time","description":"วันหมดอายุ","type":"string"},{"type":"null"}]},"referenceCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"sourceOrderCode":{"anyOf":[{"description":"เลขออเดอร์ต้นทางจากระบบขาย (การ์ด 74)","type":"string"},{"type":"null"}]},"customerId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"vendorId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"issuerSnapshot":{"additionalProperties":true,"description":"ข้อมูลผู้ออกเอกสารตอนที่ออก (แช่แข็งไว้)","type":"object","properties":{}},"partySnapshot":{"additionalProperties":true,"description":"ข้อมูลคู่ค้าตอนที่ออกเอกสาร (แช่แข็งไว้)","type":"object","properties":{}},"issuerSetting":{"anyOf":[{"additionalProperties":true,"description":"ค่าตั้งบริษัทที่ใช้ตอนออกเอกสาร","type":"object","properties":{}},{"type":"null"}]},"currency":{"example":"THB","type":"string"},"exchangeRate":{"description":"อัตราแลกเปลี่ยน","example":"1354000","type":"string"},"vatInclusive":{"type":"boolean"},"taxInvoiceCombined":{"description":"ใบเสร็จรับเงินที่ออกใบกำกับภาษีควบในใบเดียว","type":"boolean"},"vatRate":{"description":"อัตรา VAT (%)","example":"1354000","type":"string"},"whtRate":{"anyOf":[{"description":"อัตราหัก ณ ที่จ่ายระดับเอกสาร (%)","example":"1354000","type":"string"},{"type":"null"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtMode":{"example":"NONE","anyOf":[{"const":"NONE","type":"string"},{"const":"DOCUMENT_LEVEL","type":"string"},{"const":"LINE_LEVEL","type":"string"}]},"whtCertBookNo":{"anyOf":[{"description":"WHT_CERT: เล่มที่ (ผู้ใช้กรอกเอง)","type":"string"},{"type":"null"}]},"whtCertPndForm":{"anyOf":[{"description":"WHT_CERT: แบบ ภ.ง.ด. ที่ยื่นคู่กัน","anyOf":[{"const":"PND1A","type":"string"},{"const":"PND1A_SPECIAL","type":"string"},{"const":"PND2","type":"string"},{"const":"PND3","type":"string"},{"const":"PND2A","type":"string"},{"const":"PND3A","type":"string"},{"const":"PND53","type":"string"}]},{"type":"null"}]},"whtCertFormSeqNo":{"anyOf":[{"description":"WHT_CERT: ลำดับที่ในแบบ","type":"string"},{"type":"null"}]},"whtCertRemitMethod":{"anyOf":[{"description":"WHT_CERT: วิธีการนำส่งเงินภาษี","anyOf":[{"const":"WITHHELD","type":"string"},{"const":"PAY_FOREVER","type":"string"},{"const":"PAY_ONCE","type":"string"},{"const":"OTHER","type":"string"}]},{"type":"null"}]},"whtCertRemitOther":{"anyOf":[{"description":"WHT_CERT: ข้อความของวิธีการนำส่งแบบอื่น ๆ","type":"string"},{"type":"null"}]},"whtCertFundGpf":{"anyOf":[{"description":"WHT_CERT: กบข. / กสจ. / กองทุนสงเคราะห์ครูโรงเรียนเอกชน","example":"1354000","type":"string"},{"type":"null"}]},"whtCertFundSso":{"anyOf":[{"description":"WHT_CERT: กองทุนประกันสังคม","example":"1354000","type":"string"},{"type":"null"}]},"whtCertFundPvd":{"anyOf":[{"description":"WHT_CERT: กองทุนสำรองเลี้ยงชีพ","example":"1354000","type":"string"},{"type":"null"}]},"whtCertDividendRate":{"anyOf":[{"description":"WHT_CERT: 4(ข)(1.4) อัตราอื่น ๆ ของกำไรสุทธิ","example":"1354000","type":"string"},{"type":"null"}]},"whtCertDividendOther":{"anyOf":[{"description":"WHT_CERT: 4(ข)(2.5) อื่น ๆ (ระบุ)","type":"string"},{"type":"null"}]},"subtotal":{"description":"ยอดก่อนภาษี","example":"1354000","type":"string"},"discountAmount":{"description":"ส่วนลด (บาท)","example":"1354000","type":"string"},"discountPercent":{"anyOf":[{"description":"ส่วนลด (%)","example":"1354000","type":"string"},{"type":"null"}]},"taxableAmount":{"description":"ฐานภาษี","example":"1354000","type":"string"},"vatAmount":{"description":"ภาษีมูลค่าเพิ่ม","example":"1354000","type":"string"},"whtAmount":{"description":"ยอดหัก ณ ที่จ่าย","example":"1354000","type":"string"},"grandTotal":{"description":"ยอดรวมสุทธิ","example":"1354000","type":"string"},"grandTotalText":{"anyOf":[{"description":"ยอดรวมเป็นตัวอักษร","type":"string"},{"type":"null"}]},"paidAmount":{"description":"ยอดที่ชำระแล้ว","example":"1354000","type":"string"},"remainingAmount":{"description":"ยอดคงเหลือ","example":"1354000","type":"string"},"paymentDate":{"anyOf":[{"format":"date-time","description":"วันที่ชำระ","type":"string"},{"type":"null"}]},"paymentBankRef":{"anyOf":[{"type":"string"},{"type":"null"}]},"paymentNote":{"anyOf":[{"type":"string"},{"type":"null"}]},"remark":{"anyOf":[{"description":"หมายเหตุที่พิมพ์บนเอกสาร","type":"string"},{"type":"null"}]},"internalNote":{"anyOf":[{"description":"หมายเหตุภายใน ไม่พิมพ์บนเอกสาร","type":"string"},{"type":"null"}]},"paymentTerms":{"anyOf":[{"example":"30 วันหลังตอบรับ","type":"string"},{"type":"null"}]},"paymentMethod":{"anyOf":[{"type":"string"},{"type":"null"}]},"receivedDate":{"anyOf":[{"format":"date-time","description":"วันที่รับของ","type":"string"},{"type":"null"}]},"chequeNo":{"anyOf":[{"type":"string"},{"type":"null"}]},"chequeDate":{"anyOf":[{"format":"date-time","description":"วันที่บนเช็ค","type":"string"},{"type":"null"}]},"chequeBank":{"anyOf":[{"type":"string"},{"type":"null"}]},"voidedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ยกเลิก","type":"string"},{"type":"null"}]},"voidedReason":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdById":{"anyOf":[{"multipleOf":1,"description":"null เมื่อสร้างด้วย API key (ไม่ใช่คน)","type":"number"},{"type":"null"}]},"updatedById":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]},"editingByUserId":{"anyOf":[{"multipleOf":1,"description":"ผู้ที่กำลังแก้เอกสารนี้ในแอป","type":"number"},{"type":"null"}]},"editingByName":{"anyOf":[{"type":"string"},{"type":"null"}]},"editingExpiresAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ lock การแก้ในแอปหมดอายุ","type":"string"},{"type":"null"}]},"lines":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","documentId","lineNo","productId","productSnapshot","description","note","productDetail","quantity","unit","unitPrice","discountAmount","discountPercent","vatType","vatAmount","whtRate","whtRateId","whtCategory","whtIncomeType","whtDividendCase","whtPaidOn","whtAmount","lineTotal","sourceLineId","createdAt","updatedAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"documentId":{"multipleOf":1,"type":"number"},"lineNo":{"multipleOf":1,"example":1,"type":"number"},"productId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"productSnapshot":{"anyOf":[{"additionalProperties":true,"type":"object","properties":{"sku":{"anyOf":[{"type":"string"},{"type":"null"}]},"name":{"type":"string"},"unit":{"type":"string"},"vatType":{"anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"productType":{"anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]}}},{"type":"null"}]},"description":{"example":"สินค้า A","type":"string"},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"productDetail":{"anyOf":[{"type":"string"},{"type":"null"}]},"quantity":{"description":"จำนวน","example":"1354000","type":"string"},"unit":{"example":"ชิ้น","type":"string"},"unitPrice":{"description":"ราคาต่อหน่วย","example":"1354000","type":"string"},"discountAmount":{"description":"ส่วนลด (บาท)","example":"1354000","type":"string"},"discountPercent":{"anyOf":[{"description":"ส่วนลด (%)","example":"1354000","type":"string"},{"type":"null"}]},"vatType":{"example":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"vatAmount":{"description":"ภาษีของบรรทัดนี้","example":"1354000","type":"string"},"whtRate":{"anyOf":[{"description":"อัตราหัก ณ ที่จ่าย (%)","example":"1354000","type":"string"},{"type":"null"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCategory":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtIncomeType":{"anyOf":[{"description":"WHT_CERT: ประเภทเงินได้ ม.40","anyOf":[{"const":"M40_1","type":"string"},{"const":"M40_2","type":"string"},{"const":"M40_3","type":"string"},{"const":"M40_4A","type":"string"},{"const":"M40_4B","type":"string"},{"const":"M40_5","type":"string"},{"const":"M40_6","type":"string"},{"const":"M40_7","type":"string"},{"const":"M40_8","type":"string"},{"const":"OTHER","type":"string"}]},{"type":"null"}]},"whtDividendCase":{"anyOf":[{"description":"WHT_CERT: กรณีย่อยของข้อ 4(ข)","anyOf":[{"const":"1.1","type":"string"},{"const":"1.2","type":"string"},{"const":"1.3","type":"string"},{"const":"1.4","type":"string"},{"const":"2.1","type":"string"},{"const":"2.2","type":"string"},{"const":"2.3","type":"string"},{"const":"2.4","type":"string"},{"const":"2.5","type":"string"}]},{"type":"null"}]},"whtPaidOn":{"anyOf":[{"format":"date-time","description":"WHT_CERT: วันที่จ่ายเงินได้ของรายการนี้","type":"string"},{"type":"null"}]},"whtAmount":{"description":"ยอดหัก ณ ที่จ่าย","example":"1354000","type":"string"},"lineTotal":{"description":"ยอดรวมบรรทัด","example":"1354000","type":"string"},"sourceLineId":{"anyOf":[{"multipleOf":1,"description":"บรรทัดต้นทางเมื่อแปลงเอกสาร","type":"number"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"invoiceAvailable":{"description":"มีเฉพาะเอกสารที่ยังออกใบแจ้งหนี้ต่อได้","type":"boolean"},"invoiceRemainingQuantity":{"description":"จำนวนที่ยังออกใบแจ้งหนี้ได้","example":"1354000","type":"string"},"invoiceRemainingUnitPrice":{"description":"ราคาต่อหน่วยของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingDiscountAmount":{"description":"ส่วนลดของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingLineTotal":{"description":"ยอดรวมของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingVatAmount":{"description":"ภาษีของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingWhtAmount":{"description":"หัก ณ ที่จ่ายของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingAmount":{"description":"ยอดสุทธิของส่วนที่เหลือ","example":"1354000","type":"string"}}}},"payments":{"description":"รายการชำระเงินที่ผูกกับเอกสาร","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","documentId","receiptId","paidDate","amount","method","bankRef","note","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"documentId":{"multipleOf":1,"type":"number"},"receiptId":{"anyOf":[{"multipleOf":1,"description":"เอกสารใบเสร็จที่บันทึกรายการนี้ไว้ — null เมื่อยังไม่ถูกลงใบเสร็จ","type":"number"},{"type":"null"}]},"paidDate":{"format":"date-time","description":"วันที่ชำระ","type":"string"},"amount":{"description":"จำนวนเงินที่ชำระ","example":"1354000","type":"string"},"method":{"example":"transfer","description":"วิธีชำระ (ข้อความอิสระ ไม่ใช่ enum)","type":"string"},"bankRef":{"anyOf":[{"type":"string"},{"type":"null"}]},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่บันทึก","type":"string"},"sourceDocumentNumber":{"description":"เลขที่เอกสารต้นทาง — มีเฉพาะ payments ของใบเสร็จร่างที่ถูก hydrate จากใบแจ้งหนี้ต้นทาง","type":"string"}}}},"receiptPayments":{"description":"รายการชำระเงินฝั่งใบเสร็จ — โครงเดียวกับ payments แต่ไม่มี sourceDocumentNumber","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","documentId","receiptId","paidDate","amount","method","bankRef","note","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"documentId":{"multipleOf":1,"type":"number"},"receiptId":{"anyOf":[{"multipleOf":1,"description":"เอกสารใบเสร็จที่บันทึกรายการนี้ไว้ — null เมื่อยังไม่ถูกลงใบเสร็จ","type":"number"},{"type":"null"}]},"paidDate":{"format":"date-time","description":"วันที่ชำระ","type":"string"},"amount":{"description":"จำนวนเงินที่ชำระ","example":"1354000","type":"string"},"method":{"example":"transfer","description":"วิธีชำระ (ข้อความอิสระ ไม่ใช่ enum)","type":"string"},"bankRef":{"anyOf":[{"type":"string"},{"type":"null"}]},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่บันทึก","type":"string"},"sourceDocumentNumber":{"description":"เลขที่เอกสารต้นทาง — มีเฉพาะ payments ของใบเสร็จร่างที่ถูก hydrate จากใบแจ้งหนี้ต้นทาง","type":"string"}}}},"parentRefs":{"description":"เอกสารต้นทาง","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","parentId","childId","relationType","note","createdAt","parent"],"properties":{"id":{"multipleOf":1,"type":"number"},"parentId":{"multipleOf":1,"type":"number"},"childId":{"multipleOf":1,"type":"number"},"relationType":{"example":"CONVERSION","anyOf":[{"const":"CONVERSION","type":"string"},{"const":"PARTIAL","type":"string"},{"const":"REVISION","type":"string"},{"const":"CREDIT","type":"string"},{"const":"DEBIT","type":"string"},{"const":"PAYMENT","type":"string"},{"const":"BILLING","type":"string"}]},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่ผูกความสัมพันธ์","type":"string"},"parent":{"additionalProperties":true,"description":"เอกสารฝั่ง parent — คืนมาเต็มฉบับ (ฟิลด์เดียวกับเอกสารรายฉบับ)","type":"object","required":["id","type","number","status"],"properties":{"id":{"multipleOf":1,"type":"number"},"type":{"anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"type":"string"},"status":{"anyOf":[{"const":"DRAFT","type":"string"},{"const":"ISSUED","type":"string"},{"const":"PARTIALLY_ISSUED","type":"string"},{"const":"SUCCESS","type":"string"},{"const":"WAIT_ACCEPTED","type":"string"},{"const":"ACCEPTED","type":"string"},{"const":"REJECTED","type":"string"},{"const":"WAIT_PAID","type":"string"},{"const":"PARTIALLY_PAID","type":"string"},{"const":"PAID","type":"string"},{"const":"OVERDUE","type":"string"},{"const":"CANCELLED","type":"string"},{"const":"CONVERTED","type":"string"}]}}}}}},"childRefs":{"description":"เอกสารปลายทางที่แตกออกไป","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","parentId","childId","relationType","note","createdAt","child"],"properties":{"id":{"multipleOf":1,"type":"number"},"parentId":{"multipleOf":1,"type":"number"},"childId":{"multipleOf":1,"type":"number"},"relationType":{"example":"CONVERSION","anyOf":[{"const":"CONVERSION","type":"string"},{"const":"PARTIAL","type":"string"},{"const":"REVISION","type":"string"},{"const":"CREDIT","type":"string"},{"const":"DEBIT","type":"string"},{"const":"PAYMENT","type":"string"},{"const":"BILLING","type":"string"}]},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่ผูกความสัมพันธ์","type":"string"},"child":{"additionalProperties":true,"description":"เอกสารฝั่ง child — คืนมาเต็มฉบับ (ฟิลด์เดียวกับเอกสารรายฉบับ)","type":"object","required":["id","type","number","status"],"properties":{"id":{"multipleOf":1,"type":"number"},"type":{"anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"type":"string"},"status":{"anyOf":[{"const":"DRAFT","type":"string"},{"const":"ISSUED","type":"string"},{"const":"PARTIALLY_ISSUED","type":"string"},{"const":"SUCCESS","type":"string"},{"const":"WAIT_ACCEPTED","type":"string"},{"const":"ACCEPTED","type":"string"},{"const":"REJECTED","type":"string"},{"const":"WAIT_PAID","type":"string"},{"const":"PARTIALLY_PAID","type":"string"},{"const":"PAID","type":"string"},{"const":"OVERDUE","type":"string"},{"const":"CANCELLED","type":"string"},{"const":"CONVERTED","type":"string"}]}}}}}},"customer":{"anyOf":[{"additionalProperties":true,"description":"ลูกค้าเต็มรูป (ฟิลด์เดียวกับ GET /v1/clients)","type":"object","properties":{}},{"type":"null"}]},"vendor":{"anyOf":[{"additionalProperties":true,"description":"ผู้ขายเต็มรูป (ฟิลด์เดียวกับ GET /v1/clients)","type":"object","properties":{}},{"type":"null"}]},"attachments":{"description":"ไฟล์แนบ","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","documentId","fileName","fileUrl","mimeType","fileSize","uploadedAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"documentId":{"multipleOf":1,"type":"number"},"fileName":{"example":"invoice-signed.pdf","type":"string"},"fileUrl":{"example":"https://cdn.example.com/uploads/invoice-signed.pdf","type":"string"},"mimeType":{"anyOf":[{"example":"application/pdf","type":"string"},{"type":"null"}]},"fileSize":{"anyOf":[{"multipleOf":1,"description":"ขนาดไฟล์ (byte)","type":"number"},{"type":"null"}]},"uploadedAt":{"format":"date-time","description":"เวลาที่อัปโหลด","type":"string"}}}},"actionPolicy":{"additionalProperties":true,"description":"สิ่งที่ทำกับเอกสารนี้ได้ตามสถานะ — ใช้ตัดสินใจก่อนเรียก endpoint แก้/ยกเลิก","type":"object","required":["canEdit","editReason","editCode","canVoid","voidReason","voidCode","canIssue","issueReason","canMarkPaid","markPaidReason","canConvertTo"],"properties":{"canEdit":{"type":"boolean"},"editReason":{"anyOf":[{"description":"เหตุผลที่แก้ไม่ได้","type":"string"},{"type":"null"}]},"editCode":{"example":"EDITABLE_DRAFT","description":"รหัสเหตุผลของการแก้ไข (ชุดเดียวกับ edit-policy)","anyOf":[{"const":"STATUS_LOCKED","type":"string"},{"const":"EDITABLE_DRAFT","type":"string"},{"const":"QUOTATION_DRAFT_ONLY","type":"string"},{"const":"INVOICE_DRAFT_ONLY","type":"string"},{"const":"PO_DRAFT_ONLY","type":"string"},{"const":"EXPENSE_DRAFT_ONLY","type":"string"},{"const":"GR_DRAFT_ONLY","type":"string"},{"const":"DN_DRAFT_ONLY","type":"string"},{"const":"MR_DRAFT_ONLY","type":"string"},{"const":"CREDIT_NOTE_DRAFT_ONLY","type":"string"},{"const":"BILLING_NOTE_DRAFT_ONLY","type":"string"},{"const":"RECEIPT_DRAFT_ONLY","type":"string"},{"const":"WHT_CERT_DRAFT_ONLY","type":"string"},{"const":"TAX_INVOICE_SOURCE_LOCKED","type":"string"},{"const":"TAX_INVOICE_DRAFT_ONLY","type":"string"},{"const":"TYPE_IMMUTABLE","type":"string"}]},"canVoid":{"type":"boolean"},"voidReason":{"anyOf":[{"type":"string"},{"type":"null"}]},"voidCode":{"example":"VOID_ALLOWED","description":"รหัสเหตุผลของการยกเลิก (ชุดเดียวกับ edit-policy)","anyOf":[{"const":"STATUS_LOCKED","type":"string"},{"const":"VOID_ALLOWED","type":"string"},{"const":"TAX_INVOICE_VOID_FORBIDDEN","type":"string"},{"const":"RELATED_TAX_INVOICE_VOID_FORBIDDEN","type":"string"}]},"canIssue":{"type":"boolean"},"issueReason":{"anyOf":[{"type":"string"},{"type":"null"}]},"canMarkPaid":{"type":"boolean"},"markPaidReason":{"anyOf":[{"type":"string"},{"type":"null"}]},"canConvertTo":{"description":"ชนิดที่แปลงต่อได้จากสถานะปัจจุบัน","type":"array","items":{"anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]}}}},"lineage":{"description":"สายเอกสารเรียงจากต้นทางถึงฉบับนี้","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","type","number","status"],"properties":{"id":{"multipleOf":1,"type":"number"},"type":{"anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"type":"string"},"status":{"anyOf":[{"const":"DRAFT","type":"string"},{"const":"ISSUED","type":"string"},{"const":"PARTIALLY_ISSUED","type":"string"},{"const":"SUCCESS","type":"string"},{"const":"WAIT_ACCEPTED","type":"string"},{"const":"ACCEPTED","type":"string"},{"const":"REJECTED","type":"string"},{"const":"WAIT_PAID","type":"string"},{"const":"PARTIALLY_PAID","type":"string"},{"const":"PAID","type":"string"},{"const":"OVERDUE","type":"string"},{"const":"CANCELLED","type":"string"},{"const":"CONVERTED","type":"string"}]}}}},"relatedDocuments":{"additionalProperties":true,"description":"กราฟเอกสารที่เกี่ยวข้องทั้งกลุ่ม","type":"object","required":["nodes","edges","total"],"properties":{"nodes":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","type","number","status","issueDate","grandTotal","distance"],"properties":{"id":{"multipleOf":1,"type":"number"},"type":{"anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"type":"string"},"status":{"anyOf":[{"const":"DRAFT","type":"string"},{"const":"ISSUED","type":"string"},{"const":"PARTIALLY_ISSUED","type":"string"},{"const":"SUCCESS","type":"string"},{"const":"WAIT_ACCEPTED","type":"string"},{"const":"ACCEPTED","type":"string"},{"const":"REJECTED","type":"string"},{"const":"WAIT_PAID","type":"string"},{"const":"PARTIALLY_PAID","type":"string"},{"const":"PAID","type":"string"},{"const":"OVERDUE","type":"string"},{"const":"CANCELLED","type":"string"},{"const":"CONVERTED","type":"string"}]},"issueDate":{"format":"date-time","description":"วันที่ออกเอกสาร","type":"string"},"grandTotal":{"description":"ยอดรวมสุทธิ","example":"1354000","type":"string"},"distance":{"multipleOf":1,"description":"ระยะห่างจากเอกสารนี้ในกราฟความสัมพันธ์","type":"number"}}}},"edges":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["parentId","childId","relationType"],"properties":{"parentId":{"multipleOf":1,"type":"number"},"childId":{"multipleOf":1,"type":"number"},"relationType":{"anyOf":[{"const":"CONVERSION","type":"string"},{"const":"PARTIAL","type":"string"},{"const":"REVISION","type":"string"},{"const":"CREDIT","type":"string"},{"const":"DEBIT","type":"string"},{"const":"PAYMENT","type":"string"},{"const":"BILLING","type":"string"}]}}}},"total":{"multipleOf":1,"type":"number"}}},"issuableRemaining":{"anyOf":[{"description":"จำนวนที่ยังออกเอกสารต่อได้ — null เมื่อไม่เกี่ยวกับเอกสารชนิดนี้","type":"number"},{"type":"null"}]}}}}}},"404":{"description":"ไม่พบเอกสาร (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id ไม่ใช่จำนวนเต็ม (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}},"put":{"parameters":[{"description":"document id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"document id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"putV1DocumentsById","tags":["Documents"],"summary":"แก้ไขเอกสาร (เฉพาะฉบับที่ยังแก้ได้)","description":"**ต้องมี scope `documents:update`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ส่งเฉพาะฟิลด์ที่ต้องการแก้ · ฟิลด์ที่ไม่มีใน schema → 400 VALIDATION (zod .strict) แต่ฟิลด์ที่มีอยู่แล้วส่งผิดชนิด → 422 VALIDATION (TypeBox ที่ขอบตรวจก่อน) · id ต้องเป็นจำนวนเต็มตั้งแต่ 1 ขึ้นไป ไม่ใช่ → 422 · ไม่พบเอกสาร/คนละบริษัท → 404 NOT_FOUND · สถานะที่แก้ไม่ได้แล้ว → 409 · ใบลดหนี้ที่อ้างใบกำกับภาษี แก้ได้แค่ remark กับ internalNote → 409 CREDIT_NOTE_SOURCE_LOCKED · มีคนกำลังแก้เอกสารนี้ในแอป → 409 LOCK_HELD · **body ที่ตอบกลับไม่เท่ากับ `GET /v1/documents/{id}`** — ไม่มี attachments, actionPolicy, lineage, relatedDocuments, issuableRemaining","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"เอกสารหลังแก้ไข","content":{"application/json":{"schema":{"additionalProperties":true,"description":"เอกสารหลังแก้ไข — โครงเหมือนเอกสารรายฉบับแต่ **ไม่มี** attachments, actionPolicy, lineage, relatedDocuments, issuableRemaining (ต้องเรียก GET /v1/documents/{id} ถ้าต้องใช้) · ตัวเลขเงินเป็น **string** ทุกตัว (Prisma Decimal) และตัดศูนย์ท้ายทิ้ง — '86000.50' คืนเป็น '86000.5'","type":"object","required":["id","companyId","type","number","status","creationSource","issueDate","dueDate","expiryDate","referenceCode","sourceOrderCode","customerId","vendorId","issuerSnapshot","partySnapshot","issuerSetting","currency","exchangeRate","vatInclusive","taxInvoiceCombined","vatRate","whtRate","whtRateId","whtMode","whtCertBookNo","whtCertPndForm","whtCertFormSeqNo","whtCertRemitMethod","whtCertRemitOther","whtCertFundGpf","whtCertFundSso","whtCertFundPvd","whtCertDividendRate","whtCertDividendOther","subtotal","discountAmount","discountPercent","taxableAmount","vatAmount","whtAmount","grandTotal","grandTotalText","paidAmount","remainingAmount","paymentDate","paymentBankRef","paymentNote","remark","internalNote","paymentTerms","paymentMethod","receivedDate","chequeNo","chequeDate","chequeBank","voidedAt","voidedReason","createdById","updatedById","createdAt","updatedAt","deletedAt","editingByUserId","editingByName","editingExpiresAt","lines","payments","receiptPayments","parentRefs","childRefs","customer","vendor"],"properties":{"id":{"multipleOf":1,"example":8,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"type":{"example":"QUOTATION","anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"example":"QT-2026-05-0015","type":"string"},"status":{"example":"WAIT_ACCEPTED","anyOf":[{"const":"DRAFT","type":"string"},{"const":"ISSUED","type":"string"},{"const":"PARTIALLY_ISSUED","type":"string"},{"const":"SUCCESS","type":"string"},{"const":"WAIT_ACCEPTED","type":"string"},{"const":"ACCEPTED","type":"string"},{"const":"REJECTED","type":"string"},{"const":"WAIT_PAID","type":"string"},{"const":"PARTIALLY_PAID","type":"string"},{"const":"PAID","type":"string"},{"const":"OVERDUE","type":"string"},{"const":"CANCELLED","type":"string"},{"const":"CONVERTED","type":"string"}]},"creationSource":{"example":"API","anyOf":[{"const":"BACKOFFICE","type":"string"},{"const":"API","type":"string"}]},"issueDate":{"format":"date-time","description":"วันที่ออกเอกสาร","type":"string"},"dueDate":{"anyOf":[{"format":"date-time","description":"วันครบกำหนดชำระ","type":"string"},{"type":"null"}]},"expiryDate":{"anyOf":[{"format":"date-time","description":"วันหมดอายุ","type":"string"},{"type":"null"}]},"referenceCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"sourceOrderCode":{"anyOf":[{"description":"เลขออเดอร์ต้นทางจากระบบขาย (การ์ด 74)","type":"string"},{"type":"null"}]},"customerId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"vendorId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"issuerSnapshot":{"additionalProperties":true,"description":"ข้อมูลผู้ออกเอกสารตอนที่ออก (แช่แข็งไว้)","type":"object","properties":{}},"partySnapshot":{"additionalProperties":true,"description":"ข้อมูลคู่ค้าตอนที่ออกเอกสาร (แช่แข็งไว้)","type":"object","properties":{}},"issuerSetting":{"anyOf":[{"additionalProperties":true,"description":"ค่าตั้งบริษัทที่ใช้ตอนออกเอกสาร","type":"object","properties":{}},{"type":"null"}]},"currency":{"example":"THB","type":"string"},"exchangeRate":{"description":"อัตราแลกเปลี่ยน","example":"1354000","type":"string"},"vatInclusive":{"type":"boolean"},"taxInvoiceCombined":{"description":"ใบเสร็จรับเงินที่ออกใบกำกับภาษีควบในใบเดียว","type":"boolean"},"vatRate":{"description":"อัตรา VAT (%)","example":"1354000","type":"string"},"whtRate":{"anyOf":[{"description":"อัตราหัก ณ ที่จ่ายระดับเอกสาร (%)","example":"1354000","type":"string"},{"type":"null"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtMode":{"example":"NONE","anyOf":[{"const":"NONE","type":"string"},{"const":"DOCUMENT_LEVEL","type":"string"},{"const":"LINE_LEVEL","type":"string"}]},"whtCertBookNo":{"anyOf":[{"description":"WHT_CERT: เล่มที่ (ผู้ใช้กรอกเอง)","type":"string"},{"type":"null"}]},"whtCertPndForm":{"anyOf":[{"description":"WHT_CERT: แบบ ภ.ง.ด. ที่ยื่นคู่กัน","anyOf":[{"const":"PND1A","type":"string"},{"const":"PND1A_SPECIAL","type":"string"},{"const":"PND2","type":"string"},{"const":"PND3","type":"string"},{"const":"PND2A","type":"string"},{"const":"PND3A","type":"string"},{"const":"PND53","type":"string"}]},{"type":"null"}]},"whtCertFormSeqNo":{"anyOf":[{"description":"WHT_CERT: ลำดับที่ในแบบ","type":"string"},{"type":"null"}]},"whtCertRemitMethod":{"anyOf":[{"description":"WHT_CERT: วิธีการนำส่งเงินภาษี","anyOf":[{"const":"WITHHELD","type":"string"},{"const":"PAY_FOREVER","type":"string"},{"const":"PAY_ONCE","type":"string"},{"const":"OTHER","type":"string"}]},{"type":"null"}]},"whtCertRemitOther":{"anyOf":[{"description":"WHT_CERT: ข้อความของวิธีการนำส่งแบบอื่น ๆ","type":"string"},{"type":"null"}]},"whtCertFundGpf":{"anyOf":[{"description":"WHT_CERT: กบข. / กสจ. / กองทุนสงเคราะห์ครูโรงเรียนเอกชน","example":"1354000","type":"string"},{"type":"null"}]},"whtCertFundSso":{"anyOf":[{"description":"WHT_CERT: กองทุนประกันสังคม","example":"1354000","type":"string"},{"type":"null"}]},"whtCertFundPvd":{"anyOf":[{"description":"WHT_CERT: กองทุนสำรองเลี้ยงชีพ","example":"1354000","type":"string"},{"type":"null"}]},"whtCertDividendRate":{"anyOf":[{"description":"WHT_CERT: 4(ข)(1.4) อัตราอื่น ๆ ของกำไรสุทธิ","example":"1354000","type":"string"},{"type":"null"}]},"whtCertDividendOther":{"anyOf":[{"description":"WHT_CERT: 4(ข)(2.5) อื่น ๆ (ระบุ)","type":"string"},{"type":"null"}]},"subtotal":{"description":"ยอดก่อนภาษี","example":"1354000","type":"string"},"discountAmount":{"description":"ส่วนลด (บาท)","example":"1354000","type":"string"},"discountPercent":{"anyOf":[{"description":"ส่วนลด (%)","example":"1354000","type":"string"},{"type":"null"}]},"taxableAmount":{"description":"ฐานภาษี","example":"1354000","type":"string"},"vatAmount":{"description":"ภาษีมูลค่าเพิ่ม","example":"1354000","type":"string"},"whtAmount":{"description":"ยอดหัก ณ ที่จ่าย","example":"1354000","type":"string"},"grandTotal":{"description":"ยอดรวมสุทธิ","example":"1354000","type":"string"},"grandTotalText":{"anyOf":[{"description":"ยอดรวมเป็นตัวอักษร","type":"string"},{"type":"null"}]},"paidAmount":{"description":"ยอดที่ชำระแล้ว","example":"1354000","type":"string"},"remainingAmount":{"description":"ยอดคงเหลือ","example":"1354000","type":"string"},"paymentDate":{"anyOf":[{"format":"date-time","description":"วันที่ชำระ","type":"string"},{"type":"null"}]},"paymentBankRef":{"anyOf":[{"type":"string"},{"type":"null"}]},"paymentNote":{"anyOf":[{"type":"string"},{"type":"null"}]},"remark":{"anyOf":[{"description":"หมายเหตุที่พิมพ์บนเอกสาร","type":"string"},{"type":"null"}]},"internalNote":{"anyOf":[{"description":"หมายเหตุภายใน ไม่พิมพ์บนเอกสาร","type":"string"},{"type":"null"}]},"paymentTerms":{"anyOf":[{"example":"30 วันหลังตอบรับ","type":"string"},{"type":"null"}]},"paymentMethod":{"anyOf":[{"type":"string"},{"type":"null"}]},"receivedDate":{"anyOf":[{"format":"date-time","description":"วันที่รับของ","type":"string"},{"type":"null"}]},"chequeNo":{"anyOf":[{"type":"string"},{"type":"null"}]},"chequeDate":{"anyOf":[{"format":"date-time","description":"วันที่บนเช็ค","type":"string"},{"type":"null"}]},"chequeBank":{"anyOf":[{"type":"string"},{"type":"null"}]},"voidedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ยกเลิก","type":"string"},{"type":"null"}]},"voidedReason":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdById":{"anyOf":[{"multipleOf":1,"description":"null เมื่อสร้างด้วย API key (ไม่ใช่คน)","type":"number"},{"type":"null"}]},"updatedById":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]},"editingByUserId":{"anyOf":[{"multipleOf":1,"description":"ผู้ที่กำลังแก้เอกสารนี้ในแอป","type":"number"},{"type":"null"}]},"editingByName":{"anyOf":[{"type":"string"},{"type":"null"}]},"editingExpiresAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ lock การแก้ในแอปหมดอายุ","type":"string"},{"type":"null"}]},"lines":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","documentId","lineNo","productId","productSnapshot","description","note","productDetail","quantity","unit","unitPrice","discountAmount","discountPercent","vatType","vatAmount","whtRate","whtRateId","whtCategory","whtIncomeType","whtDividendCase","whtPaidOn","whtAmount","lineTotal","sourceLineId","createdAt","updatedAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"documentId":{"multipleOf":1,"type":"number"},"lineNo":{"multipleOf":1,"example":1,"type":"number"},"productId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"productSnapshot":{"anyOf":[{"additionalProperties":true,"type":"object","properties":{"sku":{"anyOf":[{"type":"string"},{"type":"null"}]},"name":{"type":"string"},"unit":{"type":"string"},"vatType":{"anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"productType":{"anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]}}},{"type":"null"}]},"description":{"example":"สินค้า A","type":"string"},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"productDetail":{"anyOf":[{"type":"string"},{"type":"null"}]},"quantity":{"description":"จำนวน","example":"1354000","type":"string"},"unit":{"example":"ชิ้น","type":"string"},"unitPrice":{"description":"ราคาต่อหน่วย","example":"1354000","type":"string"},"discountAmount":{"description":"ส่วนลด (บาท)","example":"1354000","type":"string"},"discountPercent":{"anyOf":[{"description":"ส่วนลด (%)","example":"1354000","type":"string"},{"type":"null"}]},"vatType":{"example":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"vatAmount":{"description":"ภาษีของบรรทัดนี้","example":"1354000","type":"string"},"whtRate":{"anyOf":[{"description":"อัตราหัก ณ ที่จ่าย (%)","example":"1354000","type":"string"},{"type":"null"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCategory":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtIncomeType":{"anyOf":[{"description":"WHT_CERT: ประเภทเงินได้ ม.40","anyOf":[{"const":"M40_1","type":"string"},{"const":"M40_2","type":"string"},{"const":"M40_3","type":"string"},{"const":"M40_4A","type":"string"},{"const":"M40_4B","type":"string"},{"const":"M40_5","type":"string"},{"const":"M40_6","type":"string"},{"const":"M40_7","type":"string"},{"const":"M40_8","type":"string"},{"const":"OTHER","type":"string"}]},{"type":"null"}]},"whtDividendCase":{"anyOf":[{"description":"WHT_CERT: กรณีย่อยของข้อ 4(ข)","anyOf":[{"const":"1.1","type":"string"},{"const":"1.2","type":"string"},{"const":"1.3","type":"string"},{"const":"1.4","type":"string"},{"const":"2.1","type":"string"},{"const":"2.2","type":"string"},{"const":"2.3","type":"string"},{"const":"2.4","type":"string"},{"const":"2.5","type":"string"}]},{"type":"null"}]},"whtPaidOn":{"anyOf":[{"format":"date-time","description":"WHT_CERT: วันที่จ่ายเงินได้ของรายการนี้","type":"string"},{"type":"null"}]},"whtAmount":{"description":"ยอดหัก ณ ที่จ่าย","example":"1354000","type":"string"},"lineTotal":{"description":"ยอดรวมบรรทัด","example":"1354000","type":"string"},"sourceLineId":{"anyOf":[{"multipleOf":1,"description":"บรรทัดต้นทางเมื่อแปลงเอกสาร","type":"number"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"invoiceAvailable":{"description":"มีเฉพาะเอกสารที่ยังออกใบแจ้งหนี้ต่อได้","type":"boolean"},"invoiceRemainingQuantity":{"description":"จำนวนที่ยังออกใบแจ้งหนี้ได้","example":"1354000","type":"string"},"invoiceRemainingUnitPrice":{"description":"ราคาต่อหน่วยของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingDiscountAmount":{"description":"ส่วนลดของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingLineTotal":{"description":"ยอดรวมของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingVatAmount":{"description":"ภาษีของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingWhtAmount":{"description":"หัก ณ ที่จ่ายของส่วนที่เหลือ","example":"1354000","type":"string"},"invoiceRemainingAmount":{"description":"ยอดสุทธิของส่วนที่เหลือ","example":"1354000","type":"string"}}}},"payments":{"description":"รายการชำระเงินที่ผูกกับเอกสาร","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","documentId","receiptId","paidDate","amount","method","bankRef","note","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"documentId":{"multipleOf":1,"type":"number"},"receiptId":{"anyOf":[{"multipleOf":1,"description":"เอกสารใบเสร็จที่บันทึกรายการนี้ไว้ — null เมื่อยังไม่ถูกลงใบเสร็จ","type":"number"},{"type":"null"}]},"paidDate":{"format":"date-time","description":"วันที่ชำระ","type":"string"},"amount":{"description":"จำนวนเงินที่ชำระ","example":"1354000","type":"string"},"method":{"example":"transfer","description":"วิธีชำระ (ข้อความอิสระ ไม่ใช่ enum)","type":"string"},"bankRef":{"anyOf":[{"type":"string"},{"type":"null"}]},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่บันทึก","type":"string"},"sourceDocumentNumber":{"description":"เลขที่เอกสารต้นทาง — มีเฉพาะ payments ของใบเสร็จร่างที่ถูก hydrate จากใบแจ้งหนี้ต้นทาง","type":"string"}}}},"receiptPayments":{"description":"รายการชำระเงินฝั่งใบเสร็จ — โครงเดียวกับ payments แต่ไม่มี sourceDocumentNumber","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","documentId","receiptId","paidDate","amount","method","bankRef","note","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"documentId":{"multipleOf":1,"type":"number"},"receiptId":{"anyOf":[{"multipleOf":1,"description":"เอกสารใบเสร็จที่บันทึกรายการนี้ไว้ — null เมื่อยังไม่ถูกลงใบเสร็จ","type":"number"},{"type":"null"}]},"paidDate":{"format":"date-time","description":"วันที่ชำระ","type":"string"},"amount":{"description":"จำนวนเงินที่ชำระ","example":"1354000","type":"string"},"method":{"example":"transfer","description":"วิธีชำระ (ข้อความอิสระ ไม่ใช่ enum)","type":"string"},"bankRef":{"anyOf":[{"type":"string"},{"type":"null"}]},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่บันทึก","type":"string"},"sourceDocumentNumber":{"description":"เลขที่เอกสารต้นทาง — มีเฉพาะ payments ของใบเสร็จร่างที่ถูก hydrate จากใบแจ้งหนี้ต้นทาง","type":"string"}}}},"parentRefs":{"description":"เอกสารต้นทาง","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","parentId","childId","relationType","note","createdAt","parent"],"properties":{"id":{"multipleOf":1,"type":"number"},"parentId":{"multipleOf":1,"type":"number"},"childId":{"multipleOf":1,"type":"number"},"relationType":{"example":"CONVERSION","anyOf":[{"const":"CONVERSION","type":"string"},{"const":"PARTIAL","type":"string"},{"const":"REVISION","type":"string"},{"const":"CREDIT","type":"string"},{"const":"DEBIT","type":"string"},{"const":"PAYMENT","type":"string"},{"const":"BILLING","type":"string"}]},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่ผูกความสัมพันธ์","type":"string"},"parent":{"additionalProperties":true,"description":"เอกสารฝั่ง parent — คืนมาเต็มฉบับ (ฟิลด์เดียวกับเอกสารรายฉบับ)","type":"object","required":["id","type","number","status"],"properties":{"id":{"multipleOf":1,"type":"number"},"type":{"anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"type":"string"},"status":{"anyOf":[{"const":"DRAFT","type":"string"},{"const":"ISSUED","type":"string"},{"const":"PARTIALLY_ISSUED","type":"string"},{"const":"SUCCESS","type":"string"},{"const":"WAIT_ACCEPTED","type":"string"},{"const":"ACCEPTED","type":"string"},{"const":"REJECTED","type":"string"},{"const":"WAIT_PAID","type":"string"},{"const":"PARTIALLY_PAID","type":"string"},{"const":"PAID","type":"string"},{"const":"OVERDUE","type":"string"},{"const":"CANCELLED","type":"string"},{"const":"CONVERTED","type":"string"}]}}}}}},"childRefs":{"description":"เอกสารปลายทางที่แตกออกไป","type":"array","items":{"additionalProperties":true,"type":"object","required":["id","parentId","childId","relationType","note","createdAt","child"],"properties":{"id":{"multipleOf":1,"type":"number"},"parentId":{"multipleOf":1,"type":"number"},"childId":{"multipleOf":1,"type":"number"},"relationType":{"example":"CONVERSION","anyOf":[{"const":"CONVERSION","type":"string"},{"const":"PARTIAL","type":"string"},{"const":"REVISION","type":"string"},{"const":"CREDIT","type":"string"},{"const":"DEBIT","type":"string"},{"const":"PAYMENT","type":"string"},{"const":"BILLING","type":"string"}]},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"createdAt":{"format":"date-time","description":"เวลาที่ผูกความสัมพันธ์","type":"string"},"child":{"additionalProperties":true,"description":"เอกสารฝั่ง child — คืนมาเต็มฉบับ (ฟิลด์เดียวกับเอกสารรายฉบับ)","type":"object","required":["id","type","number","status"],"properties":{"id":{"multipleOf":1,"type":"number"},"type":{"anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"number":{"type":"string"},"status":{"anyOf":[{"const":"DRAFT","type":"string"},{"const":"ISSUED","type":"string"},{"const":"PARTIALLY_ISSUED","type":"string"},{"const":"SUCCESS","type":"string"},{"const":"WAIT_ACCEPTED","type":"string"},{"const":"ACCEPTED","type":"string"},{"const":"REJECTED","type":"string"},{"const":"WAIT_PAID","type":"string"},{"const":"PARTIALLY_PAID","type":"string"},{"const":"PAID","type":"string"},{"const":"OVERDUE","type":"string"},{"const":"CANCELLED","type":"string"},{"const":"CONVERTED","type":"string"}]}}}}}},"customer":{"anyOf":[{"additionalProperties":true,"description":"ลูกค้าเต็มรูป (ฟิลด์เดียวกับ GET /v1/clients)","type":"object","properties":{}},{"type":"null"}]},"vendor":{"anyOf":[{"additionalProperties":true,"description":"ผู้ขายเต็มรูป (ฟิลด์เดียวกับ GET /v1/clients)","type":"object","properties":{}},{"type":"null"}]}}}}}},"400":{"description":"มีฟิลด์ที่ schema ไม่รับ (VALIDATION — zod .strict)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"404":{"description":"ไม่พบเอกสาร (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"409":{"description":"แก้ไม่ได้ตามสถานะ/ถูกล็อกอยู่ (LOCK_HELD · CREDIT_NOTE_SOURCE_LOCKED)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id หรือชนิดของฟิลด์ไม่ผ่านที่ขอบ (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"ฟิลด์ที่ต้องการแก้ (ฟิลด์ตรงกับ documentUpdateSchema — ส่งมาเฉพาะที่แก้ได้)","type":"object","properties":{"paymentTerms":{"type":"string"},"paymentMethod":{"type":"string"},"receiptPayment":{},"remark":{"type":"string"},"internalNote":{"type":"string"},"referenceCode":{"type":"string"},"dueDate":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"issueDate":{"format":"date-time","type":"string"},"customerId":{"anyOf":[{"example":42,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":42,"type":"number"}]},{"type":"null"}]},"vendorId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"vatInclusive":{"type":"boolean"},"taxInvoiceCombined":{"type":"boolean"},"whtMode":{"example":"NONE","anyOf":[{"const":"NONE","type":"string"},{"const":"DOCUMENT_LEVEL","type":"string"},{"const":"LINE_LEVEL","type":"string"}]},"whtRate":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtAmount":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertBookNo":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertPndForm":{"anyOf":[{"anyOf":[{"const":"PND1A","type":"string"},{"const":"PND1A_SPECIAL","type":"string"},{"const":"PND2","type":"string"},{"const":"PND3","type":"string"},{"const":"PND2A","type":"string"},{"const":"PND3A","type":"string"},{"const":"PND53","type":"string"}]},{"type":"null"}]},"whtCertFormSeqNo":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertRemitMethod":{"anyOf":[{"anyOf":[{"const":"WITHHELD","type":"string"},{"const":"PAY_FOREVER","type":"string"},{"const":"PAY_ONCE","type":"string"},{"const":"OTHER","type":"string"}]},{"type":"null"}]},"whtCertRemitOther":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertFundGpf":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertFundSso":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertFundPvd":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertDividendRate":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertDividendOther":{"anyOf":[{"type":"string"},{"type":"null"}]},"lines":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["lineNo","description","quantity","unit","unitPrice","vatType"],"properties":{"lineNo":{"example":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1,"type":"number"}]},"productId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"sourceLineId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"productSnapshot":{},"description":{"example":"สินค้า A","type":"string"},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"productDetail":{"anyOf":[{"type":"string"},{"type":"null"}]},"quantity":{"example":2,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":2,"type":"number"}]},"unit":{"example":"ชิ้น","type":"string"},"unitPrice":{"example":150,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":150,"type":"number"}]},"discountAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"discountPercent":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"vatType":{"example":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"whtRate":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCategory":{"type":"string"},"whtIncomeType":{"description":"WHT_CERT: ประเภทเงินได้ ม.40","anyOf":[{"const":"M40_1","type":"string"},{"const":"M40_2","type":"string"},{"const":"M40_3","type":"string"},{"const":"M40_4A","type":"string"},{"const":"M40_4B","type":"string"},{"const":"M40_5","type":"string"},{"const":"M40_6","type":"string"},{"const":"M40_7","type":"string"},{"const":"M40_8","type":"string"},{"const":"OTHER","type":"string"}]},"whtDividendCase":{"description":"WHT_CERT: กรณีย่อยของข้อ 4(ข) — บังคับเมื่อ whtIncomeType = M40_4B","anyOf":[{"const":"1.1","type":"string"},{"const":"1.2","type":"string"},{"const":"1.3","type":"string"},{"const":"1.4","type":"string"},{"const":"2.1","type":"string"},{"const":"2.2","type":"string"},{"const":"2.3","type":"string"},{"const":"2.4","type":"string"},{"const":"2.5","type":"string"}]},"whtPaidOn":{"format":"date-time","description":"WHT_CERT: วันที่จ่ายเงินได้ของรายการนี้","type":"string"}}}}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"ฟิลด์ที่ต้องการแก้ (ฟิลด์ตรงกับ documentUpdateSchema — ส่งมาเฉพาะที่แก้ได้)","type":"object","properties":{"paymentTerms":{"type":"string"},"paymentMethod":{"type":"string"},"receiptPayment":{},"remark":{"type":"string"},"internalNote":{"type":"string"},"referenceCode":{"type":"string"},"dueDate":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"issueDate":{"format":"date-time","type":"string"},"customerId":{"anyOf":[{"example":42,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":42,"type":"number"}]},{"type":"null"}]},"vendorId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"vatInclusive":{"type":"boolean"},"taxInvoiceCombined":{"type":"boolean"},"whtMode":{"example":"NONE","anyOf":[{"const":"NONE","type":"string"},{"const":"DOCUMENT_LEVEL","type":"string"},{"const":"LINE_LEVEL","type":"string"}]},"whtRate":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtAmount":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertBookNo":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertPndForm":{"anyOf":[{"anyOf":[{"const":"PND1A","type":"string"},{"const":"PND1A_SPECIAL","type":"string"},{"const":"PND2","type":"string"},{"const":"PND3","type":"string"},{"const":"PND2A","type":"string"},{"const":"PND3A","type":"string"},{"const":"PND53","type":"string"}]},{"type":"null"}]},"whtCertFormSeqNo":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertRemitMethod":{"anyOf":[{"anyOf":[{"const":"WITHHELD","type":"string"},{"const":"PAY_FOREVER","type":"string"},{"const":"PAY_ONCE","type":"string"},{"const":"OTHER","type":"string"}]},{"type":"null"}]},"whtCertRemitOther":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertFundGpf":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertFundSso":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertFundPvd":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertDividendRate":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertDividendOther":{"anyOf":[{"type":"string"},{"type":"null"}]},"lines":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["lineNo","description","quantity","unit","unitPrice","vatType"],"properties":{"lineNo":{"example":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1,"type":"number"}]},"productId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"sourceLineId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"productSnapshot":{},"description":{"example":"สินค้า A","type":"string"},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"productDetail":{"anyOf":[{"type":"string"},{"type":"null"}]},"quantity":{"example":2,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":2,"type":"number"}]},"unit":{"example":"ชิ้น","type":"string"},"unitPrice":{"example":150,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":150,"type":"number"}]},"discountAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"discountPercent":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"vatType":{"example":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"whtRate":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCategory":{"type":"string"},"whtIncomeType":{"description":"WHT_CERT: ประเภทเงินได้ ม.40","anyOf":[{"const":"M40_1","type":"string"},{"const":"M40_2","type":"string"},{"const":"M40_3","type":"string"},{"const":"M40_4A","type":"string"},{"const":"M40_4B","type":"string"},{"const":"M40_5","type":"string"},{"const":"M40_6","type":"string"},{"const":"M40_7","type":"string"},{"const":"M40_8","type":"string"},{"const":"OTHER","type":"string"}]},"whtDividendCase":{"description":"WHT_CERT: กรณีย่อยของข้อ 4(ข) — บังคับเมื่อ whtIncomeType = M40_4B","anyOf":[{"const":"1.1","type":"string"},{"const":"1.2","type":"string"},{"const":"1.3","type":"string"},{"const":"1.4","type":"string"},{"const":"2.1","type":"string"},{"const":"2.2","type":"string"},{"const":"2.3","type":"string"},{"const":"2.4","type":"string"},{"const":"2.5","type":"string"}]},"whtPaidOn":{"format":"date-time","description":"WHT_CERT: วันที่จ่ายเงินได้ของรายการนี้","type":"string"}}}}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"ฟิลด์ที่ต้องการแก้ (ฟิลด์ตรงกับ documentUpdateSchema — ส่งมาเฉพาะที่แก้ได้)","type":"object","properties":{"paymentTerms":{"type":"string"},"paymentMethod":{"type":"string"},"receiptPayment":{},"remark":{"type":"string"},"internalNote":{"type":"string"},"referenceCode":{"type":"string"},"dueDate":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"issueDate":{"format":"date-time","type":"string"},"customerId":{"anyOf":[{"example":42,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":42,"type":"number"}]},{"type":"null"}]},"vendorId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"vatInclusive":{"type":"boolean"},"taxInvoiceCombined":{"type":"boolean"},"whtMode":{"example":"NONE","anyOf":[{"const":"NONE","type":"string"},{"const":"DOCUMENT_LEVEL","type":"string"},{"const":"LINE_LEVEL","type":"string"}]},"whtRate":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtAmount":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertBookNo":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertPndForm":{"anyOf":[{"anyOf":[{"const":"PND1A","type":"string"},{"const":"PND1A_SPECIAL","type":"string"},{"const":"PND2","type":"string"},{"const":"PND3","type":"string"},{"const":"PND2A","type":"string"},{"const":"PND3A","type":"string"},{"const":"PND53","type":"string"}]},{"type":"null"}]},"whtCertFormSeqNo":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertRemitMethod":{"anyOf":[{"anyOf":[{"const":"WITHHELD","type":"string"},{"const":"PAY_FOREVER","type":"string"},{"const":"PAY_ONCE","type":"string"},{"const":"OTHER","type":"string"}]},{"type":"null"}]},"whtCertRemitOther":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCertFundGpf":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertFundSso":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertFundPvd":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertDividendRate":{"anyOf":[{"type":"number"},{"type":"null"}]},"whtCertDividendOther":{"anyOf":[{"type":"string"},{"type":"null"}]},"lines":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["lineNo","description","quantity","unit","unitPrice","vatType"],"properties":{"lineNo":{"example":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1,"type":"number"}]},"productId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"sourceLineId":{"anyOf":[{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},{"type":"null"}]},"productSnapshot":{},"description":{"example":"สินค้า A","type":"string"},"note":{"anyOf":[{"type":"string"},{"type":"null"}]},"productDetail":{"anyOf":[{"type":"string"},{"type":"null"}]},"quantity":{"example":2,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":2,"type":"number"}]},"unit":{"example":"ชิ้น","type":"string"},"unitPrice":{"example":150,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":150,"type":"number"}]},"discountAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"discountPercent":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"vatType":{"example":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"whtRate":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtAmount":{"anyOf":[{"format":"numeric","default":0,"type":"string"},{"type":"number"}]},"whtRateId":{"anyOf":[{"type":"string"},{"type":"null"}]},"whtCategory":{"type":"string"},"whtIncomeType":{"description":"WHT_CERT: ประเภทเงินได้ ม.40","anyOf":[{"const":"M40_1","type":"string"},{"const":"M40_2","type":"string"},{"const":"M40_3","type":"string"},{"const":"M40_4A","type":"string"},{"const":"M40_4B","type":"string"},{"const":"M40_5","type":"string"},{"const":"M40_6","type":"string"},{"const":"M40_7","type":"string"},{"const":"M40_8","type":"string"},{"const":"OTHER","type":"string"}]},"whtDividendCase":{"description":"WHT_CERT: กรณีย่อยของข้อ 4(ข) — บังคับเมื่อ whtIncomeType = M40_4B","anyOf":[{"const":"1.1","type":"string"},{"const":"1.2","type":"string"},{"const":"1.3","type":"string"},{"const":"1.4","type":"string"},{"const":"2.1","type":"string"},{"const":"2.2","type":"string"},{"const":"2.3","type":"string"},{"const":"2.4","type":"string"},{"const":"2.5","type":"string"}]},"whtPaidOn":{"format":"date-time","description":"WHT_CERT: วันที่จ่ายเงินได้ของรายการนี้","type":"string"}}}}}}}}}},"delete":{"parameters":[{"description":"document id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"document id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"deleteV1DocumentsById","tags":["Documents"],"summary":"ลบเอกสารฉบับร่าง","description":"**ต้องมี scope `documents:delete`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ลบแบบ soft-delete และทำได้เฉพาะฉบับร่างตามนโยบายของ service — ออกเอกสารไปแล้วให้ใช้ยกเลิกแทน · สำเร็จ → 204 ไม่มี body · ลบไปแล้ว → 409 `ALREADY_DELETED` · ฉบับร่างที่มีคนกำลังแก้ในแอป → 409 `LOCK_HELD`","security":[{"bearerAuth":[]}],"responses":{"204":{"description":"ลบแล้ว (ไม่มี body)"},"404":{"description":"ไม่พบเอกสาร (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"409":{"description":"ลบไม่ได้ตามสถานะ/ถูกล็อกอยู่ (ALREADY_DELETED · LOCK_HELD)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id ไม่ใช่จำนวนเต็ม (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}}},"/v1/documents/jobs/{jobId}":{"get":{"parameters":[{"description":"job id ที่ได้จาก 202 ของ POST /documents","schema":{"type":"string","minLength":1},"in":"path","name":"jobId","required":true}],"operationId":"getV1DocumentsJobsByJobId","tags":["Documents"],"summary":"สถานะงานสร้างเอกสาร","description":"**ต้องมี scope `documents:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · สถานะไต่ `QUEUED → PROCESSING → DONE | FAILED | DEAD` · `DONE` แล้วใช้ `document_id` ไปเรียก `GET /v1/documents/{id}` ต่อได้ · `FAILED` = ผิดกฎธุรกิจ ไม่ retry ให้ · `DEAD` = ระบบ retry ครบแล้วยังไม่ผ่าน ทีมงานเห็นในคิวจดหมายตาย · อ่านจาก NATS KV เป็นหลัก (poll ถี่ได้ ไม่โดน DB) และตกลง MySQL เมื่อเกิน 24 ชม. · ไม่พบงาน → 404 `NOT_FOUND`","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"สถานะงานปัจจุบัน","content":{"application/json":{"schema":{"description":"สถานะงานสร้างเอกสาร (KV เส้นร้อน · MySQL เส้นเย็นเมื่อ KV หมดอายุ 24 ชม.)","type":"object","required":["job_id","status","document_id","document_no","error"],"properties":{"job_id":{"example":"job_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"status":{"example":"DONE","anyOf":[{"const":"QUEUED","type":"string"},{"const":"PROCESSING","type":"string"},{"const":"DONE","type":"string"},{"const":"FAILED","type":"string"},{"const":"DEAD","type":"string"}]},"document_id":{"anyOf":[{"multipleOf":1,"example":1042,"type":"number"},{"type":"null"}]},"document_no":{"anyOf":[{"example":"QT-2026-0001","type":"string"},{"type":"null"}]},"error":{"anyOf":[{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"VALIDATION","type":"string"},"message":{"example":"ยังไม่จดทะเบียน VAT","type":"string"}}},{"type":"null"}]}}}}}},"404":{"description":"ไม่พบงานสร้างเอกสารนี้ (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}}},"/v1/documents/{id}/convert":{"post":{"parameters":[{"description":"document id ของเอกสารต้นทาง","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"document id ของเอกสารต้นทาง","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"postV1DocumentsByIdConvert","tags":["Documents"],"summary":"สร้างเอกสารลูกจากเอกสารนี้ (แปลงเอกสาร)","description":"**ต้องมี scope `documents:convert`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · สร้างเอกสารใหม่ตาม `childType` โดยยกคู่ค้า/บรรทัดมาจากเอกสารต้นทาง — เอกสารต้นทางไม่ถูกแก้เนื้อหา · 201 พร้อมเอกสารลูก · สถานะต้นทางยังแปลงไม่ได้ → 409 `DOCUMENT_CONVERT_NOT_ALLOWED` · ใบแจ้งหนี้/ใบวางบิลที่ยังไม่รับชำระแปลงเป็นใบเสร็จไม่ได้ → 409 `DOCUMENT_CONVERT_PAYMENT_REQUIRED` · บริษัทที่ยังไม่จดทะเบียน VAT ออกใบกำกับภาษีไม่ได้ → 403 · id ต้องเป็นจำนวนเต็ม ไม่ใช่ → 422","security":[{"bearerAuth":[]}],"responses":{"201":{"description":"เอกสารลูกที่สร้างขึ้น","content":{"application/json":{"schema":{"additionalProperties":true,"description":"เอกสารลูกที่เพิ่งสร้าง — เรียก GET /v1/documents/{id} เพื่อดูฉบับเต็ม","type":"object","required":["id","status"],"properties":{"id":{"multipleOf":1,"type":"number"},"status":{"example":"ISSUED","type":"string"}}}}}},"403":{"description":"ยังไม่จดทะเบียน VAT (TAX_INVOICE_NOT_ALLOWED) หรือไม่มี scope (SCOPE_FORBIDDEN)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"404":{"description":"ไม่พบเอกสารต้นทาง (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"409":{"description":"สถานะปัจจุบันแปลงไม่ได้ (DOCUMENT_CONVERT_NOT_ALLOWED · DOCUMENT_CONVERT_PAYMENT_REQUIRED)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id หรือชนิดของฟิลด์ไม่ผ่านที่ขอบ (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"ชนิดเอกสารลูกที่ต้องการสร้างจากเอกสารนี้","type":"object","required":["childType"],"properties":{"childType":{"example":"INVOICE","anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"lineSelections":{"description":"เลือกบรรทัด/จำนวนที่ยกไปเอกสารลูก — ไม่ส่ง = ยกทั้งฉบับ","type":"array","items":{}},"issueDate":{"format":"date-time","type":"string"}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"ชนิดเอกสารลูกที่ต้องการสร้างจากเอกสารนี้","type":"object","required":["childType"],"properties":{"childType":{"example":"INVOICE","anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"lineSelections":{"description":"เลือกบรรทัด/จำนวนที่ยกไปเอกสารลูก — ไม่ส่ง = ยกทั้งฉบับ","type":"array","items":{}},"issueDate":{"format":"date-time","type":"string"}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"ชนิดเอกสารลูกที่ต้องการสร้างจากเอกสารนี้","type":"object","required":["childType"],"properties":{"childType":{"example":"INVOICE","anyOf":[{"const":"QUOTATION","type":"string"},{"const":"INVOICE","type":"string"},{"const":"TAX_INVOICE","type":"string"},{"const":"RECEIPT","type":"string"},{"const":"CREDIT_NOTE","type":"string"},{"const":"BILLING_NOTE","type":"string"},{"const":"PURCHASE_ORDER","type":"string"},{"const":"GOODS_RECEIPT","type":"string"},{"const":"DELIVERY_NOTE","type":"string"},{"const":"MATERIAL_REQUEST","type":"string"},{"const":"EXPENSE","type":"string"},{"const":"WHT_CERT","type":"string"}]},"lineSelections":{"description":"เลือกบรรทัด/จำนวนที่ยกไปเอกสารลูก — ไม่ส่ง = ยกทั้งฉบับ","type":"array","items":{}},"issueDate":{"format":"date-time","type":"string"}}}}}}}},"/v1/documents/{id}/issue":{"post":{"parameters":[{"description":"document id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"document id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"postV1DocumentsByIdIssue","tags":["Documents"],"summary":"ออกเอกสาร (ร่าง → ออกแล้ว/รอรับชำระ)","description":"**ต้องมี scope `documents:issue`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · เปลี่ยนสถานะจากร่างเป็นออกแล้ว/รอรับชำระ — เลขที่เอกสารถูกกำหนดตั้งแต่ตอนสร้างและไม่เปลี่ยนตอนออก · ออกได้เฉพาะฉบับร่าง — ออกไปแล้ว → 409 `ALREADY_ISSUED`, สถานะอื่น → 409 `ISSUE_NOT_ALLOWED` · ใบกำกับภาษีแบบตรงต้องแนบ `receiptPayment` ให้ครบ → ไม่ครบ 409 `TAX_INVOICE_PAYMENT_*` · มีคนกำลังแก้เอกสารนี้ในแอป → 409 `LOCK_HELD` · ส่ง header `Idempotency-Key` ได้เพื่อกันออกซ้ำ","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"เอกสารหลังออก","content":{"application/json":{"schema":{"additionalProperties":true,"description":"เอกสารหลังออก — สถานะใหม่ เลขที่เอกสารเท่าเดิมกับตอนสร้าง","type":"object","required":["id","status"],"properties":{"id":{"multipleOf":1,"type":"number"},"status":{"example":"ISSUED","type":"string"}}}}}},"404":{"description":"ไม่พบเอกสาร (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"409":{"description":"ออกไม่ได้ตามสถานะ/ถูกล็อกอยู่ (ALREADY_ISSUED · ISSUE_NOT_ALLOWED · TAX_INVOICE_PAYMENT_* · LOCK_HELD)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id หรือชนิดของฟิลด์ไม่ผ่านที่ขอบ (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"ออกเอกสาร — แนบ receiptPayment เฉพาะใบกำกับภาษีแบบตรง/ใบเสร็จที่ต้องบันทึกรับชำระพร้อมกัน","type":"object","properties":{"receiptPayment":{"additionalProperties":true,"type":"object","required":["paidDate","amount","method"],"properties":{"paidDate":{"format":"date-time","example":"2026-08-05T03:00:00.000Z","type":"string"},"amount":{"example":1070,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1070,"type":"number"}]},"method":{"example":"transfer","type":"string"},"bankRef":{"type":"string"},"note":{"type":"string"},"bankAccountName":{"type":"string"},"bankAccountNumber":{"type":"string"}}}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"ออกเอกสาร — แนบ receiptPayment เฉพาะใบกำกับภาษีแบบตรง/ใบเสร็จที่ต้องบันทึกรับชำระพร้อมกัน","type":"object","properties":{"receiptPayment":{"additionalProperties":true,"type":"object","required":["paidDate","amount","method"],"properties":{"paidDate":{"format":"date-time","example":"2026-08-05T03:00:00.000Z","type":"string"},"amount":{"example":1070,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1070,"type":"number"}]},"method":{"example":"transfer","type":"string"},"bankRef":{"type":"string"},"note":{"type":"string"},"bankAccountName":{"type":"string"},"bankAccountNumber":{"type":"string"}}}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"ออกเอกสาร — แนบ receiptPayment เฉพาะใบกำกับภาษีแบบตรง/ใบเสร็จที่ต้องบันทึกรับชำระพร้อมกัน","type":"object","properties":{"receiptPayment":{"additionalProperties":true,"type":"object","required":["paidDate","amount","method"],"properties":{"paidDate":{"format":"date-time","example":"2026-08-05T03:00:00.000Z","type":"string"},"amount":{"example":1070,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1070,"type":"number"}]},"method":{"example":"transfer","type":"string"},"bankRef":{"type":"string"},"note":{"type":"string"},"bankAccountName":{"type":"string"},"bankAccountNumber":{"type":"string"}}}}}}}}}},"/v1/documents/{id}/mark-paid":{"post":{"parameters":[{"description":"document id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"document id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"postV1DocumentsByIdMark-paid","tags":["Documents"],"summary":"บันทึกรับชำระ","description":"**ต้องมี scope `documents:mark_paid`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · บันทึกยอดที่รับจริง — ยอดเต็มปิดเป็นรับชำระแล้ว ยอดบางส่วนคงสถานะรับชำระบางส่วน · ทำได้เฉพาะเอกสารที่รอรับชำระ — สถานะอื่น → 409 `MARK_PAID_NOT_ALLOWED` · ยอดเกินคงเหลือ → 409 · เอกสารร่างยังบันทึกรับชำระไม่ได้ (ต้องออกก่อน)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"เอกสารหลังบันทึกรับชำระ","content":{"application/json":{"schema":{"additionalProperties":true,"description":"เอกสารหลังบันทึกรับชำระ","type":"object","required":["id","status"],"properties":{"id":{"multipleOf":1,"type":"number"},"status":{"example":"ISSUED","type":"string"}}}}}},"404":{"description":"ไม่พบเอกสาร (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"409":{"description":"บันทึกรับชำระไม่ได้ตามสถานะ/ยอดเกิน (MARK_PAID_NOT_ALLOWED)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id หรือชนิดของฟิลด์ไม่ผ่านที่ขอบ (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"ยอดที่รับชำระจริง — เกินยอดคงเหลือของเอกสารจะถูกปฏิเสธที่ service","type":"object","required":["amount"],"properties":{"amount":{"example":1070,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1070,"type":"number"}]},"paidDate":{"format":"date-time","type":"string"},"method":{"example":"transfer","type":"string"},"bankRef":{"type":"string"},"note":{"type":"string"},"bankAccountName":{"type":"string"},"bankAccountNumber":{"type":"string"}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"ยอดที่รับชำระจริง — เกินยอดคงเหลือของเอกสารจะถูกปฏิเสธที่ service","type":"object","required":["amount"],"properties":{"amount":{"example":1070,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1070,"type":"number"}]},"paidDate":{"format":"date-time","type":"string"},"method":{"example":"transfer","type":"string"},"bankRef":{"type":"string"},"note":{"type":"string"},"bankAccountName":{"type":"string"},"bankAccountNumber":{"type":"string"}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"ยอดที่รับชำระจริง — เกินยอดคงเหลือของเอกสารจะถูกปฏิเสธที่ service","type":"object","required":["amount"],"properties":{"amount":{"example":1070,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"example":1070,"type":"number"}]},"paidDate":{"format":"date-time","type":"string"},"method":{"example":"transfer","type":"string"},"bankRef":{"type":"string"},"note":{"type":"string"},"bankAccountName":{"type":"string"},"bankAccountNumber":{"type":"string"}}}}}}}},"/v1/documents/{id}/void":{"post":{"parameters":[{"description":"document id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"document id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"postV1DocumentsByIdVoid","tags":["Documents"],"summary":"ยกเลิกเอกสาร (พร้อมเอกสารต่อเนื่อง)","description":"**ต้องมี scope `documents:void`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ยกเลิกเอกสารและเอกสารที่สืบต่อจากมันตามนโยบายของระบบ — `voidSummary` บอกว่ายกเลิกไปกี่ฉบับ · ยกเลิกไม่ได้ตามนโยบาย → 409 พร้อม code จาก void-policy · ยกเลิกฉบับร่างที่มีคนกำลังแก้ในแอป → 409 `LOCK_HELD`","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"เอกสารหลังยกเลิก พร้อมสรุปการยกเลิกต่อเนื่อง","content":{"application/json":{"schema":{"additionalProperties":true,"description":"เอกสารหลังยกเลิก — เรียก GET /v1/documents/{id} เพื่อดูฉบับเต็ม","type":"object","required":["id","status","voidSummary"],"properties":{"id":{"multipleOf":1,"type":"number"},"status":{"example":"CANCELLED","type":"string"},"voidSummary":{"additionalProperties":true,"type":"object","required":["cancelledDocumentIds","cancelledCount","cascaded"],"properties":{"cancelledDocumentIds":{"type":"array","items":{"multipleOf":1,"type":"number"}},"cancelledCount":{"multipleOf":1,"example":1,"type":"number"},"cascaded":{"example":false,"type":"boolean"}}}}}}}},"404":{"description":"ไม่พบเอกสาร (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"409":{"description":"ยกเลิกไม่ได้ตามนโยบาย/ถูกล็อกอยู่ (VOID_POLICY code · LOCK_HELD)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id หรือชนิดของฟิลด์ไม่ผ่านที่ขอบ (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"เหตุผลการยกเลิก (ไม่บังคับ)","type":"object","properties":{"reason":{"example":"ลูกค้ายกเลิกคำสั่งซื้อ","type":"string"}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"เหตุผลการยกเลิก (ไม่บังคับ)","type":"object","properties":{"reason":{"example":"ลูกค้ายกเลิกคำสั่งซื้อ","type":"string"}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"เหตุผลการยกเลิก (ไม่บังคับ)","type":"object","properties":{"reason":{"example":"ลูกค้ายกเลิกคำสั่งซื้อ","type":"string"}}}}}}}},"/v1/documents/{id}/share-links":{"post":{"parameters":[{"description":"document id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"document id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"postV1DocumentsByIdShare-links","tags":["Share links"],"summary":"สร้างลิงก์แชร์เอกสารแบบสาธารณะ","description":"**ต้องมี scope `documents:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ตอบ 201 พร้อม token แบบ plaintext **ครั้งเดียว** · url = `<APP_BASE_URL>/share/<token>` เปิดได้โดยไม่ต้อง login · ส่ง pin (ตัวเลข 6 หลัก) เพื่อบังคับกรอก PIN ก่อนดู · pin ผิดรูป → 400 VALIDATION · ไม่พบเอกสาร/คนละบริษัท → 404 NOT_FOUND · อายุลิงก์ (ttlDays) มาจากค่าตั้งขององค์กรตอนสร้าง และเริ่มนับเมื่อมีคนเปิดใช้ครั้งแรก · ใช้ scope เดิมของการอ่านเอกสาร — **คีย์ทุกใบที่มี `documents:read` (หรือ `documents:*`) สร้างลิงก์แชร์สาธารณะได้ทันที** ไม่มี scope แยกสำหรับการแชร์","security":[{"bearerAuth":[]}],"responses":{"201":{"description":"ลิงก์ที่สร้างใหม่ (มี token ครั้งเดียว)","content":{"application/json":{"schema":{"additionalProperties":true,"description":"token เป็น plaintext ที่โผล่ครั้งเดียวในชีวิตของลิงก์ — เก็บไม่ทันคือต้องสร้างลิงก์ใหม่","type":"object","required":["url","token","link"],"properties":{"url":{"example":"https://ketbill.com/share/8f2c1d0e4b6a9c3f","type":"string"},"token":{"example":"8f2c1d0e4b6a9c3f","type":"string"},"link":{"additionalProperties":true,"description":"ลิงก์หนึ่งเส้น · PENDING = ยังไม่มีใครเปิดใช้ (ไม่มีวันหมดอายุเอง) · expiresAt/remainingDays เป็น null จนถูกเปิดใช้ · ttlDays ถูกแช่ไว้ตอนสร้าง ไม่ใช่ค่าปัจจุบันขององค์กร","type":"object","required":["id","documentId","status","requiresPin","ttlDays","activatedAt","expiresAt","remainingDays","revokedAt","viewCount","lastViewedAt","createdVia","createdByUserId","createdAt"],"properties":{"id":{"multipleOf":1,"example":21,"type":"number"},"documentId":{"multipleOf":1,"example":1042,"type":"number"},"status":{"example":"PENDING","anyOf":[{"const":"PENDING","type":"string"},{"const":"ACTIVE","type":"string"},{"const":"EXPIRED","type":"string"},{"const":"REVOKED","type":"string"}]},"requiresPin":{"example":false,"type":"boolean"},"ttlDays":{"multipleOf":1,"example":15,"type":"number"},"activatedAt":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"expiresAt":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"remainingDays":{"anyOf":[{"multipleOf":1,"example":15,"type":"number"},{"type":"null"}]},"revokedAt":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"viewCount":{"multipleOf":1,"example":0,"type":"number"},"lastViewedAt":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"createdVia":{"example":"OPEN_API","anyOf":[{"const":"UI","type":"string"},{"const":"OPEN_API","type":"string"},{"const":"MCP","type":"string"}]},"createdByUserId":{"anyOf":[{"multipleOf":1,"example":7,"type":"number"},{"type":"null"}]},"createdAt":{"format":"date-time","type":"string"}}}}}}}},"400":{"description":"pin ไม่ใช่ตัวเลข 6 หลัก (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"404":{"description":"ไม่พบเอกสาร (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id ไม่ใช่จำนวนเต็ม (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"ไม่ส่ง pin หรือส่ง null = ลิงก์สาธารณะ · ส่ง pin = ตัวเลข 6 หลักเท่านั้น","type":"object","properties":{"pin":{"anyOf":[{"example":"482913","type":"string"},{"type":"null"}]}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"ไม่ส่ง pin หรือส่ง null = ลิงก์สาธารณะ · ส่ง pin = ตัวเลข 6 หลักเท่านั้น","type":"object","properties":{"pin":{"anyOf":[{"example":"482913","type":"string"},{"type":"null"}]}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"ไม่ส่ง pin หรือส่ง null = ลิงก์สาธารณะ · ส่ง pin = ตัวเลข 6 หลักเท่านั้น","type":"object","properties":{"pin":{"anyOf":[{"example":"482913","type":"string"},{"type":"null"}]}}}}}}},"get":{"parameters":[{"description":"document id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"document id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"getV1DocumentsByIdShare-links","tags":["Share links"],"summary":"ลิงก์แชร์ทั้งหมดของเอกสารหนึ่งฉบับ","description":"**ต้องมี scope `documents:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · คืน array เปล่า ๆ (ไม่ห่อ items/total) ใหม่สุดก่อน · ไม่มี token/tokenHash/pinHash ในผลลัพธ์ — token ได้ตอนสร้างเท่านั้น · เอกสารที่ไม่มีลิงก์เลยได้ `[]` ไม่ใช่ 404 · ใช้ scope เดิมของการอ่านเอกสาร — **คีย์ทุกใบที่มี `documents:read` (หรือ `documents:*`) สร้างลิงก์แชร์สาธารณะได้ทันที** ไม่มี scope แยกสำหรับการแชร์","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"ลิงก์ทั้งหมดของเอกสารนี้","content":{"application/json":{"schema":{"description":"ลิงก์ทุกเส้นที่เคยสร้างของเอกสารนี้ ใหม่สุดก่อน รวมเส้นที่ถูกเพิกถอน/หมดอายุแล้ว","type":"array","items":{"additionalProperties":true,"description":"ลิงก์หนึ่งเส้น · PENDING = ยังไม่มีใครเปิดใช้ (ไม่มีวันหมดอายุเอง) · expiresAt/remainingDays เป็น null จนถูกเปิดใช้ · ttlDays ถูกแช่ไว้ตอนสร้าง ไม่ใช่ค่าปัจจุบันขององค์กร","type":"object","required":["id","documentId","status","requiresPin","ttlDays","activatedAt","expiresAt","remainingDays","revokedAt","viewCount","lastViewedAt","createdVia","createdByUserId","createdAt"],"properties":{"id":{"multipleOf":1,"example":21,"type":"number"},"documentId":{"multipleOf":1,"example":1042,"type":"number"},"status":{"example":"PENDING","anyOf":[{"const":"PENDING","type":"string"},{"const":"ACTIVE","type":"string"},{"const":"EXPIRED","type":"string"},{"const":"REVOKED","type":"string"}]},"requiresPin":{"example":false,"type":"boolean"},"ttlDays":{"multipleOf":1,"example":15,"type":"number"},"activatedAt":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"expiresAt":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"remainingDays":{"anyOf":[{"multipleOf":1,"example":15,"type":"number"},{"type":"null"}]},"revokedAt":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"viewCount":{"multipleOf":1,"example":0,"type":"number"},"lastViewedAt":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"createdVia":{"example":"OPEN_API","anyOf":[{"const":"UI","type":"string"},{"const":"OPEN_API","type":"string"},{"const":"MCP","type":"string"}]},"createdByUserId":{"anyOf":[{"multipleOf":1,"example":7,"type":"number"},{"type":"null"}]},"createdAt":{"format":"date-time","type":"string"}}}}}}},"422":{"description":"id ไม่ใช่จำนวนเต็ม (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}}},"/v1/share-links/{id}":{"delete":{"parameters":[{"description":"share link id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"share link id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"deleteV1Share-linksById","tags":["Share links"],"summary":"เพิกถอนลิงก์แชร์","description":"**ต้องมี scope `documents:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · การเพิกถอนชนะทุกสถานะ — ลิงก์ที่ถูกเพิกถอนแล้วเปิดไม่ได้อีก แม้ยังไม่หมดอายุ · เรียกซ้ำได้ ครั้งหลังตอบ `{ \"revoked\": false }` ไม่ใช่ error · ไม่พบลิงก์/คนละบริษัท → 404 NOT_FOUND · ใช้ scope เดิมของการอ่านเอกสาร — **คีย์ทุกใบที่มี `documents:read` (หรือ `documents:*`) สร้างลิงก์แชร์สาธารณะได้ทันที** ไม่มี scope แยกสำหรับการแชร์","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"ผลการเพิกถอน","content":{"application/json":{"schema":{"additionalProperties":true,"description":"false = ถูกเพิกถอนไปก่อนแล้ว (idempotent ไม่ error ไม่เขียน audit ซ้ำ)","type":"object","required":["revoked"],"properties":{"revoked":{"example":true,"type":"boolean"}}}}}},"404":{"description":"ไม่พบลิงก์ (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id ไม่ใช่จำนวนเต็ม (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}}},"/v1/clients":{"get":{"parameters":[{"description":"หน้า (เริ่มที่ 1) / page","schema":{"default":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"default":1,"description":"หน้า (เริ่มที่ 1) / page","type":"number"}]},"in":"query","name":"page","required":false},{"description":"จำนวนต่อหน้า / page size","schema":{"default":20,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"default":20,"description":"จำนวนต่อหน้า / page size","type":"number"}]},"in":"query","name":"limit","required":false},{"description":"คำค้น / search term","schema":{"type":"string"},"in":"query","name":"q","required":false},{"schema":{"anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"in":"query","name":"kind","required":false}],"operationId":"getV1Clients","tags":["Clients"],"summary":"รายการลูกค้า (own-company)","description":"**ต้องมี scope `clients:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · คืน **อาเรย์ตรง ๆ** ไม่ได้ห่อด้วย `{ items, total }` · เลื่อนหน้าด้วย `page`/`limit`","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"รายการลูกค้า/ผู้ขาย","content":{"application/json":{"schema":{"description":"อาเรย์ตรง ๆ (ไม่ห่อ items/total) — ใช้ page/limit เลื่อนหน้า","type":"array","items":{"additionalProperties":true,"description":"ลูกค้า/ผู้ขาย — ตัวเลขเงินทุกตัวเป็น string และตัดศูนย์ท้ายทิ้ง","type":"object","required":["id","companyId","accountManagerId","kind","code","customCode","externalId","legalName","displayName","ownerName","clientType","taxId","branchCode","branchName","email","phone","fax","website","lineId","creditLimit","creditMonths","creditDays","defaultWhtRate","notes","logoUrl","signatureUrl","stampUrl","isActive","createdAt","updatedAt","deletedAt","addresses","clientPersons","accountManager"],"properties":{"id":{"multipleOf":1,"example":10,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"accountManagerId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"code":{"anyOf":[{"description":"รหัสที่ระบบ gen ให้ — CUS/VEN/BTH ตามชนิด","example":"V-0002","type":"string"},{"type":"null"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"description":"รหัสอ้างอิงจากระบบต้นทาง (ถ้าสร้างผ่าน upsert)","type":"string"},{"type":"null"}]},"legalName":{"example":"บริษัท คลาวด์ โซลูชั่น จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"description":"JURISTIC เป็นค่า legacy — ข้อมูลเก่ายังคืนค่านี้ได้","example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105559900112","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"example":"00000","type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"example":"สำนักงานใหญ่","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"02-301-5555","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"description":"วงเงินเครดิต — ตัวเลขคืนเป็น string","example":"1234.5","type":"string"},{"type":"null"}]},"creditMonths":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"creditDays":{"anyOf":[{"multipleOf":1,"example":30,"type":"number"},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"description":"อัตราหัก ณ ที่จ่ายเริ่มต้น (%)","example":"1234.5","type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"logoUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"signatureUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"stampUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","clientId","label","isPrimary","isBilling","isShipping","branchCode","branchName","addressLine1","addressLine2","subDistrict","district","province","postalCode","country","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"clientId":{"multipleOf":1,"type":"number"},"label":{"example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"type":"boolean"},"isBilling":{"type":"boolean"},"isShipping":{"type":"boolean"},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"example":"TH","type":"string"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","clientId","name","position","email","phone","isPrimary","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"clientId":{"multipleOf":1,"type":"number"},"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"type":"string"},{"type":"null"}]},"isPrimary":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"}}}},"accountManager":{"anyOf":[{"additionalProperties":true,"description":"ผู้ดูแล (User) — null เมื่อไม่ได้กำหนด","type":"object","properties":{}},{"type":"null"}]}}}}}}}}},"post":{"parameters":[],"operationId":"postV1Clients","tags":["Clients"],"summary":"สร้างลูกค้า","description":"**ต้องมี scope `clients:create`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ส่ง `externalId` = upsert ตาม (บริษัท, externalId): สร้างใหม่ → `201`, มีอยู่แล้วและถูกอัปเดต → `200` · ไม่ส่ง `externalId` = สร้างใหม่เสมอ (`201`) · body คือตัวลูกค้าเอง ไม่ได้ห่อ · field บังคับที่ขาด → `422 VALIDATION` (TypeBox ที่ขอบตรวจก่อน zod)","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"อัปเดตลูกค้าเดิมที่ externalId ตรงกัน","content":{"application/json":{"schema":{"additionalProperties":true,"description":"ลูกค้า/ผู้ขาย — ตัวเลขเงินทุกตัวเป็น string และตัดศูนย์ท้ายทิ้ง","type":"object","required":["id","companyId","accountManagerId","kind","code","customCode","externalId","legalName","displayName","ownerName","clientType","taxId","branchCode","branchName","email","phone","fax","website","lineId","creditLimit","creditMonths","creditDays","defaultWhtRate","notes","logoUrl","signatureUrl","stampUrl","isActive","createdAt","updatedAt","deletedAt","addresses","clientPersons","accountManager"],"properties":{"id":{"multipleOf":1,"example":10,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"accountManagerId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"code":{"anyOf":[{"description":"รหัสที่ระบบ gen ให้ — CUS/VEN/BTH ตามชนิด","example":"V-0002","type":"string"},{"type":"null"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"description":"รหัสอ้างอิงจากระบบต้นทาง (ถ้าสร้างผ่าน upsert)","type":"string"},{"type":"null"}]},"legalName":{"example":"บริษัท คลาวด์ โซลูชั่น จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"description":"JURISTIC เป็นค่า legacy — ข้อมูลเก่ายังคืนค่านี้ได้","example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105559900112","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"example":"00000","type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"example":"สำนักงานใหญ่","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"02-301-5555","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"description":"วงเงินเครดิต — ตัวเลขคืนเป็น string","example":"1234.5","type":"string"},{"type":"null"}]},"creditMonths":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"creditDays":{"anyOf":[{"multipleOf":1,"example":30,"type":"number"},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"description":"อัตราหัก ณ ที่จ่ายเริ่มต้น (%)","example":"1234.5","type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"logoUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"signatureUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"stampUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","clientId","label","isPrimary","isBilling","isShipping","branchCode","branchName","addressLine1","addressLine2","subDistrict","district","province","postalCode","country","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"clientId":{"multipleOf":1,"type":"number"},"label":{"example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"type":"boolean"},"isBilling":{"type":"boolean"},"isShipping":{"type":"boolean"},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"example":"TH","type":"string"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","clientId","name","position","email","phone","isPrimary","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"clientId":{"multipleOf":1,"type":"number"},"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"type":"string"},{"type":"null"}]},"isPrimary":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"}}}},"accountManager":{"anyOf":[{"additionalProperties":true,"description":"ผู้ดูแล (User) — null เมื่อไม่ได้กำหนด","type":"object","properties":{}},{"type":"null"}]}}}}}},"201":{"description":"สร้างลูกค้าใหม่แล้ว","content":{"application/json":{"schema":{"additionalProperties":true,"description":"ลูกค้า/ผู้ขาย — ตัวเลขเงินทุกตัวเป็น string และตัดศูนย์ท้ายทิ้ง","type":"object","required":["id","companyId","accountManagerId","kind","code","customCode","externalId","legalName","displayName","ownerName","clientType","taxId","branchCode","branchName","email","phone","fax","website","lineId","creditLimit","creditMonths","creditDays","defaultWhtRate","notes","logoUrl","signatureUrl","stampUrl","isActive","createdAt","updatedAt","deletedAt","addresses","clientPersons","accountManager"],"properties":{"id":{"multipleOf":1,"example":10,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"accountManagerId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"code":{"anyOf":[{"description":"รหัสที่ระบบ gen ให้ — CUS/VEN/BTH ตามชนิด","example":"V-0002","type":"string"},{"type":"null"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"description":"รหัสอ้างอิงจากระบบต้นทาง (ถ้าสร้างผ่าน upsert)","type":"string"},{"type":"null"}]},"legalName":{"example":"บริษัท คลาวด์ โซลูชั่น จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"description":"JURISTIC เป็นค่า legacy — ข้อมูลเก่ายังคืนค่านี้ได้","example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105559900112","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"example":"00000","type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"example":"สำนักงานใหญ่","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"02-301-5555","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"description":"วงเงินเครดิต — ตัวเลขคืนเป็น string","example":"1234.5","type":"string"},{"type":"null"}]},"creditMonths":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"creditDays":{"anyOf":[{"multipleOf":1,"example":30,"type":"number"},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"description":"อัตราหัก ณ ที่จ่ายเริ่มต้น (%)","example":"1234.5","type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"logoUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"signatureUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"stampUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","clientId","label","isPrimary","isBilling","isShipping","branchCode","branchName","addressLine1","addressLine2","subDistrict","district","province","postalCode","country","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"clientId":{"multipleOf":1,"type":"number"},"label":{"example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"type":"boolean"},"isBilling":{"type":"boolean"},"isShipping":{"type":"boolean"},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"example":"TH","type":"string"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","clientId","name","position","email","phone","isPrimary","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"clientId":{"multipleOf":1,"type":"number"},"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"type":"string"},{"type":"null"}]},"isPrimary":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"}}}},"accountManager":{"anyOf":[{"additionalProperties":true,"description":"ผู้ดูแล (User) — null เมื่อไม่ได้กำหนด","type":"object","properties":{}},{"type":"null"}]}}}}}},"422":{"description":"body ไม่ผ่าน schema ที่ขอบ (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"ลูกค้า/ผู้ขายที่จะสร้าง (ฟิลด์ตรงกับ clientCreateSchema) — ระบบ gen รหัสลูกค้าให้อัตโนมัติ","type":"object","required":["kind","legalName"],"properties":{"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"example":"cms-contact-123","description":"รหัสอ้างอิงจาก CMS — ส่งมาเพื่อ upsert (สร้าง/อัปเดต) ตาม (บริษัท, externalId)","type":"string"},{"type":"null"}]},"legalName":{"minLength":1,"example":"บริษัท ตัวอย่าง จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105512345678","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"021234567","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"contact@example.co.th","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"default":true,"type":"boolean"},"accountManagerId":{"anyOf":[{"example":5,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":5,"type":"integer"}]},{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"example":100000,"type":"number"},{"type":"null"}]},"creditMonths":{"anyOf":[{"example":2,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":2,"type":"integer"}]},{"type":"null"}]},"creditDays":{"anyOf":[{"example":30,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":30,"type":"integer"}]},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"example":3,"type":"number"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["addressLine1"],"properties":{"label":{"default":"ที่อยู่หลัก","example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"default":false,"description":"ไม่ระบุที่อยู่หลักเลย → ระบบตั้งที่อยู่แรกให้เป็นหลัก","type":"boolean"},"isBilling":{"default":true,"type":"boolean"},"isShipping":{"default":false,"type":"boolean"},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"default":"TH","example":"TH","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["name"],"properties":{"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"wichai@example.co.th","type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"0812345678","type":"string"},{"type":"null"}]},"isPrimary":{"default":false,"type":"boolean"}}}}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"ลูกค้า/ผู้ขายที่จะสร้าง (ฟิลด์ตรงกับ clientCreateSchema) — ระบบ gen รหัสลูกค้าให้อัตโนมัติ","type":"object","required":["kind","legalName"],"properties":{"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"example":"cms-contact-123","description":"รหัสอ้างอิงจาก CMS — ส่งมาเพื่อ upsert (สร้าง/อัปเดต) ตาม (บริษัท, externalId)","type":"string"},{"type":"null"}]},"legalName":{"minLength":1,"example":"บริษัท ตัวอย่าง จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105512345678","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"021234567","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"contact@example.co.th","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"default":true,"type":"boolean"},"accountManagerId":{"anyOf":[{"example":5,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":5,"type":"integer"}]},{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"example":100000,"type":"number"},{"type":"null"}]},"creditMonths":{"anyOf":[{"example":2,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":2,"type":"integer"}]},{"type":"null"}]},"creditDays":{"anyOf":[{"example":30,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":30,"type":"integer"}]},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"example":3,"type":"number"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["addressLine1"],"properties":{"label":{"default":"ที่อยู่หลัก","example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"default":false,"description":"ไม่ระบุที่อยู่หลักเลย → ระบบตั้งที่อยู่แรกให้เป็นหลัก","type":"boolean"},"isBilling":{"default":true,"type":"boolean"},"isShipping":{"default":false,"type":"boolean"},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"default":"TH","example":"TH","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["name"],"properties":{"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"wichai@example.co.th","type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"0812345678","type":"string"},{"type":"null"}]},"isPrimary":{"default":false,"type":"boolean"}}}}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"ลูกค้า/ผู้ขายที่จะสร้าง (ฟิลด์ตรงกับ clientCreateSchema) — ระบบ gen รหัสลูกค้าให้อัตโนมัติ","type":"object","required":["kind","legalName"],"properties":{"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"example":"cms-contact-123","description":"รหัสอ้างอิงจาก CMS — ส่งมาเพื่อ upsert (สร้าง/อัปเดต) ตาม (บริษัท, externalId)","type":"string"},{"type":"null"}]},"legalName":{"minLength":1,"example":"บริษัท ตัวอย่าง จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105512345678","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"021234567","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"contact@example.co.th","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"default":true,"type":"boolean"},"accountManagerId":{"anyOf":[{"example":5,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":5,"type":"integer"}]},{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"example":100000,"type":"number"},{"type":"null"}]},"creditMonths":{"anyOf":[{"example":2,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":2,"type":"integer"}]},{"type":"null"}]},"creditDays":{"anyOf":[{"example":30,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":30,"type":"integer"}]},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"example":3,"type":"number"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["addressLine1"],"properties":{"label":{"default":"ที่อยู่หลัก","example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"default":false,"description":"ไม่ระบุที่อยู่หลักเลย → ระบบตั้งที่อยู่แรกให้เป็นหลัก","type":"boolean"},"isBilling":{"default":true,"type":"boolean"},"isShipping":{"default":false,"type":"boolean"},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"default":"TH","example":"TH","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["name"],"properties":{"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"wichai@example.co.th","type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"0812345678","type":"string"},{"type":"null"}]},"isPrimary":{"default":false,"type":"boolean"}}}}}}}}}}},"/v1/clients/{id}":{"put":{"parameters":[{"description":"client id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"client id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"putV1ClientsById","tags":["Clients"],"summary":"แก้ไขลูกค้า","description":"**ต้องมี scope `clients:update`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ส่งเฉพาะฟิลด์ที่ต้องการแก้ · id ต้องเป็นจำนวนเต็มตั้งแต่ 1 ขึ้นไป ไม่ใช่ → `422` · ไม่พบลูกค้า/คนละบริษัท/ถูกลบแล้ว → `404 NOT_FOUND` · ส่ง `addresses` หรือ `clientPersons` มา = **แทนที่ทั้งชุด** (ของเดิมถูกลบก่อนเขียนใหม่) ไม่ส่ง = คงของเดิมไว้ · ไม่ใช่ upsert ตาม `externalId` เหมือน `POST` — เส้นนี้อ้างอิง id เท่านั้น","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"ลูกค้าหลังแก้ไข","content":{"application/json":{"schema":{"additionalProperties":true,"description":"ลูกค้า/ผู้ขาย — ตัวเลขเงินทุกตัวเป็น string และตัดศูนย์ท้ายทิ้ง","type":"object","required":["id","companyId","accountManagerId","kind","code","customCode","externalId","legalName","displayName","ownerName","clientType","taxId","branchCode","branchName","email","phone","fax","website","lineId","creditLimit","creditMonths","creditDays","defaultWhtRate","notes","logoUrl","signatureUrl","stampUrl","isActive","createdAt","updatedAt","deletedAt","addresses","clientPersons","accountManager"],"properties":{"id":{"multipleOf":1,"example":10,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"accountManagerId":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"code":{"anyOf":[{"description":"รหัสที่ระบบ gen ให้ — CUS/VEN/BTH ตามชนิด","example":"V-0002","type":"string"},{"type":"null"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"description":"รหัสอ้างอิงจากระบบต้นทาง (ถ้าสร้างผ่าน upsert)","type":"string"},{"type":"null"}]},"legalName":{"example":"บริษัท คลาวด์ โซลูชั่น จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"description":"JURISTIC เป็นค่า legacy — ข้อมูลเก่ายังคืนค่านี้ได้","example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105559900112","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"example":"00000","type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"example":"สำนักงานใหญ่","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"02-301-5555","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"description":"วงเงินเครดิต — ตัวเลขคืนเป็น string","example":"1234.5","type":"string"},{"type":"null"}]},"creditMonths":{"anyOf":[{"multipleOf":1,"type":"number"},{"type":"null"}]},"creditDays":{"anyOf":[{"multipleOf":1,"example":30,"type":"number"},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"description":"อัตราหัก ณ ที่จ่ายเริ่มต้น (%)","example":"1234.5","type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"logoUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"signatureUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"stampUrl":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","clientId","label","isPrimary","isBilling","isShipping","branchCode","branchName","addressLine1","addressLine2","subDistrict","district","province","postalCode","country","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"clientId":{"multipleOf":1,"type":"number"},"label":{"example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"type":"boolean"},"isBilling":{"type":"boolean"},"isShipping":{"type":"boolean"},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"example":"TH","type":"string"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","clientId","name","position","email","phone","isPrimary","createdAt"],"properties":{"id":{"multipleOf":1,"type":"number"},"clientId":{"multipleOf":1,"type":"number"},"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"type":"string"},{"type":"null"}]},"isPrimary":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"}}}},"accountManager":{"anyOf":[{"additionalProperties":true,"description":"ผู้ดูแล (User) — null เมื่อไม่ได้กำหนด","type":"object","properties":{}},{"type":"null"}]}}}}}},"404":{"description":"ไม่พบลูกค้า (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id หรือชนิดของฟิลด์ไม่ผ่านที่ขอบ (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"ฟิลด์ที่ต้องการแก้ (ตรงกับ clientUpdateSchema) — ส่งเฉพาะที่แก้ ไม่ต้องส่งครบ","type":"object","properties":{"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"example":"cms-contact-123","description":"รหัสอ้างอิงจาก CMS","type":"string"},{"type":"null"}]},"legalName":{"minLength":1,"example":"บริษัท ตัวอย่าง จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105512345678","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"021234567","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"contact@example.co.th","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"type":"boolean"},"accountManagerId":{"anyOf":[{"example":5,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":5,"type":"integer"}]},{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"example":100000,"type":"number"},{"type":"null"}]},"creditMonths":{"anyOf":[{"example":2,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":2,"type":"integer"}]},{"type":"null"}]},"creditDays":{"anyOf":[{"example":30,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":30,"type":"integer"}]},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"example":3,"type":"number"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["addressLine1"],"properties":{"label":{"default":"ที่อยู่หลัก","example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"default":false,"description":"ไม่ระบุที่อยู่หลักเลย → ระบบตั้งที่อยู่แรกให้เป็นหลัก","type":"boolean"},"isBilling":{"default":true,"type":"boolean"},"isShipping":{"default":false,"type":"boolean"},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"default":"TH","example":"TH","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["name"],"properties":{"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"wichai@example.co.th","type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"0812345678","type":"string"},{"type":"null"}]},"isPrimary":{"default":false,"type":"boolean"}}}}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"ฟิลด์ที่ต้องการแก้ (ตรงกับ clientUpdateSchema) — ส่งเฉพาะที่แก้ ไม่ต้องส่งครบ","type":"object","properties":{"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"example":"cms-contact-123","description":"รหัสอ้างอิงจาก CMS","type":"string"},{"type":"null"}]},"legalName":{"minLength":1,"example":"บริษัท ตัวอย่าง จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105512345678","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"021234567","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"contact@example.co.th","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"type":"boolean"},"accountManagerId":{"anyOf":[{"example":5,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":5,"type":"integer"}]},{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"example":100000,"type":"number"},{"type":"null"}]},"creditMonths":{"anyOf":[{"example":2,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":2,"type":"integer"}]},{"type":"null"}]},"creditDays":{"anyOf":[{"example":30,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":30,"type":"integer"}]},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"example":3,"type":"number"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["addressLine1"],"properties":{"label":{"default":"ที่อยู่หลัก","example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"default":false,"description":"ไม่ระบุที่อยู่หลักเลย → ระบบตั้งที่อยู่แรกให้เป็นหลัก","type":"boolean"},"isBilling":{"default":true,"type":"boolean"},"isShipping":{"default":false,"type":"boolean"},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"default":"TH","example":"TH","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["name"],"properties":{"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"wichai@example.co.th","type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"0812345678","type":"string"},{"type":"null"}]},"isPrimary":{"default":false,"type":"boolean"}}}}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"ฟิลด์ที่ต้องการแก้ (ตรงกับ clientUpdateSchema) — ส่งเฉพาะที่แก้ ไม่ต้องส่งครบ","type":"object","properties":{"kind":{"example":"CUSTOMER","anyOf":[{"const":"CUSTOMER","type":"string"},{"const":"VENDOR","type":"string"},{"const":"BOTH","type":"string"}]},"customCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"example":"cms-contact-123","description":"รหัสอ้างอิงจาก CMS","type":"string"},{"type":"null"}]},"legalName":{"minLength":1,"example":"บริษัท ตัวอย่าง จำกัด","type":"string"},"displayName":{"anyOf":[{"type":"string"},{"type":"null"}]},"ownerName":{"anyOf":[{"type":"string"},{"type":"null"}]},"clientType":{"example":"COMPANY","anyOf":[{"const":"COMPANY","type":"string"},{"const":"PARTNERSHIP","type":"string"},{"const":"INDIVIDUAL","type":"string"},{"const":"GOVERNMENT","type":"string"},{"const":"ASSOCIATION","type":"string"},{"const":"FOREIGN","type":"string"},{"const":"JURISTIC","type":"string"}]},"taxId":{"anyOf":[{"example":"0105512345678","type":"string"},{"type":"null"}]},"branchCode":{"anyOf":[{"type":"string"},{"type":"null"}]},"branchName":{"anyOf":[{"type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"021234567","type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"contact@example.co.th","type":"string"},{"type":"null"}]},"fax":{"anyOf":[{"type":"string"},{"type":"null"}]},"website":{"anyOf":[{"type":"string"},{"type":"null"}]},"lineId":{"anyOf":[{"type":"string"},{"type":"null"}]},"notes":{"anyOf":[{"type":"string"},{"type":"null"}]},"isActive":{"type":"boolean"},"accountManagerId":{"anyOf":[{"example":5,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":5,"type":"integer"}]},{"type":"string"},{"type":"null"}]},"creditLimit":{"anyOf":[{"example":100000,"type":"number"},{"type":"null"}]},"creditMonths":{"anyOf":[{"example":2,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":2,"type":"integer"}]},{"type":"null"}]},"creditDays":{"anyOf":[{"example":30,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":30,"type":"integer"}]},{"type":"null"}]},"defaultWhtRate":{"anyOf":[{"example":3,"type":"number"},{"type":"null"}]},"addresses":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["addressLine1"],"properties":{"label":{"default":"ที่อยู่หลัก","example":"สำนักงานใหญ่","type":"string"},"isPrimary":{"default":false,"description":"ไม่ระบุที่อยู่หลักเลย → ระบบตั้งที่อยู่แรกให้เป็นหลัก","type":"boolean"},"isBilling":{"default":true,"type":"boolean"},"isShipping":{"default":false,"type":"boolean"},"addressLine1":{"example":"313 ถนนสีลม","type":"string"},"addressLine2":{"anyOf":[{"type":"string"},{"type":"null"}]},"subDistrict":{"anyOf":[{"example":"แขวงสีลม","type":"string"},{"type":"null"}]},"district":{"anyOf":[{"example":"เขตบางรัก","type":"string"},{"type":"null"}]},"province":{"anyOf":[{"example":"กรุงเทพมหานคร","type":"string"},{"type":"null"}]},"postalCode":{"anyOf":[{"example":"10500","type":"string"},{"type":"null"}]},"country":{"default":"TH","example":"TH","type":"string"}}}},"clientPersons":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["name"],"properties":{"name":{"example":"คุณ วิชัย ศรีทอง","type":"string"},"position":{"anyOf":[{"type":"string"},{"type":"null"}]},"email":{"anyOf":[{"example":"wichai@example.co.th","type":"string"},{"type":"null"}]},"phone":{"anyOf":[{"example":"0812345678","type":"string"},{"type":"null"}]},"isPrimary":{"default":false,"type":"boolean"}}}}}}}}}}},"/v1/products":{"get":{"parameters":[{"description":"หน้า (เริ่มที่ 1) / page","schema":{"default":1,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"default":1,"description":"หน้า (เริ่มที่ 1) / page","type":"number"}]},"in":"query","name":"page","required":false},{"description":"จำนวนต่อหน้า / page size","schema":{"default":20,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"default":20,"description":"จำนวนต่อหน้า / page size","type":"number"}]},"in":"query","name":"limit","required":false},{"description":"คำค้น / search term","schema":{"type":"string"},"in":"query","name":"q","required":false},{"schema":{"anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]},"in":"query","name":"type","required":false}],"operationId":"getV1Products","tags":["Products"],"summary":"รายการสินค้า (own-company)","description":"**ต้องมี scope `products:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · คืน **อาเรย์ตรง ๆ** ไม่ได้ห่อด้วย `{ items, total }` · เลื่อนหน้าด้วย `page`/`limit`","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"รายการสินค้า/บริการ","content":{"application/json":{"schema":{"description":"อาเรย์ตรง ๆ (ไม่ห่อ items/total) — ใช้ page/limit เลื่อนหน้า","type":"array","items":{"additionalProperties":true,"description":"สินค้า/บริการ — ราคาทุกตัวเป็น string","type":"object","required":["id","companyId","sku","barcode","externalId","name","description","unit","defaultPrice","costPrice","stock","vatType","productType","isActive","createdAt","updatedAt","deletedAt"],"properties":{"id":{"multipleOf":1,"example":7,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"sku":{"anyOf":[{"example":"TR-WS-AI","type":"string"},{"type":"null"}]},"barcode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"description":"รหัสอ้างอิงจากระบบต้นทาง (ถ้าสร้างผ่าน upsert)","type":"string"},{"type":"null"}]},"name":{"example":"อบรมเชิงปฏิบัติการ AI สำหรับธุรกิจ (1 วัน)","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"unit":{"example":"ครั้ง","type":"string"},"defaultPrice":{"description":"ราคาตั้งต้น — คืนเป็น **string** และตัดศูนย์ท้ายทิ้ง ('123.50' → '123.5')","example":"35000","type":"string"},"costPrice":{"anyOf":[{"description":"ราคาทุน — string เช่นเดียวกัน","example":"16800","type":"string"},{"type":"null"}]},"stock":{"anyOf":[{"multipleOf":1,"example":6,"type":"number"},{"type":"null"}]},"vatType":{"example":"VAT_0","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"productType":{"example":"SERVICE","anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]},"isActive":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]}}}}}}}}},"post":{"parameters":[],"operationId":"postV1Products","tags":["Products"],"summary":"สร้างสินค้า","description":"**ต้องมี scope `products:create`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ส่ง `externalId` = upsert ตาม (บริษัท, externalId): สร้างใหม่ → `201`, มีอยู่แล้วและถูกอัปเดต → `200` · ไม่ส่ง `externalId` = สร้างใหม่เสมอ (`201`) · body คือตัวสินค้าเอง ไม่ได้ห่อ · ไม่ส่ง `vatType` → ระบบเลือกตาม vatStatus ของบริษัท · field เกิน/ผิดชนิด → `422 VALIDATION`","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"อัปเดตสินค้าเดิมที่ externalId ตรงกัน","content":{"application/json":{"schema":{"additionalProperties":true,"description":"สินค้า/บริการ — ราคาทุกตัวเป็น string","type":"object","required":["id","companyId","sku","barcode","externalId","name","description","unit","defaultPrice","costPrice","stock","vatType","productType","isActive","createdAt","updatedAt","deletedAt"],"properties":{"id":{"multipleOf":1,"example":7,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"sku":{"anyOf":[{"example":"TR-WS-AI","type":"string"},{"type":"null"}]},"barcode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"description":"รหัสอ้างอิงจากระบบต้นทาง (ถ้าสร้างผ่าน upsert)","type":"string"},{"type":"null"}]},"name":{"example":"อบรมเชิงปฏิบัติการ AI สำหรับธุรกิจ (1 วัน)","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"unit":{"example":"ครั้ง","type":"string"},"defaultPrice":{"description":"ราคาตั้งต้น — คืนเป็น **string** และตัดศูนย์ท้ายทิ้ง ('123.50' → '123.5')","example":"35000","type":"string"},"costPrice":{"anyOf":[{"description":"ราคาทุน — string เช่นเดียวกัน","example":"16800","type":"string"},{"type":"null"}]},"stock":{"anyOf":[{"multipleOf":1,"example":6,"type":"number"},{"type":"null"}]},"vatType":{"example":"VAT_0","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"productType":{"example":"SERVICE","anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]},"isActive":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]}}}}}},"201":{"description":"สร้างสินค้าใหม่แล้ว","content":{"application/json":{"schema":{"additionalProperties":true,"description":"สินค้า/บริการ — ราคาทุกตัวเป็น string","type":"object","required":["id","companyId","sku","barcode","externalId","name","description","unit","defaultPrice","costPrice","stock","vatType","productType","isActive","createdAt","updatedAt","deletedAt"],"properties":{"id":{"multipleOf":1,"example":7,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"sku":{"anyOf":[{"example":"TR-WS-AI","type":"string"},{"type":"null"}]},"barcode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"description":"รหัสอ้างอิงจากระบบต้นทาง (ถ้าสร้างผ่าน upsert)","type":"string"},{"type":"null"}]},"name":{"example":"อบรมเชิงปฏิบัติการ AI สำหรับธุรกิจ (1 วัน)","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"unit":{"example":"ครั้ง","type":"string"},"defaultPrice":{"description":"ราคาตั้งต้น — คืนเป็น **string** และตัดศูนย์ท้ายทิ้ง ('123.50' → '123.5')","example":"35000","type":"string"},"costPrice":{"anyOf":[{"description":"ราคาทุน — string เช่นเดียวกัน","example":"16800","type":"string"},{"type":"null"}]},"stock":{"anyOf":[{"multipleOf":1,"example":6,"type":"number"},{"type":"null"}]},"vatType":{"example":"VAT_0","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"productType":{"example":"SERVICE","anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]},"isActive":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]}}}}}},"422":{"description":"body ไม่ผ่าน schema ที่ขอบ (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"สินค้า/บริการที่จะสร้าง (ฟิลด์ตรงกับ productCreateSchema)","type":"object","required":["name"],"properties":{"sku":{"anyOf":[{"example":"SKU-001","type":"string"},{"type":"null"}]},"barcode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"example":"cms-product-123","description":"รหัสอ้างอิงจาก CMS — ส่งมาเพื่อ upsert (สร้าง/อัปเดต) ตาม (บริษัท, externalId)","type":"string"},{"type":"null"}]},"name":{"minLength":1,"example":"สินค้าตัวอย่าง","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"unit":{"default":"ชิ้น","example":"ชิ้น","type":"string"},"defaultPrice":{"default":0,"description":"ราคาตั้งต้น (ชื่อฟิลด์คือ defaultPrice ไม่ใช่ price)","example":250,"type":"number"},"costPrice":{"anyOf":[{"type":"number"},{"type":"null"}]},"stock":{"anyOf":[{"example":100,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":100,"type":"integer"}]},{"type":"null"}]},"vatType":{"default":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"productType":{"default":"GOODS","anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]},"isActive":{"default":true,"type":"boolean"}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"สินค้า/บริการที่จะสร้าง (ฟิลด์ตรงกับ productCreateSchema)","type":"object","required":["name"],"properties":{"sku":{"anyOf":[{"example":"SKU-001","type":"string"},{"type":"null"}]},"barcode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"example":"cms-product-123","description":"รหัสอ้างอิงจาก CMS — ส่งมาเพื่อ upsert (สร้าง/อัปเดต) ตาม (บริษัท, externalId)","type":"string"},{"type":"null"}]},"name":{"minLength":1,"example":"สินค้าตัวอย่าง","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"unit":{"default":"ชิ้น","example":"ชิ้น","type":"string"},"defaultPrice":{"default":0,"description":"ราคาตั้งต้น (ชื่อฟิลด์คือ defaultPrice ไม่ใช่ price)","example":250,"type":"number"},"costPrice":{"anyOf":[{"type":"number"},{"type":"null"}]},"stock":{"anyOf":[{"example":100,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":100,"type":"integer"}]},{"type":"null"}]},"vatType":{"default":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"productType":{"default":"GOODS","anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]},"isActive":{"default":true,"type":"boolean"}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"สินค้า/บริการที่จะสร้าง (ฟิลด์ตรงกับ productCreateSchema)","type":"object","required":["name"],"properties":{"sku":{"anyOf":[{"example":"SKU-001","type":"string"},{"type":"null"}]},"barcode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"example":"cms-product-123","description":"รหัสอ้างอิงจาก CMS — ส่งมาเพื่อ upsert (สร้าง/อัปเดต) ตาม (บริษัท, externalId)","type":"string"},{"type":"null"}]},"name":{"minLength":1,"example":"สินค้าตัวอย่าง","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"unit":{"default":"ชิ้น","example":"ชิ้น","type":"string"},"defaultPrice":{"default":0,"description":"ราคาตั้งต้น (ชื่อฟิลด์คือ defaultPrice ไม่ใช่ price)","example":250,"type":"number"},"costPrice":{"anyOf":[{"type":"number"},{"type":"null"}]},"stock":{"anyOf":[{"example":100,"anyOf":[{"format":"integer","default":0,"type":"string"},{"example":100,"type":"integer"}]},{"type":"null"}]},"vatType":{"default":"VAT_7","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"productType":{"default":"GOODS","anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]},"isActive":{"default":true,"type":"boolean"}}}}}}}},"/v1/products/{id}":{"get":{"parameters":[{"description":"product id","schema":{"minimum":1,"anyOf":[{"format":"integer","default":0,"type":"string"},{"minimum":1,"description":"product id","type":"integer"}]},"in":"path","name":"id","required":true}],"operationId":"getV1ProductsById","tags":["Products"],"summary":"สินค้ารายตัว","description":"**ต้องมี scope `products:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · id ต้องเป็นจำนวนเต็มตั้งแต่ 1 ขึ้นไป ไม่ใช่ → `422` · ไม่พบ/คนละบริษัท → `404 NOT_FOUND`","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"สินค้ารายตัว","content":{"application/json":{"schema":{"additionalProperties":true,"description":"สินค้า/บริการ — ราคาทุกตัวเป็น string","type":"object","required":["id","companyId","sku","barcode","externalId","name","description","unit","defaultPrice","costPrice","stock","vatType","productType","isActive","createdAt","updatedAt","deletedAt"],"properties":{"id":{"multipleOf":1,"example":7,"type":"number"},"companyId":{"multipleOf":1,"type":"number"},"sku":{"anyOf":[{"example":"TR-WS-AI","type":"string"},{"type":"null"}]},"barcode":{"anyOf":[{"type":"string"},{"type":"null"}]},"externalId":{"anyOf":[{"description":"รหัสอ้างอิงจากระบบต้นทาง (ถ้าสร้างผ่าน upsert)","type":"string"},{"type":"null"}]},"name":{"example":"อบรมเชิงปฏิบัติการ AI สำหรับธุรกิจ (1 วัน)","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"unit":{"example":"ครั้ง","type":"string"},"defaultPrice":{"description":"ราคาตั้งต้น — คืนเป็น **string** และตัดศูนย์ท้ายทิ้ง ('123.50' → '123.5')","example":"35000","type":"string"},"costPrice":{"anyOf":[{"description":"ราคาทุน — string เช่นเดียวกัน","example":"16800","type":"string"},{"type":"null"}]},"stock":{"anyOf":[{"multipleOf":1,"example":6,"type":"number"},{"type":"null"}]},"vatType":{"example":"VAT_0","anyOf":[{"const":"VAT_7","type":"string"},{"const":"VAT_0","type":"string"},{"const":"NON_VAT","type":"string"}]},"productType":{"example":"SERVICE","anyOf":[{"const":"GOODS","type":"string"},{"const":"SERVICE","type":"string"}]},"isActive":{"type":"boolean"},"createdAt":{"format":"date-time","description":"เวลาที่สร้าง","type":"string"},"updatedAt":{"format":"date-time","description":"เวลาที่แก้ไขล่าสุด","type":"string"},"deletedAt":{"anyOf":[{"format":"date-time","description":"เวลาที่ลบ (soft delete)","type":"string"},{"type":"null"}]}}}}}},"404":{"description":"ไม่พบสินค้า (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"422":{"description":"id ไม่ใช่จำนวนเต็ม (VALIDATION)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}}},"/v1/me":{"get":{"operationId":"getV1Me","tags":["Me"],"summary":"บริษัทที่ token นี้ผูกอยู่","description":"**ไม่ต้องมี scope เฉพาะ** (แค่ auth ผ่าน) · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ใช้โชว์สถานะการเชื่อมต่อใน CMS · ไม่พบบริษัท → `404 NOT_FOUND`","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"บริษัทของ token นี้","content":{"application/json":{"schema":{"additionalProperties":true,"description":"บริษัทที่ token นี้ผูกอยู่ — โครงย่อ 4 ฟิลด์ ไม่ใช่บริษัทเต็มรูป","type":"object","required":["company"],"properties":{"company":{"additionalProperties":true,"type":"object","required":["id","slug","name","website"],"properties":{"id":{"multipleOf":1,"example":1,"type":"number"},"slug":{"example":"demo-company","type":"string"},"name":{"description":"ชื่อทางการค้า ถ้าไม่มีใช้ชื่อนิติบุคคล","example":"Ketshopweb","type":"string"},"website":{"anyOf":[{"example":"https://ketshopweb.com","type":"string"},{"type":"null"}]}}}}}}}},"404":{"description":"ไม่พบบริษัท (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}}},"/v1/payment-accounts":{"get":{"operationId":"getV1Payment-accounts","tags":["Payment accounts"],"summary":"รายชื่อบัญชีรับเงินของบริษัท","description":"**ต้องมี scope `payment_accounts:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · คืนทั้งหมดในครั้งเดียว ไม่มี paging (บัญชีรับเงินต่อบริษัทมีหลักหน่วย) · เรียงตามลำดับที่สร้างไว้ในหน้าตั้งค่า · บริษัทที่ยังไม่ตั้งบัญชีได้ `items: []` ไม่ใช่ `404` · ทุกบริษัทมีบัญชีระบบ (`systemKey` ไม่เป็น null) ติดมาด้วยเสมอ — `id` ของบัญชีระบบคงที่ตลอด ผูกช่องทางกับมันได้อย่างปลอดภัย ต่างจากบัญชีปกติที่ id เปลี่ยนเมื่อร้านบันทึกรายการใหม่","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"รายชื่อบัญชีรับเงิน","content":{"application/json":{"schema":{"additionalProperties":true,"description":"รายชื่อบัญชีรับเงินทั้งหมดของบริษัท ไม่แบ่งหน้า","type":"object","required":["items"],"properties":{"items":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","name","type","bankName","accountNumber","isPrimary","isActive","systemKey"],"properties":{"id":{"multipleOf":1,"example":12,"description":"ค่าที่ CMS เก็บไว้ผูกกับช่องทางการเงิน","type":"number"},"name":{"example":"บริษัท เดโม จำกัด","description":"ชื่อบัญชี","type":"string"},"type":{"example":"bank","description":"ชนิดช่องทาง — \"bank\" หรือ \"promptpay\"","type":"string"},"bankName":{"anyOf":[{"example":"กสิกรไทย","type":"string"},{"type":"null"}]},"accountNumber":{"anyOf":[{"example":"123-4-56789-0","description":"PromptPay ไม่มีเลขบัญชี","type":"string"},{"type":"null"}]},"isPrimary":{"description":"บัญชีหลักของบริษัท","type":"boolean"},"isActive":{"description":"ปิดใช้งานแล้วยังคืนมา เพื่อให้ค่าที่ CMS ผูกไว้เดิมยังแสดงชื่อได้","type":"boolean"},"systemKey":{"anyOf":[{"example":"subsidy_shopee","description":"บัญชีที่ระบบสร้างให้ · null = บัญชีปกติของร้าน · ค่าอื่นคือบัญชีระบบ: ร้านลบไม่ได้ แก้ได้แค่ชื่อ และ id ไม่เปลี่ยนแม้ร้านบันทึกหน้าตั้งค่าใหม่ ค่าปัจจุบันคือ \"mp_holding\" (เงินรอรับจาก Marketplace) และ \"subsidy_shopee\" / \"subsidy_lazada\" / \"subsidy_tiktok\" / \"subsidy_line\" · ไม่ใช่รายการปิด อาจมีค่าเพิ่มภายหลัง","type":"string"},{"type":"null"}]}}}}}}}}}}}},"/v1/events":{"get":{"parameters":[{"schema":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]},"in":"query","name":"type","required":false},{"description":"id ของ event ตัวสุดท้ายที่ได้จากหน้าก่อน","schema":{"type":"string"},"in":"query","name":"cursor","required":false},{"description":"จำนวนต่อหน้า (สูงสุด 100)","schema":{"default":20,"anyOf":[{"format":"numeric","default":0,"type":"string"},{"default":20,"description":"จำนวนต่อหน้า (สูงสุด 100)","type":"number"}]},"in":"query","name":"limit","required":false}],"operationId":"getV1Events","tags":["Events"],"summary":"ประวัติเหตุการณ์ (event) ของบริษัท","description":"**ต้องมี scope `events:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · เรียงจากใหม่ไปเก่า · ไล่หน้าด้วย cursor (ไม่ใช่ page) · แต่ละรายการแนบผลการส่งเข้า webhook ทุก endpoint · รับ `documents:read` (หรือ `documents:*`) ได้ด้วย — key เดิมยังใช้ได้ต่อไปโดยไม่ต้องแก้ scope","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"รายการเหตุการณ์","content":{"application/json":{"schema":{"description":"ไล่ย้อนหลังจากใหม่ไปเก่า — ส่ง next_cursor กลับมาที่พารามิเตอร์ cursor เพื่อขอหน้าถัดไป","type":"object","required":["items","next_cursor"],"properties":{"items":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","type","created_at","job_id","job_status","document_id","document_no","client_name","amount","error_code","error_message","source","summary","payload","deliveries"],"properties":{"id":{"example":"evt_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"type":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]},"created_at":{"format":"date-time","type":"string"},"job_id":{"anyOf":[{"example":"job_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},{"type":"null"}]},"job_status":{"anyOf":[{"anyOf":[{"const":"QUEUED","type":"string"},{"const":"PROCESSING","type":"string"},{"const":"DONE","type":"string"},{"const":"FAILED","type":"string"},{"const":"DEAD","type":"string"}]},{"type":"null"}]},"document_id":{"anyOf":[{"multipleOf":1,"example":1042,"type":"number"},{"type":"null"}]},"document_no":{"anyOf":[{"example":"INV-2569-00842","type":"string"},{"type":"null"}]},"client_name":{"anyOf":[{"type":"string"},{"type":"null"}]},"amount":{"anyOf":[{"example":160500,"type":"number"},{"type":"null"}]},"error_code":{"anyOf":[{"example":"VAT_POLICY_MISMATCH","type":"string"},{"type":"null"}]},"error_message":{"anyOf":[{"type":"string"},{"type":"null"}]},"source":{"anyOf":[{"example":"ERP บัญชี (API key)","type":"string"},{"type":"null"}]},"summary":{"example":"ออกใบแจ้งหนี้ INV-2569-00842","type":"string"},"payload":{"description":"ก้อน JSON เดียวกับที่ยิงเข้า webhook"},"deliveries":{"type":"array","items":{"additionalProperties":true,"description":"ผลการส่งของ endpoint หนึ่งตัว (state retrying/pending เป็นค่าที่คำนวณ ไม่ใช่ค่าที่เก็บ)","type":"object","required":["delivery_id","endpoint_id","state","attempts","attempt_count","last_http_status","last_error","delivered_at","next_retry_at","updated_at"],"properties":{"delivery_id":{"example":"whd_5f3a1b","type":"string"},"endpoint_id":{"example":"whe_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"state":{"example":"delivered","anyOf":[{"const":"delivered","type":"string"},{"const":"retrying","type":"string"},{"const":"failed","type":"string"},{"const":"skipped","type":"string"},{"const":"pending","type":"string"}]},"attempts":{"type":"array","items":{"additionalProperties":true,"description":"ความพยายามส่งหนึ่งครั้ง · cause มีเฉพาะครั้งที่ไม่สำเร็จ (แถวเก่าก่อนฟีเจอร์นี้ไม่มี)","type":"object","required":["no","at","httpStatus","durationMs","outcome"],"properties":{"no":{"multipleOf":1,"example":1,"type":"number"},"at":{"format":"date-time","type":"string"},"httpStatus":{"anyOf":[{"multipleOf":1,"example":200,"type":"number"},{"type":"null"}]},"durationMs":{"multipleOf":1,"example":436,"type":"number"},"outcome":{"example":"delivered","anyOf":[{"const":"delivered","type":"string"},{"const":"http_error","type":"string"},{"const":"timeout","type":"string"}]},"cause":{"example":"dns","anyOf":[{"const":"dns","type":"string"},{"const":"blocked","type":"string"},{"const":"invalid_url","type":"string"},{"const":"timeout","type":"string"},{"const":"network","type":"string"},{"const":"http_error","type":"string"}]}}}},"attempt_count":{"multipleOf":1,"example":1,"type":"number"},"last_http_status":{"anyOf":[{"multipleOf":1,"example":200,"type":"number"},{"type":"null"}]},"last_error":{"anyOf":[{"type":"string"},{"type":"null"}]},"delivered_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"next_retry_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"updated_at":{"format":"date-time","type":"string"}}}}}}},"next_cursor":{"anyOf":[{"example":"evt_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},{"type":"null"}]}}}}}}}}},"/v1/events/{id}":{"get":{"parameters":[{"description":"event id (evt_...)","schema":{"type":"string","minLength":1},"in":"path","name":"id","required":true}],"operationId":"getV1EventsById","tags":["Events"],"summary":"เหตุการณ์รายตัว + ประวัติการส่งรายครั้ง","description":"**ต้องมี scope `events:read`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · deliveries[].attempts เก็บทุกครั้งที่ยิง (เวลา, HTTP, เวลาที่ใช้, ผล) · state retrying หมายถึงยังมีนัดยิงใหม่ที่ next_retry_at · รับ `documents:read` (หรือ `documents:*`) ได้ด้วย — key เดิมยังใช้ได้ต่อไปโดยไม่ต้องแก้ scope","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"เหตุการณ์และผลการส่ง","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["id","type","created_at","job_id","job_status","document_id","document_no","client_name","amount","error_code","error_message","source","summary","payload","deliveries"],"properties":{"id":{"example":"evt_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"type":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]},"created_at":{"format":"date-time","type":"string"},"job_id":{"anyOf":[{"example":"job_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},{"type":"null"}]},"job_status":{"anyOf":[{"anyOf":[{"const":"QUEUED","type":"string"},{"const":"PROCESSING","type":"string"},{"const":"DONE","type":"string"},{"const":"FAILED","type":"string"},{"const":"DEAD","type":"string"}]},{"type":"null"}]},"document_id":{"anyOf":[{"multipleOf":1,"example":1042,"type":"number"},{"type":"null"}]},"document_no":{"anyOf":[{"example":"INV-2569-00842","type":"string"},{"type":"null"}]},"client_name":{"anyOf":[{"type":"string"},{"type":"null"}]},"amount":{"anyOf":[{"example":160500,"type":"number"},{"type":"null"}]},"error_code":{"anyOf":[{"example":"VAT_POLICY_MISMATCH","type":"string"},{"type":"null"}]},"error_message":{"anyOf":[{"type":"string"},{"type":"null"}]},"source":{"anyOf":[{"example":"ERP บัญชี (API key)","type":"string"},{"type":"null"}]},"summary":{"example":"ออกใบแจ้งหนี้ INV-2569-00842","type":"string"},"payload":{"description":"ก้อน JSON เดียวกับที่ยิงเข้า webhook"},"deliveries":{"type":"array","items":{"additionalProperties":true,"description":"ผลการส่งของ endpoint หนึ่งตัว (state retrying/pending เป็นค่าที่คำนวณ ไม่ใช่ค่าที่เก็บ)","type":"object","required":["delivery_id","endpoint_id","state","attempts","attempt_count","last_http_status","last_error","delivered_at","next_retry_at","updated_at"],"properties":{"delivery_id":{"example":"whd_5f3a1b","type":"string"},"endpoint_id":{"example":"whe_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"state":{"example":"delivered","anyOf":[{"const":"delivered","type":"string"},{"const":"retrying","type":"string"},{"const":"failed","type":"string"},{"const":"skipped","type":"string"},{"const":"pending","type":"string"}]},"attempts":{"type":"array","items":{"additionalProperties":true,"description":"ความพยายามส่งหนึ่งครั้ง · cause มีเฉพาะครั้งที่ไม่สำเร็จ (แถวเก่าก่อนฟีเจอร์นี้ไม่มี)","type":"object","required":["no","at","httpStatus","durationMs","outcome"],"properties":{"no":{"multipleOf":1,"example":1,"type":"number"},"at":{"format":"date-time","type":"string"},"httpStatus":{"anyOf":[{"multipleOf":1,"example":200,"type":"number"},{"type":"null"}]},"durationMs":{"multipleOf":1,"example":436,"type":"number"},"outcome":{"example":"delivered","anyOf":[{"const":"delivered","type":"string"},{"const":"http_error","type":"string"},{"const":"timeout","type":"string"}]},"cause":{"example":"dns","anyOf":[{"const":"dns","type":"string"},{"const":"blocked","type":"string"},{"const":"invalid_url","type":"string"},{"const":"timeout","type":"string"},{"const":"network","type":"string"},{"const":"http_error","type":"string"}]}}}},"attempt_count":{"multipleOf":1,"example":1,"type":"number"},"last_http_status":{"anyOf":[{"multipleOf":1,"example":200,"type":"number"},{"type":"null"}]},"last_error":{"anyOf":[{"type":"string"},{"type":"null"}]},"delivered_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"next_retry_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"updated_at":{"format":"date-time","type":"string"}}}}}}}}},"404":{"description":"ไม่พบเหตุการณ์ (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}}},"/v1/events/{id}/redeliver":{"post":{"parameters":[{"description":"event id (evt_...)","schema":{"type":"string","minLength":1},"in":"path","name":"id","required":true}],"operationId":"postV1EventsByIdRedeliver","tags":["Events"],"summary":"ส่งเหตุการณ์นี้เข้า webhook อีกครั้ง","description":"**ต้องมี scope `webhooks:manage`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ตอบ 202 แล้วส่งเบื้องหลัง · บันทึกเป็นความพยายามครั้งใหม่ ไม่ทับผลของครั้งก่อน · endpoint ที่ถูกปิดอัตโนมัติต้องเปิดใช้งานก่อน ไม่งั้น 409 ENDPOINT_DISABLED · รับ `documents:*` ได้ด้วย — key เดิมยังใช้ได้ต่อไปโดยไม่ต้องแก้ scope","security":[{"bearerAuth":[]}],"responses":{"202":{"description":"เข้าคิวส่งซ้ำแล้ว","content":{"application/json":{"schema":{"description":"รับคำสั่งส่งซ้ำเข้าคิวแล้ว — ผลจริงดูที่ GET /v1/events/{id}","type":"object","required":["event_id","queued"],"properties":{"event_id":{"example":"evt_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"queued":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["delivery_id","endpoint_id"],"properties":{"delivery_id":{"example":"whd_5f3a1b","type":"string"},"endpoint_id":{"example":"whe_01JZ8Q2K","type":"string"}}}}}}}}},"404":{"description":"ไม่พบเหตุการณ์หรือ endpoint (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"409":{"description":"endpoint ถูกปิดอัตโนมัติ (ENDPOINT_DISABLED)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"ไม่ส่ง endpoint_id = ส่งซ้ำให้ทุก endpoint ที่ยังเปิดใช้งานและสมัคร event ชนิดนี้","type":"object","properties":{"endpoint_id":{"example":"whe_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"ไม่ส่ง endpoint_id = ส่งซ้ำให้ทุก endpoint ที่ยังเปิดใช้งานและสมัคร event ชนิดนี้","type":"object","properties":{"endpoint_id":{"example":"whe_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"ไม่ส่ง endpoint_id = ส่งซ้ำให้ทุก endpoint ที่ยังเปิดใช้งานและสมัคร event ชนิดนี้","type":"object","properties":{"endpoint_id":{"example":"whe_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"}}}}}}}},"/v1/webhooks":{"get":{"operationId":"getV1Webhooks","tags":["Webhooks"],"summary":"รายการ webhook endpoint","description":"**ต้องมี scope `webhooks:manage`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · secret ไม่ถูกคืนอีกหลังตอนสร้าง (เหลือ secret_preview) · แถวที่ type != \"user\" สร้างจากการเชื่อมต่อของพาร์ทเนอร์: ไม่นับโควต้า และลบจากหน้าเว็บไม่ได้ (403 MANAGED_ENDPOINT) แต่ integration key ของบริษัทนั้นลบได้ · รับ `documents:*` ได้ด้วย — key เดิมยังใช้ได้ต่อไปโดยไม่ต้องแก้ scope","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"รายการ endpoint","content":{"application/json":{"schema":{"description":"รายการ endpoint ของบริษัทนี้ (ผู้ใช้สร้างได้สูงสุด 5 ไม่นับตัวที่ระบบสร้าง)","type":"object","required":["items","max","used"],"properties":{"items":{"type":"array","items":{"additionalProperties":true,"type":"object","required":["id","url","description","events","status","secret_preview","created_at","disabled_at","delivered","failed","pending","last_attempt_at","last_http_status","type"],"properties":{"id":{"example":"whe_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"url":{"example":"https://erp.example.com/hooks/ketbill","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"events":{"type":"array","items":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]}},"status":{"example":"active","anyOf":[{"const":"active","type":"string"},{"const":"auto_disabled","type":"string"}]},"secret_preview":{"example":"whsec_9c2f1a••••7b41","type":"string"},"created_at":{"format":"date-time","type":"string"},"disabled_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"delivered":{"multipleOf":1,"example":1284,"type":"number"},"failed":{"multipleOf":1,"example":3,"type":"number"},"pending":{"multipleOf":1,"example":0,"type":"number"},"last_attempt_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"last_http_status":{"anyOf":[{"multipleOf":1,"example":200,"type":"number"},{"type":"null"}]},"type":{"example":"user","description":"ต้นทางที่สร้าง endpoint นี้ · \"user\" = ผู้ใช้สร้างเอง · ค่าอื่น (เช่น \"cms\") = สร้างจากการเชื่อมต่อของพาร์ทเนอร์: ไม่นับโควต้าและลบจากหน้าเว็บไม่ได้ · ไม่ใช่รายการค่าปิด พาร์ทเนอร์รายใหม่เพิ่มค่าใหม่ได้ · กำหนดจากตราของคีย์ที่เรียกเท่านั้น ส่งมาใน body ไม่มีผล","type":"string"}}}},"max":{"multipleOf":1,"example":5,"type":"number"},"used":{"multipleOf":1,"example":1,"description":"จำนวนที่กินโควต้า — ไม่รวมแถวที่ type != \"user\" ใช้เลขนี้ ไม่ใช่ items.length","type":"number"}}}}}}}},"post":{"parameters":[],"operationId":"postV1Webhooks","tags":["Webhooks"],"summary":"ลงทะเบียน webhook endpoint","description":"**ต้องมี scope `webhooks:manage`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · จำกัด 5 endpoint ต่อบริษัท เกินแล้ว 409 ENDPOINT_LIMIT · ทุกครั้งที่ยิงจะมี header `X-KetBill-Signature: t=<unixts>,v1=<hex>` โดย v1 = HMAC-SHA256 ของสตริง `<t>.<rawBody>` ด้วย secret เต็ม (รวม prefix whsec_) · ฝั่งรับควรตรวจ t ไม่ให้เก่าเกิน 5 นาที แล้วเทียบ v1 แบบ constant-time · url ที่ไม่ใช่ https → 400 VALIDATION (รับ https เท่านั้น), ชนิดฟิลด์หรือชื่อ event ที่ไม่รู้จัก → 422 · **URL ต้องเป็น https และเป็นที่อยู่สาธารณะ**: ปลายทางที่เป็น loopback/เครือข่ายภายใน/link-local (รวม metadata ของ cloud) หรือชื่อ localhost/.local/.internal → 400 `URL_NOT_ALLOWED` และระบบตรวจซ้ำทุกครั้งก่อนส่ง ปลายทางที่เปลี่ยน DNS มาชี้ภายในทีหลังจะถูกปฏิเสธและถูกบันทึกเป็นการส่งที่ล้มเหลว · ระบบ **ไม่ตาม redirect**: ตอบ 3xx = การส่งล้มเหลว ให้ตั้ง URL ปลายทางสุดท้ายมาตรงๆ · รับ `documents:*` ได้ด้วย — key เดิมยังใช้ได้ต่อไปโดยไม่ต้องแก้ scope","security":[{"bearerAuth":[]}],"responses":{"201":{"description":"สร้างแล้ว (secret เต็มออกครั้งเดียว)","content":{"application/json":{"schema":{"description":"secret เต็มออกครั้งนี้ครั้งเดียว — เก็บทันที ระบบไม่แสดงซ้ำอีก","type":"object","required":["endpoint","secret"],"properties":{"endpoint":{"additionalProperties":true,"type":"object","required":["id","url","description","events","status","secret_preview","created_at","disabled_at","delivered","failed","pending","last_attempt_at","last_http_status","type"],"properties":{"id":{"example":"whe_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"url":{"example":"https://erp.example.com/hooks/ketbill","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"events":{"type":"array","items":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]}},"status":{"example":"active","anyOf":[{"const":"active","type":"string"},{"const":"auto_disabled","type":"string"}]},"secret_preview":{"example":"whsec_9c2f1a••••7b41","type":"string"},"created_at":{"format":"date-time","type":"string"},"disabled_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"delivered":{"multipleOf":1,"example":1284,"type":"number"},"failed":{"multipleOf":1,"example":3,"type":"number"},"pending":{"multipleOf":1,"example":0,"type":"number"},"last_attempt_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"last_http_status":{"anyOf":[{"multipleOf":1,"example":200,"type":"number"},{"type":"null"}]},"type":{"example":"user","description":"ต้นทางที่สร้าง endpoint นี้ · \"user\" = ผู้ใช้สร้างเอง · ค่าอื่น (เช่น \"cms\") = สร้างจากการเชื่อมต่อของพาร์ทเนอร์: ไม่นับโควต้าและลบจากหน้าเว็บไม่ได้ · ไม่ใช่รายการค่าปิด พาร์ทเนอร์รายใหม่เพิ่มค่าใหม่ได้ · กำหนดจากตราของคีย์ที่เรียกเท่านั้น ส่งมาใน body ไม่มีผล","type":"string"}}},"secret":{"example":"whsec_4f1Ck2Vb9QpZ7mR3sT6yXw8NuE0aD5gH","type":"string"}}}}}},"409":{"description":"ครบเพดานจำนวน endpoint (ENDPOINT_LIMIT)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"endpoint ที่จะลงทะเบียน","type":"object","required":["url","events"],"properties":{"url":{"example":"https://erp.example.com/hooks/ketbill","description":"ปลายทาง https (http ธรรมดาถูกปฏิเสธ)","type":"string"},"events":{"minItems":1,"type":"array","items":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]}},"description":{"anyOf":[{"example":"ERP บัญชี","type":"string"},{"type":"null"}]}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"endpoint ที่จะลงทะเบียน","type":"object","required":["url","events"],"properties":{"url":{"example":"https://erp.example.com/hooks/ketbill","description":"ปลายทาง https (http ธรรมดาถูกปฏิเสธ)","type":"string"},"events":{"minItems":1,"type":"array","items":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]}},"description":{"anyOf":[{"example":"ERP บัญชี","type":"string"},{"type":"null"}]}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"endpoint ที่จะลงทะเบียน","type":"object","required":["url","events"],"properties":{"url":{"example":"https://erp.example.com/hooks/ketbill","description":"ปลายทาง https (http ธรรมดาถูกปฏิเสธ)","type":"string"},"events":{"minItems":1,"type":"array","items":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]}},"description":{"anyOf":[{"example":"ERP บัญชี","type":"string"},{"type":"null"}]}}}}}}}},"/v1/webhooks/{id}":{"put":{"parameters":[{"description":"webhook endpoint id (whe_...)","schema":{"type":"string","minLength":1},"in":"path","name":"id","required":true}],"operationId":"putV1WebhooksById","tags":["Webhooks"],"summary":"แก้ไข endpoint / เปิดใช้งานอีกครั้ง","description":"**ต้องมี scope `webhooks:manage`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ส่ง status=ACTIVE เพื่อเปิดใช้งาน endpoint ที่ถูกปิดอัตโนมัติ (ล้างนาฬิกา 24 ชั่วโมงให้ด้วย) · รับ `documents:*` ได้ด้วย — key เดิมยังใช้ได้ต่อไปโดยไม่ต้องแก้ scope","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"endpoint หลังแก้","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["id","url","description","events","status","secret_preview","created_at","disabled_at","delivered","failed","pending","last_attempt_at","last_http_status","type"],"properties":{"id":{"example":"whe_01JZ8Q2K3M4N5P6Q7R8S9T0V1W","type":"string"},"url":{"example":"https://erp.example.com/hooks/ketbill","type":"string"},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"events":{"type":"array","items":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]}},"status":{"example":"active","anyOf":[{"const":"active","type":"string"},{"const":"auto_disabled","type":"string"}]},"secret_preview":{"example":"whsec_9c2f1a••••7b41","type":"string"},"created_at":{"format":"date-time","type":"string"},"disabled_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"delivered":{"multipleOf":1,"example":1284,"type":"number"},"failed":{"multipleOf":1,"example":3,"type":"number"},"pending":{"multipleOf":1,"example":0,"type":"number"},"last_attempt_at":{"anyOf":[{"format":"date-time","type":"string"},{"type":"null"}]},"last_http_status":{"anyOf":[{"multipleOf":1,"example":200,"type":"number"},{"type":"null"}]},"type":{"example":"user","description":"ต้นทางที่สร้าง endpoint นี้ · \"user\" = ผู้ใช้สร้างเอง · ค่าอื่น (เช่น \"cms\") = สร้างจากการเชื่อมต่อของพาร์ทเนอร์: ไม่นับโควต้าและลบจากหน้าเว็บไม่ได้ · ไม่ใช่รายการค่าปิด พาร์ทเนอร์รายใหม่เพิ่มค่าใหม่ได้ · กำหนดจากตราของคีย์ที่เรียกเท่านั้น ส่งมาใน body ไม่มีผล","type":"string"}}}}}},"404":{"description":"ไม่พบ endpoint (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}},"requestBody":{"required":true,"content":{"application/json":{"schema":{"additionalProperties":true,"description":"ส่งมาเฉพาะฟิลด์ที่ต้องการแก้","type":"object","properties":{"url":{"example":"https://erp.example.com/hooks/ketbill","type":"string"},"events":{"minItems":1,"type":"array","items":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]}},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"status":{"description":"ส่ง ACTIVE เพื่อเปิดใช้งานอีกครั้งหลังถูกปิดอัตโนมัติ","const":"ACTIVE","type":"string"}}}},"multipart/form-data":{"schema":{"additionalProperties":true,"description":"ส่งมาเฉพาะฟิลด์ที่ต้องการแก้","type":"object","properties":{"url":{"example":"https://erp.example.com/hooks/ketbill","type":"string"},"events":{"minItems":1,"type":"array","items":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]}},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"status":{"description":"ส่ง ACTIVE เพื่อเปิดใช้งานอีกครั้งหลังถูกปิดอัตโนมัติ","const":"ACTIVE","type":"string"}}}},"text/plain":{"schema":{"additionalProperties":true,"description":"ส่งมาเฉพาะฟิลด์ที่ต้องการแก้","type":"object","properties":{"url":{"example":"https://erp.example.com/hooks/ketbill","type":"string"},"events":{"minItems":1,"type":"array","items":{"example":"document.created","anyOf":[{"const":"document.created","type":"string"},{"const":"document.failed","type":"string"}]}},"description":{"anyOf":[{"type":"string"},{"type":"null"}]},"status":{"description":"ส่ง ACTIVE เพื่อเปิดใช้งานอีกครั้งหลังถูกปิดอัตโนมัติ","const":"ACTIVE","type":"string"}}}}}}},"delete":{"parameters":[{"description":"webhook endpoint id (whe_...)","schema":{"type":"string","minLength":1},"in":"path","name":"id","required":true}],"operationId":"deleteV1WebhooksById","tags":["Webhooks"],"summary":"ลบ endpoint","description":"**ต้องมี scope `webhooks:manage`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ลบแล้วเหตุการณ์ใหม่ไม่ถูกส่งมาที่นี่อีก และรายการที่ค้างรอส่งซ้ำถูกยกเลิก · แถวที่ type != \"user\" ลบได้จาก integration key ของบริษัทนั้นใบไหนก็ได้ (ใช้ตอนยกเลิกการเชื่อมต่อ) แต่หน้าเว็บได้ 403 MANAGED_ENDPOINT · รับ `documents:*` ได้ด้วย — key เดิมยังใช้ได้ต่อไปโดยไม่ต้องแก้ scope","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"ลบแล้ว","content":{"application/json":{"schema":{"type":"object","required":["deleted"],"properties":{"deleted":{"const":true,"type":"boolean"}}}}}},"403":{"description":"endpoint ที่พาร์ทเนอร์สร้าง ลบจากหน้าเว็บไม่ได้ (MANAGED_ENDPOINT)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}},"404":{"description":"ไม่พบ endpoint (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}}},"/v1/webhooks/{id}/test":{"post":{"parameters":[{"description":"webhook endpoint id (whe_...)","schema":{"type":"string","minLength":1},"in":"path","name":"id","required":true}],"operationId":"postV1WebhooksByIdTest","tags":["Webhooks"],"summary":"ยิงทดสอบไปที่ endpoint นี้","description":"**ต้องมี scope `webhooks:manage`** · auth: `Authorization: Bearer <API key kdoc_ หรือ OAuth token>` · ส่ง payload ตัวอย่าง type=ping ที่ลงลายเซ็นจริง เพื่อตรวจว่าปลายทางรับได้ · ไม่ถูกนับเป็นประวัติการส่งและไม่กระทบการปิดอัตโนมัติ · รับ `documents:*` ได้ด้วย — key เดิมยังใช้ได้ต่อไปโดยไม่ต้องแก้ scope","security":[{"bearerAuth":[]}],"responses":{"200":{"description":"ผลการยิงทดสอบ","content":{"application/json":{"schema":{"description":"ผลการยิงทดสอบ (ไม่ถูกบันทึกเป็นประวัติการส่ง และไม่กระทบการปิดอัตโนมัติ)","type":"object","required":["ok","http_status","duration_ms","outcome","cause","error"],"properties":{"ok":{"example":true,"type":"boolean"},"http_status":{"anyOf":[{"multipleOf":1,"example":200,"type":"number"},{"type":"null"}]},"duration_ms":{"multipleOf":1,"example":436,"type":"number"},"outcome":{"example":"delivered","anyOf":[{"const":"delivered","type":"string"},{"const":"http_error","type":"string"},{"const":"timeout","type":"string"}]},"cause":{"anyOf":[{"example":"dns","anyOf":[{"const":"dns","type":"string"},{"const":"blocked","type":"string"},{"const":"invalid_url","type":"string"},{"const":"timeout","type":"string"},{"const":"network","type":"string"},{"const":"http_error","type":"string"}]},{"type":"null"}]},"error":{"anyOf":[{"type":"string"},{"type":"null"}]}}}}}},"404":{"description":"ไม่พบ endpoint (NOT_FOUND)","content":{"application/json":{"schema":{"additionalProperties":true,"type":"object","required":["error"],"properties":{"error":{"additionalProperties":true,"type":"object","required":["code","message"],"properties":{"code":{"example":"NOT_FOUND","type":"string"},"message":{"example":"ไม่พบสินค้า","type":"string"}}}}}}}}}}},"/oauth/authorize":{"get":{"tags":["OAuth 2.1"],"summary":"Authorization code (PKCE S256)","description":"เปิด URL นี้ใน browser. gen code_verifier (สุ่ม) + code_challenge = BASE64URL(SHA256(code_verifier)). ผู้ใช้ login + consent แล้วระบบ redirect กลับ redirect_uri พร้อม ?code=<authorization_code>&state=<state>. ขั้นถัดไป: เอา code + code_verifier ไปเรียก POST /oauth/token (code อายุสั้น ใช้ครั้งเดียว)","security":[],"parameters":[{"name":"response_type","in":"query","required":true,"schema":{"type":"string","enum":["code"]},"example":"code"},{"name":"client_id","in":"query","required":true,"schema":{"type":"string"},"example":"kdoc-client-a1b2c3d4"},{"name":"redirect_uri","in":"query","required":true,"schema":{"type":"string"},"example":"https://app.example.com/callback"},{"name":"code_challenge","in":"query","required":true,"schema":{"type":"string"},"example":"E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM"},{"name":"code_challenge_method","in":"query","required":true,"schema":{"type":"string","enum":["S256"]},"example":"S256"},{"name":"scope","in":"query","required":false,"schema":{"type":"string"},"example":"documents:read documents:create"},{"name":"state","in":"query","required":false,"schema":{"type":"string"},"example":"xyz-csrf-token"}],"responses":{"302":{"description":"redirect ไปหน้า login/consent แล้วกลับด้วย code","headers":{"Location":{"schema":{"type":"string"},"example":"https://app.example.com/callback?code=oac_7f3a...&state=xyz-csrf-token"}}}}}},"/oauth/token":{"post":{"tags":["OAuth 2.1"],"summary":"Token exchange","description":"grant_type=authorization_code พร้อม code (จากขั้น 2) + code_verifier (ตัวจริงของ code_challenge). client_secret ส่งใน body (client_secret_post) เฉพาะ confidential client — ไม่ใช่ header Basic. ได้ access_token = EdDSA-signed JWT แบบไม่มีวันหมดอายุ (ยกเลิกได้ทันทีที่ปุ่มตัดการเชื่อมต่อ). ใช้เป็น Authorization: Bearer <access_token> กับทุก endpoint /v1/*","security":[],"requestBody":{"required":true,"content":{"application/x-www-form-urlencoded":{"schema":{"type":"object","properties":{"grant_type":{"type":"string","enum":["authorization_code"]},"code":{"type":"string"},"redirect_uri":{"type":"string"},"code_verifier":{"type":"string"},"client_id":{"type":"string"},"client_secret":{"type":"string","description":"เฉพาะ confidential client"}},"required":["grant_type","code","redirect_uri","code_verifier","client_id"]},"example":{"grant_type":"authorization_code","code":"oac_7f3a...","redirect_uri":"https://app.example.com/callback","code_verifier":"dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk","client_id":"kdoc-client-a1b2c3d4"}}}},"responses":{"200":{"description":"access token (verify offline ได้ผ่าน /.well-known/jwks.json)","content":{"application/json":{"schema":{"type":"object","properties":{"access_token":{"type":"string","description":"EdDSA-signed JWT — ไม่มีวันหมดอายุ (revoke ผ่าน salt / ปุ่มตัดการเชื่อมต่อ)"},"token_type":{"type":"string","enum":["Bearer"]},"scope":{"type":"string"}},"required":["access_token","token_type","scope"]},"example":{"access_token":"eyJhbGciOiJFZERTQSIsImtpZCI6Imtc...","token_type":"Bearer","scope":"documents:read documents:create"}}}},"400":{"description":"code/code_verifier ไม่ถูกต้อง หรือ PKCE ไม่ผ่าน","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string"},"error_description":{"type":"string"}},"required":["error"]},"example":{"error":"invalid_grant","error_description":"authorization code ไม่ถูกต้องหรือหมดอายุ"}}}}}}},"/oauth/revoke":{"post":{"tags":["OAuth 2.1"],"summary":"เพิกถอน token (RFC 7009)","description":"ส่ง access token ที่ต้องการเพิกถอน. ระบบลบ per-user salt ของ token นั้น → access token ทุกใบของผู้ใช้รายนั้นใช้ไม่ได้ทันที. คืน 200 เสมอ (idempotent) แม้ token ไม่มีอยู่","security":[],"requestBody":{"required":true,"content":{"application/x-www-form-urlencoded":{"schema":{"type":"object","properties":{"token":{"type":"string"}},"required":["token"]},"example":{"token":"eyJhbGciOiJFZERTQSIsImtpZCI6Imtc..."}}}},"responses":{"200":{"description":"เพิกถอนแล้ว (body ว่าง) — คืน 200 เสมอตาม RFC 7009"}}}},"/.well-known/jwks.json":{"get":{"tags":["OAuth 2.1"],"summary":"JWKS — public key สำหรับ verify access token แบบ offline","description":"ชุด EdDSA public keys (RFC 7517). ใช้ verify ลายเซ็นของ access_token (JWT) โดยไม่ต้องเรียก introspect. จับคู่ key ด้วย kid ใน JWT header. cache ได้ (Cache-Control: max-age=3600)","security":[],"responses":{"200":{"description":"JWKS (EdDSA public keys)","content":{"application/json":{"schema":{"type":"object","properties":{"keys":{"type":"array","items":{"type":"object","properties":{"kty":{"type":"string","enum":["OKP"]},"crv":{"type":"string","enum":["Ed25519"]},"x":{"type":"string","description":"public key (base64url)"},"kid":{"type":"string"},"use":{"type":"string","enum":["sig"]},"alg":{"type":"string","enum":["EdDSA"]}}}}}},"example":{"keys":[{"kty":"OKP","crv":"Ed25519","x":"11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo","kid":"k1","use":"sig","alg":"EdDSA"}]}}}}}}},"/.well-known/oauth-authorization-server":{"get":{"tags":["OAuth 2.1"],"summary":"Authorization Server metadata (RFC 8414)","description":"ค่า config สำหรับ auto-discovery ของ OAuth client — endpoints, PKCE method, auth methods, scopes ที่รองรับ","security":[],"responses":{"200":{"description":"authorization-server metadata (issuer สะท้อน host ที่เรียกมา)","content":{"application/json":{"schema":{"type":"object"},"example":{"issuer":"https://api.ketbill.com","authorization_endpoint":"https://api.ketbill.com/oauth/authorize","token_endpoint":"https://api.ketbill.com/oauth/token","revocation_endpoint":"https://api.ketbill.com/oauth/revoke","jwks_uri":"https://api.ketbill.com/.well-known/jwks.json","response_types_supported":["code"],"grant_types_supported":["authorization_code"],"code_challenge_methods_supported":["S256"],"token_endpoint_auth_methods_supported":["none","client_secret_post"],"scopes_supported":["clients:read","documents:read","documents:create","documents:convert","documents:issue","documents:mark_paid","documents:void","documents:update","documents:delete","reports:read","documents:*","products:read","products:create","clients:create","clients:update","events:read","webhooks:manage","payment_accounts:read"]}}}}}}},"/.well-known/oauth-protected-resource":{"get":{"tags":["OAuth 2.1"],"summary":"Protected Resource metadata (RFC 9728)","description":"บอกว่า resource (/v1) เชื่อถือ authorization server ใด และรับ bearer token ทาง header","security":[],"responses":{"200":{"description":"protected-resource metadata","content":{"application/json":{"schema":{"type":"object"},"example":{"resource":"https://api.ketbill.com/v1","authorization_servers":["https://api.ketbill.com"],"scopes_supported":["clients:read","documents:read","documents:create","documents:convert","documents:issue","documents:mark_paid","documents:void","documents:update","documents:delete","reports:read","documents:*","products:read","products:create","clients:create","clients:update","events:read","webhooks:manage","payment_accounts:read"],"bearer_methods_supported":["header"]}}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","description":"API key `kdoc_xxxxx` หรือ OAuth access token — ใส่ในช่อง Authorization (Bearer)"}},"schemas":{}},"security":[{"bearerAuth":[]}]}