All API routes are scoped to the authenticated user's organization. Responses follow a consistent format:
{
"success": true,
"data": {/* ... */},
"error": "Error message if success is false"
}NextAuth.js catch-all handler. Handles sign-in, sign-out, and session retrieval.
Create a new user account and organization.
Request Body:
{
"email": "user@example.com",
"password": "securePassword123",
"name": "User Name"
}Response: { success: true, data: { user: {...}, organization: {...} } }
List all suppliers for the current organization.
Response: { success: true, data: SupplierRecord[] }
Batch-create suppliers.
Request Body:
{
"suppliers": [{ "name": "Supplier A", "location": "New York", "category": "Raw Materials" }]
}Delete a supplier by ID.
List all facilities for the current organization.
Batch-create facilities.
Request Body:
{
"facilities": [{ "name": "Warehouse 1", "type": "Storage", "location": "Chicago" }]
}Delete a facility by ID.
List all transport routes.
Batch-create routes.
Request Body:
{
"routes": [
{
"originSupplierId": "uuid",
"destinationId": "uuid",
"mode": "TRUCK",
"distanceKm": 150
}
]
}Mode options: TRUCK, RAIL, AIR, SEA, OTHER
Delete a route by ID.
List all activity records.
Batch-create activity records with automatic emissions calculation.
Request Body:
{
"activities": [
{
"facilityId": "uuid",
"factorCategory": "diesel",
"amount": 5000,
"unit": "L",
"date": "2024-01-15"
}
]
}Bulk import suppliers, facilities, or activity data from CSV/Excel content.
Request Body:
{
"kind": "suppliers | facilities | activities",
"rows": [/* parsed rows */]
}Get the organization's carbon footprint summary.
Response:
{
"success": true,
"data": {
"total": 125000,
"scope1": 45000,
"scope2": 30000,
"scope3": 50000,
"topSuppliers": [{ "id": "uuid", "name": "Supplier A", "emissionsKg": 35000 }],
"topFacilities": [{ "id": "uuid", "name": "Facility B", "emissionsKg": 28000 }],
"monthlyTrend": [{ "month": "2024-01", "emissionsKg": 10000 }],
"activityCount": 42,
"supplierCount": 5,
"facilityCount": 3
}
}Run the rule-based insight engine and return observations.
Response:
{
"success": true,
"data": {
"insights": [
{
"id": "uuid",
"kind": "hotspot | recommendation | anomaly | breakdown",
"text": "Supplier A accounts for 45% of total emissions",
"detail": "Consider diversifying suppliers to reduce concentration risk."
}
]
}
}List report generation history.
Record a report generation event.
Request Body:
{
"format": "PDF | CSV | JSON"
}All endpoints return appropriate HTTP status codes:
| Status | Meaning |
|---|---|
| 200 | Success |
| 400 | Validation error (invalid input) |
| 401 | Not authenticated |
| 404 | Organization not found or entity not found |
| 500 | Internal server error |
Error responses include a user-friendly message in the error field.