M2 API Reference
The M2 Maintenance API provides endpoints for work orders, assets, vendors, and emergency management.
Base URL
Section titled “Base URL”Production: https://m2.inspiringlivingsolutions.com/apiDevelopment: http://localhost:3000/apiAuthentication
Section titled “Authentication”Requires Authentik SSO session via NextAuth.
Endpoints
Section titled “Endpoints”Work Orders
Section titled “Work Orders”List Work Orders
Section titled “List Work Orders”GET /work-ordersQuery Parameters:
| Parameter | Type | Description |
|---|---|---|
| page | number | Page number |
| limit | number | Items per page |
| status | string | Filter by status |
| priority | string | Filter by priority |
| villaId | string | Filter by property |
| assigneeId | string | Filter by assignee |
Response:
{ "data": [ { "id": "uuid", "title": "AC not cooling", "status": "IN_PROGRESS", "priority": "HIGH", "category": "HVAC", "villa": { "id": "uuid", "name": "Villa Sunrise" }, "assignee": { "id": "uuid", "name": "John Tech" }, "createdAt": "2024-01-15T10:00:00Z" } ], "pagination": { "page": 1, "limit": 10, "total": 150 }}Get Work Order
Section titled “Get Work Order”GET /work-orders/:idCreate Work Order
Section titled “Create Work Order”POST /work-ordersBody:
{ "title": "AC not cooling", "description": "Master bedroom AC not working", "villaId": "uuid", "category": "HVAC", "priority": "HIGH", "assetId": "uuid"}Update Work Order
Section titled “Update Work Order”PATCH /work-orders/:idAssign Work Order
Section titled “Assign Work Order”POST /work-orders/:id/assignBody:
{ "assigneeId": "uuid", "assigneeType": "TECHNICIAN", "dueDate": "2024-01-20T17:00:00Z"}Add Comment
Section titled “Add Comment”POST /work-orders/:id/commentsBody:
{ "content": "Parts ordered, arriving tomorrow", "type": "PUBLIC"}Assets
Section titled “Assets”List Assets
Section titled “List Assets”GET /assetsGet Asset
Section titled “Get Asset”GET /assets/:idCreate Asset
Section titled “Create Asset”POST /assetsBody:
{ "name": "Samsung AC Unit", "category": "HVAC", "villaId": "uuid", "brand": "Samsung", "model": "AR24TXHQ", "serialNumber": "SN12345", "purchaseDate": "2023-01-15", "warrantyEndDate": "2026-01-15"}Update Health Score
Section titled “Update Health Score”PATCH /assets/:id/healthBody:
{ "healthScore": 75, "condition": "GOOD", "notes": "Minor wear observed"}Vendors
Section titled “Vendors”List Vendors
Section titled “List Vendors”GET /vendorsGet Vendor
Section titled “Get Vendor”GET /vendors/:idCreate Vendor
Section titled “Create Vendor”POST /vendorsBody:
{ "companyName": "AC Service Co", "contactName": "Somchai", "phone": "+66812345678", "categories": ["HVAC", "ELECTRICAL"]}Rate Vendor
Section titled “Rate Vendor”POST /vendors/:id/ratingsBody:
{ "workOrderId": "uuid", "quality": 5, "timeliness": 4, "communication": 5, "value": 4, "comments": "Excellent service"}Emergency Incidents
Section titled “Emergency Incidents”Report Emergency
Section titled “Report Emergency”POST /emergenciesBody:
{ "villaId": "uuid", "category": "WATER", "severity": "CRITICAL", "description": "Major water leak in kitchen", "location": "Kitchen"}Update Status
Section titled “Update Status”PATCH /emergencies/:id/statusBody:
{ "status": "CONTAINED", "notes": "Water shut off, waiting for plumber"}Log Action
Section titled “Log Action”POST /emergencies/:id/actionsBody:
{ "action": "Shut off main water valve", "performedBy": "uuid"}PMP (Preventive Maintenance)
Section titled “PMP (Preventive Maintenance)”List Templates
Section titled “List Templates”GET /pmp/templatesCreate Schedule
Section titled “Create Schedule”POST /pmp/schedulesBody:
{ "templateId": "uuid", "assetId": "uuid", "frequency": "MONTHLY", "startDate": "2024-01-01", "assigneeId": "uuid"}Field Notes
Section titled “Field Notes”Create Field Note
Section titled “Create Field Note”POST /field-notesBody (multipart/form-data):
- content: Note text
- type: TEXT | VOICE | PHOTO
- workOrderId: Linked work order (optional)
- assetId: Linked asset (optional)
- file: Media file (for VOICE/PHOTO)
Timesheets
Section titled “Timesheets”Log Time
Section titled “Log Time”POST /timesheetsBody:
{ "workOrderId": "uuid", "hours": 2.5, "activityType": "REPAIR", "date": "2024-01-15", "notes": "Replaced compressor"}Error Responses
Section titled “Error Responses”{ "error": { "code": "WORK_ORDER_NOT_FOUND", "message": "Work order not found", "statusCode": 404 }}