Skip to content

API Reference Overview

ภาพรวม REST API — endpoint groups, auth schemes, response conventions

เอกสารแบบ interactive

หน้านี้คือ overview — สำหรับ schema + try-it-now ของแต่ละ endpoint ให้ดู Swagger UI: https://wms-api-dev-2w6s.onrender.com/api/v1/docs (non-prod เท่านั้น)

Base URL

EnvURL
Developmenthttps://wms-api-dev-2w6s.onrender.com/api/v1
Localhttp://localhost:3000/api/v1

Global prefix /api/v1 ตั้งใน main.ts:

typescript
app.setGlobalPrefix('api/v1');

Auth Schemes

ระบบรองรับ 2 auth scheme พร้อมกันบน API เดียว:

SchemeHeaderใช้กับบทบาท
JWT BearerAuthorization: Bearer <jwt>endpoint ปกติend-user (operator/admin) จาก Main WMS หรือ Admin Portal
API KeyX-API-Key: wms_… (หรือ Authorization: ApiKey …)/integration/v1/*external system (ERP, e-commerce)

ดูรายละเอียด: Authentication · Authorization

Swagger UI

URL: /api/v1/docs — เปิด เฉพาะ เมื่อ NODE_ENV !== 'production'

จาก main.ts:

typescript
if (nodeEnv !== 'production') {
  const swaggerConfig = new DocumentBuilder()
    .setTitle('WMS API')
    .setVersion('1.0')
    .addBearerAuth()
    .addApiKey({ type: 'apiKey', name: 'X-API-Key', in: 'header' }, 'api-key')
    .build();
  SwaggerModule.setup('api/v1/docs', app, document);
}

Endpoint Groups

จาก @Controller('…') ของทุก module:

PrefixModuleAuthPurpose
/authauthnone + JWTlogin, register, me, change-password
/usersusersJWT + admin/roleuser CRUD + permission management
/healthhealthnone/live, /ready, /stats
/itemsmaster-data/itemsJWTitems CRUD
/locationsmaster-data/locationsJWTlocations CRUD (20+ fields)
/uomsmaster-data/uomsJWTUoM CRUD + conversions
/partnersmaster-data/partnersJWTsuppliers/customers/carriers
/warehousesmaster-data/warehousesJWTwarehouse CRUD
/asninbound/asnJWTASN create + lines + status
/grninbound/grnJWTGRN (receive against ASN)
/putawayinbound/putawayJWTputaway tasks lifecycle
/putaway-rulesinbound/putawayJWTrule engine config
/stockinventory/stockJWTinquiry by item/location/lot
/movementsinventory (via stock)JWTmovement ledger query
/adjustmentsinventory/adjustmentsJWTstock correction
/cycle-countsinventory/cycle-countsJWTcount CRUD + variance
/ordersoutbound/ordersJWTsales order CRUD + cancel
/wavesoutbound/wavesJWTwave plan + release
/pick-tasksoutbound/pick-tasksJWTpick lifecycle
/shipmentsoutbound/shipmentsJWTshipment + packages + label
/rmareturns/rmaJWTreturn authorization + receipt
/lpnlpnJWTlicense plate CRUD + nest/split/movements
/replenishmentreplenishmentJWTrules + tasks
/approvalsapprovalsJWTpending queue + approve/reject
/auditauditJWT + adminaudit log search
/announcementsannouncementsJWT (admin write)banner messages
/api-keysapi-keysJWT + adminkey CRUD + stats + requests log
/webhookswebhookJWT + adminsubscription CRUD + test fire
/configconfigJWT + adminsystem config keys (WMS settings 8 tabs)
/filesfilesJWTR2 presigned upload URLs
/reportsreportsJWT + role22 aggregated reports (see below)
/integration/v1/*integrationAPI Keypush API (items, partners, locations, asn, grn, orders, lpn, stock)

ดูรายละเอียด method+path ต่อ module: Module Reference

Reports Endpoints (22)

ทั้งหมดอยู่ใต้ /reports/* — ทุก endpoint รับ filter querystring (warehouseId, dateFrom, dateTo, …)

GroupEndpoints
Inventory/inventory/stock-snapshot, /movements, /adjustments, /aging, /low-stock, /cycle-count-variance
Receiving/receiving/asn-summary, /grn-summary, /by-sku, /putaway-summary
Outbound/outbound/order-fulfillment, /pick-tasks, /cycle-time, /by-customer
Delivery/delivery/shipments, /by-carrier
Users/users/activity, /login-history, /productivity

Response Format Conventions

Paginated list (default)

json
{
  "data": [ /* array of records */ ],
  "total": 142,
  "page": 1,
  "limit": 20,
  "totalPages": 8
}

Query params: ?page=1&limit=20&search=…&sort=…&order=asc|desc

Single record

json
{ "id": "uuid", "field": "…" }

Mutation success (POST/PATCH/DELETE)

ส่วนใหญ่ตอบ record ที่ updated/created กลับ:

json
{ "id": "uuid", "field": "new value" }

Integration API envelope

ต่างกับ endpoints ปกติ — มี wrapper { status, data, requestId }:

json
{
  "status": "success",
  "data": { "item": { ... } },
  "requestId": "uuid-v4"
}

Bulk:

json
{
  "status": "partial",
  "total": 3,
  "created": 2,
  "errors": [ { "index": 1, "error": "..." } ],
  "data": [ ... ],
  "requestId": "uuid-v4"
}

HTTP 207 ถ้ามี errors

ดูเต็ม: Push Integration API

Error format

NestJS default — มาจาก HttpException:

json
{
  "statusCode": 400,
  "message": ["email must be an email", "password must be longer than 8"],
  "error": "Bad Request"
}

หรือ object ตรง ๆ (auth error):

json
{ "statusCode": 401, "message": "Invalid email or password" }

Special Headers

Headerใช้กับคำอธิบาย
Authorization: Bearer <jwt>endpoint ปกติJWT auth
X-API-Key: wms_…integrationAPI Key auth
Authorization: ApiKey wms_…integrationalt format
Idempotency-Key: <id>integration POST24h replay protection
Idempotent-Replay: trueresponseบอกว่า response เป็น cached replay
X-RateLimit-Limitintegration responsereq/min ของ API key
X-RateLimit-Remainingintegration responseคงเหลือใน window
Retry-After429 responseวินาทีที่ต้องรอ

CORS

จาก main.ts:

  • อนุญาต *.pages.dev ทุก subdomain (สำหรับ Cloudflare Pages preview deploys)
  • บวก origin list จาก CORS_ORIGIN env (comma-separated)
  • credentials: true — ส่ง cookie/Authorization ข้าม origin ได้
  • No-origin request (server-to-server, curl) → อนุญาตเสมอ

เผยแพร่ภายใต้ Digital Outsourcing