จัดการโควตา
ตรวจสอบและควบคุมการใช้โควตาของแต่ละสาขา โควตากำหนดจำนวน API call ที่สาขาสามารถใช้ได้ภายในรอบบิลลิ่ง
ตรวจสอบโควตา
GET /b2b/branches/:branchId/quotaFull URL: https://api.easyslip.com/b2b/branches/:branchId/quota
Permission: quota:read
ตัวอย่าง
curl -X GET https://api.easyslip.com/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota \
-H "X-API-Key: ${API_KEY}" \
-H "X-Timestamp: ${TIMESTAMP}" \
-H "X-Nonce: ${NONCE}" \
-H "X-Signature: ${SIGNATURE}"const headers = signRequest({
method: 'GET',
path: '/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota',
body: null,
apiKey: 'your_api_key',
secretKey: 'your_secret_key',
})
const response = await fetch(
'https://api.easyslip.com/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota',
{ headers }
)
const result = await response.json()Success Response (200)
{
"success": true,
"data": {
"branch": {
"id": "cm1a2b3c4d5e6f7g8h9i0",
"name": "สำนักงานใหญ่",
"limitQuota": 10000,
"usedQuota": 1500,
"totalUsedQuota": 45000
},
"service": {
"limitQuota": 50000,
"usedQuota": 8500,
"totalUsedQuota": 120000
}
}
}ฟิลด์ใน Response
| ฟิลด์ | ชนิด | คำอธิบาย |
|---|---|---|
branch.id | string | ID สาขา |
branch.name | string | ชื่อสาขา |
branch.limitQuota | number | null | โควตาสูงสุดระดับสาขา (null = ใช้โควตาระดับบริการ) |
branch.usedQuota | number | โควตาที่ใช้ไปในรอบนี้ |
branch.totalUsedQuota | number | โควตาที่ใช้ไปทั้งหมดตลอดการใช้งาน |
service.limitQuota | number | โควตาสูงสุดระดับบริการ |
service.usedQuota | number | โควตาที่ใช้ไปในรอบนี้ (ระดับบริการ) |
service.totalUsedQuota | number | โควตาที่ใช้ไปทั้งหมดตลอดการใช้งาน (ระดับบริการ) |
กำหนดโควตา
กำหนดค่าโควตาสูงสุดของสาขาแบบระบุจำนวนตรงๆ
PUT /b2b/branches/:branchId/quotaFull URL: https://api.easyslip.com/b2b/branches/:branchId/quota
Permission: quota:write
Request Body
| ฟิลด์ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
limitQuota | number | null | ใช่ | โควตาสูงสุดใหม่ หรือ null เพื่อใช้โควตาระดับบริการ |
TIP
การกำหนด limitQuota เป็น null จะลบโควตาเฉพาะสาขาออก สาขาจะถูกจำกัดด้วยโควตาระดับบริการเท่านั้น
WARNING
ไม่สามารถกำหนด limitQuota ให้น้อยกว่า usedQuota ปัจจุบันได้ เช่น หากสาขาใช้ไปแล้ว 1500 ครั้ง จะไม่สามารถกำหนดโควตาเป็น 1000 ได้
ตัวอย่าง
curl -X PUT https://api.easyslip.com/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota \
-H "Content-Type: application/json" \
-H "X-API-Key: ${API_KEY}" \
-H "X-Timestamp: ${TIMESTAMP}" \
-H "X-Nonce: ${NONCE}" \
-H "X-Signature: ${SIGNATURE}" \
-d '{"limitQuota": 15000}'const body = { limitQuota: 15000 }
const headers = signRequest({
method: 'PUT',
path: '/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota',
body,
apiKey: 'your_api_key',
secretKey: 'your_secret_key',
})
const response = await fetch(
'https://api.easyslip.com/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota',
{
method: 'PUT',
headers,
body: JSON.stringify(body),
}
)
const result = await response.json()Success Response (200)
{
"success": true,
"data": {
"id": "cm1a2b3c4d5e6f7g8h9i0",
"name": "สำนักงานใหญ่",
"limitQuota": 15000,
"usedQuota": 1500,
"totalUsedQuota": 45000
}
}Error Response (400)
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "Limit quota cannot be less than current used quota (1500)"
}
}ปรับโควตา
เพิ่มหรือลดจากโควตาสูงสุดปัจจุบัน
POST /b2b/branches/:branchId/quota/adjustFull URL: https://api.easyslip.com/b2b/branches/:branchId/quota/adjust
Permission: quota:write
Request Body
| ฟิลด์ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
amount | number | ใช่ | จำนวนที่ต้องการปรับ (ค่าบวกเพื่อเพิ่ม ค่าลบเพื่อลด) |
TIP
ใช้ตัวเลขบวกเพื่อเพิ่มโควตา และตัวเลขลบเพื่อลดโควตา เช่น amount: 5000 จะเพิ่มโควตา 5000 จากค่าปัจจุบัน
ตัวอย่าง
# เพิ่มโควตา 5000 จากค่าปัจจุบัน
curl -X POST https://api.easyslip.com/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota/adjust \
-H "Content-Type: application/json" \
-H "X-API-Key: ${API_KEY}" \
-H "X-Timestamp: ${TIMESTAMP}" \
-H "X-Nonce: ${NONCE}" \
-H "X-Signature: ${SIGNATURE}" \
-d '{"amount": 5000}'const body = { amount: 5000 }
const headers = signRequest({
method: 'POST',
path: '/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota/adjust',
body,
apiKey: 'your_api_key',
secretKey: 'your_secret_key',
})
const response = await fetch(
'https://api.easyslip.com/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota/adjust',
{
method: 'POST',
headers,
body: JSON.stringify(body),
}
)
const result = await response.json()Success Response (200)
{
"success": true,
"data": {
"id": "cm1a2b3c4d5e6f7g8h9i0",
"name": "สำนักงานใหญ่",
"limitQuota": 20000,
"usedQuota": 1500,
"totalUsedQuota": 45000
}
}รีเซ็ตโควตาที่ใช้ไป
รีเซ็ตตัวนับโควตาที่ใช้ไปของสาขากลับเป็น 0
POST /b2b/branches/:branchId/quota/resetFull URL: https://api.easyslip.com/b2b/branches/:branchId/quota/reset
Permission: quota:write
DANGER
การดำเนินการนี้ไม่สามารถย้อนกลับได้ ตัวนับโควตาที่ใช้ไปจะถูกรีเซ็ตเป็น 0 แต่โควตาที่ใช้ไปทั้งหมดตลอดการใช้งาน (totalUsedQuota) จะไม่ได้รับผลกระทบ
ตัวอย่าง
curl -X POST https://api.easyslip.com/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota/reset \
-H "X-API-Key: ${API_KEY}" \
-H "X-Timestamp: ${TIMESTAMP}" \
-H "X-Nonce: ${NONCE}" \
-H "X-Signature: ${SIGNATURE}"const headers = signRequest({
method: 'POST',
path: '/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota/reset',
body: null,
apiKey: 'your_api_key',
secretKey: 'your_secret_key',
})
const response = await fetch(
'https://api.easyslip.com/b2b/branches/cm1a2b3c4d5e6f7g8h9i0/quota/reset',
{ method: 'POST', headers }
)
const result = await response.json()Success Response (200)
{
"success": true,
"data": {
"id": "cm1a2b3c4d5e6f7g8h9i0",
"name": "สำนักงานใหญ่",
"limitQuota": 20000,
"usedQuota": 0,
"totalUsedQuota": 45000
}
}หมายเหตุ
limitQuota: nullหมายความว่าสาขาไม่มีโควตาเฉพาะ จะถูกจำกัดด้วยโควตาระดับบริการเท่านั้นusedQuotaจะรีเซ็ตอัตโนมัติตามรอบบิลลิ่งของคุณtotalUsedQuotaติดตามการใช้งานทั้งหมดตลอดการใช้งาน ไม่มีการรีเซ็ต- ไม่สามารถปรับโควตาให้ต่ำกว่า
usedQuotaได้