This document provides detailed information about the PowerPulse API endpoints.
- Authentication
- Auth API
- Users API
- NUT Servers API
- UPS Systems API
- Notifications API
- User Settings API
- Debug API
- System API
PowerPulse uses JSON Web Tokens (JWT) for authentication. Most API endpoints require a valid JWT token to be included in the request header.
Include the token in the Authorization header using the Bearer scheme:
Authorization: Bearer <your_jwt_token>
Tokens expire after 24 hours. After expiration, you'll need to log in again to get a new token.
Endpoints for authentication and user management.
GET /api/auth/check-setup
Checks if the application needs initial setup.
Response:
{
"isFirstTimeSetup": true|false
}
Endpoints for managing user settings.
GET /api/user-settings
Returns the settings for the current user.
Response:
{
"inactivity_timeout": 30,
"discord_webhook_url": "https://discord.com/api/webhooks/...",
"slack_webhook_url": "https://hooks.slack.com/services/...",
"notifications_enabled": 1,
"battery_notifications": 1,
"low_battery_notifications": 1,
"email_notifications": 0,
"email_recipients": "",
"poll_interval": 30
}
If no settings exist for the user, default settings are returned.
POST /api/user-settings
Updates the settings for the current user.
Request Body:
{
"inactivity_timeout": 60,
"discord_webhook_url": "https://discord.com/api/webhooks/...",
"slack_webhook_url": "https://hooks.slack.com/services/...",
"notifications_enabled": true,
"battery_notifications": true,
"low_battery_notifications": true,
"email_notifications": false,
"email_recipients": "",
"poll_interval": 60
}
All fields are optional. Only the fields that are provided will be updated.
Response:
{
"message": "User settings updated",
"inactivity_timeout": 60,
"discord_webhook_url": "https://discord.com/api/webhooks/...",
"slack_webhook_url": "https://hooks.slack.com/services/...",
"notifications_enabled": 1,
"battery_notifications": 1,
"low_battery_notifications": 1,
"email_notifications": 0,
"email_recipients": "",
"poll_interval": 60
}
Endpoints for debugging and testing. These endpoints are intended for development and troubleshooting purposes only.
GET /api/debug/battery-history/:upsId
Returns the raw battery history for a UPS system directly from the database.
Query Parameters:
days
(optional): Number of days of history to return (default: 7)
Response:
[
{
"id": 1,
"ups_id": 1,
"charge_percent": 100,
"timestamp": "2025-02-27T12:00:00.000Z"
},
{
"id": 2,
"ups_id": 1,
"charge_percent": 99,
"timestamp": "2025-02-27T12:05:00.000Z"
}
]
POST /api/debug/record-battery/:upsId/:charge
Manually records a battery charge percentage for a UPS system.
URL Parameters:
upsId
: ID of the UPS systemcharge
: Battery charge percentage (0-100)
Response:
{
"message": "Battery charge recorded",
"id": 3,
"upsId": 1,
"chargePercent": 98,
"timestamp": "2025-02-27T12:10:00.000Z"
}
GET /api/debug/tables
Returns a list of all tables in the database.
Response:
[
{
"name": "users"
},
{
"name": "nut_servers"
},
{
"name": "ups_systems"
}
]
GET /api/debug/schema/:table
Returns the schema for a specific database table.
URL Parameters:
table
: Name of the table
Response:
[
{
"cid": 0,
"name": "id",
"type": "INTEGER",
"notnull": 0,
"dflt_value": null,
"pk": 1
},
{
"cid": 1,
"name": "username",
"type": "TEXT",
"notnull": 1,
"dflt_value": null,
"pk": 0
}
]
POST /api/debug/test-ups-monitoring
Tests the UPS monitoring system by simulating a status change.
Request Body:
{
"ups_id": 1,
"ups_name": "Server Room UPS",
"server_id": 1,
"new_status": "On Battery",
"old_status": "Online"
}
All fields are optional and have default values.
Response:
{
"message": "UPS monitoring test completed",
"result": {
"success": true,
"notifications": {
"discord": true,
"slack": true,
"email": false
}
}
}
POST /api/debug/force-status-change
Forces a UPS status change and sends notifications to all users with notifications enabled.
Request Body:
{
"ups_id": 1,
"new_status": "On Battery",
"old_status": "Online"
}
All fields are optional and have default values.
Response:
{
"message": "Forced status change notifications processed",
"ups_id": 1,
"old_status": "Online",
"new_status": "On Battery",
"results": [
{
"user_id": 1,
"success": true,
"results": {
"discord": { "success": true },
"slack": { "success": true },
"email": null
}
}
]
}
GET /api/debug/ups-status-raw
Returns the raw UPS status values from the NUT server.
Response:
[
{
"id": 1,
"name": "ups1",
"displayName": "ups1",
"model": "APC Smart-UPS 1500",
"brand": "APC",
"serial": "AS1234567890",
"status": "OL",
"raw_status": "OL",
"batteryCharge": 100,
"batteryVoltage": 27.3,
"inputVoltage": 230.1,
"outputVoltage": 230.0,
"runtimeRemaining": 120,
"load": 30,
"temperature": 25.5,
"server": {
"id": 1,
"host": "localhost",
"port": 3493
}
}
]
GET /api/debug/count/:table
Returns the number of records in a specific database table.
URL Parameters:
table
: Name of the table
Response:
{
"count": 10
}
GET /api/debug/notification-settings
Returns the notification settings for the current user with masked webhook URLs for security.
Response:
{
"notifications_enabled": true,
"battery_notifications": true,
"low_battery_notifications": true,
"discord_webhook_url": "Configured",
"slack_webhook_url": "Not configured",
"email_notifications": false,
"email_recipients": "None"
}
POST /api/debug/raw-notification-test
Tests sending a notification with a raw NUT status code.
Request Body:
{
"status": "OB",
"webhook_url": "https://discord.com/api/webhooks/...",
"webhook_type": "discord"
}
Response:
{
"message": "Raw notification test sent successfully",
"status": "OB",
"translated_status": "On Battery",
"webhook_type": "discord",
"result": "Success"
}
POST /api/debug/test-notification
Tests sending a notification using the current user's notification settings.
Request Body:
{
"status": "On Battery",
"previous_status": "Online",
"ups_name": "Debug UPS",
"ups_id": 999
}
All fields are optional and have default values.
Response:
{
"message": "Debug notification sent successfully",
"settings": {
"discord_webhook_url": "Configured",
"slack_webhook_url": "Not configured",
"email_notifications": false,
"email_recipients": "None"
},
"response": {
"message": "Notifications sent successfully"
}
}
POST /api/auth/setup
Creates the first admin user and configures the initial NUT server.
Request Body:
{
"username": "admin",
"password": "your_password",
"nutServer": "localhost",
"nutPort": 3493
}
Response:
{
"message": "Setup completed successfully",
"user": {
"id": 1,
"username": "admin",
"role": "admin"
},
"token": "jwt_token",
"nutServer": {
"id": 1,
"host": "localhost",
"port": 3493
},
"upsSystemsDiscovered": 2,
"upsSystemsAdded": [
{
"id": 1,
"name": "ups1",
"upsName": "ups1",
"nutServerId": 1
}
]
}
POST /api/auth/login
Authenticates a user and returns a JWT token.
Request Body:
{
"username": "admin",
"password": "your_password"
}
Response:
{
"message": "Login successful",
"user": {
"id": 1,
"username": "admin",
"email": "[email protected]",
"role": "admin"
},
"token": "jwt_token"
}
POST /api/auth/register
Creates a new user (admin only).
Request Body:
{
"username": "user",
"email": "[email protected]",
"password": "user_password"
}
Response:
{
"message": "User created successfully",
"user": {
"id": 2,
"username": "user",
"email": "[email protected]",
"role": "user"
}
}
Endpoints for user management.
GET /api/users
Returns a list of all users (admin only).
Response:
[
{
"id": 1,
"username": "admin",
"email": "[email protected]",
"role": "admin",
"created_at": "2025-02-27T12:00:00.000Z"
},
{
"id": 2,
"username": "user",
"email": "[email protected]",
"role": "user",
"created_at": "2025-02-27T12:30:00.000Z"
}
]
GET /api/users/:id
Returns information about a specific user. Users can only view their own profile unless they are an admin.
Response:
{
"id": 1,
"username": "admin",
"email": "[email protected]",
"role": "admin",
"created_at": "2025-02-27T12:00:00.000Z"
}
PUT /api/users/:id
Updates a user's information. Users can only update their own profile unless they are an admin. Only admins can change user roles.
Request Body:
{
"username": "admin2",
"email": "[email protected]",
"role": "admin"
}
Response:
{
"message": "User updated",
"user": {
"id": 1,
"username": "admin2",
"email": "[email protected]",
"role": "admin",
"created_at": "2025-02-27T12:00:00.000Z"
}
}
DELETE /api/users/:id
Deletes a user (admin only). Cannot delete the last admin.
Response:
{
"message": "User deleted"
}
Endpoints for managing Network UPS Tools (NUT) servers.
GET /api/nut-servers
Returns a list of all NUT servers.
Response:
[
{
"id": 1,
"host": "localhost",
"port": 3493,
"username": null,
"updated_at": "2025-02-27T12:00:00.000Z"
}
]
GET /api/nut-servers/:id
Returns information about a specific NUT server.
Response:
{
"id": 1,
"host": "localhost",
"port": 3493,
"username": null,
"updated_at": "2025-02-27T12:00:00.000Z"
}
POST /api/nut-servers
Adds a new NUT server (admin only).
Request Body:
{
"host": "192.168.1.100",
"port": 3493,
"username": "upsmon",
"password": "secret"
}
Response:
{
"message": "NUT server created",
"id": 2,
"host": "192.168.1.100",
"port": 3493,
"username": "upsmon",
"upsSystemsDiscovered": 1,
"upsSystemsAdded": [
{
"id": 3,
"name": "ups2",
"upsName": "ups2",
"nutServerId": 2
}
]
}
PUT /api/nut-servers/:id
Updates a NUT server (admin only).
Request Body:
{
"host": "192.168.1.101",
"port": 3493,
"username": "upsmon",
"password": "newsecret"
}
Response:
{
"message": "NUT server updated",
"id": 2,
"host": "192.168.1.101",
"port": 3493,
"username": "upsmon"
}
DELETE /api/nut-servers/:id
Deletes a NUT server and all associated UPS systems (admin only).
Response:
{
"message": "NUT server deleted",
"deletedUpsSystems": [
{
"id": 3,
"name": "ups2"
}
]
}
POST /api/nut-servers/:id/test
Tests the connection to a NUT server and returns a list of available UPS systems.
Response:
{
"message": "Connection successful",
"upsList": ["ups1", "ups2"]
}
Endpoints for managing UPS systems.
GET /api/ups-systems
Returns a list of all UPS systems with their current status. Requires authentication.
Response:
[
{
"id": 1,
"name": "ups1",
"nickname": "Server Room UPS",
"displayName": "Server Room UPS",
"upsName": "ups1",
"nutServerId": 1,
"model": "APC Smart-UPS 1500",
"status": "Online",
"batteryCharge": 100,
"batteryVoltage": 27.3,
"inputVoltage": 230.1,
"outputVoltage": 230.0,
"runtimeRemaining": 120,
"load": 30,
"temperature": 25.5,
"batteryDetails": { ... },
"deviceDetails": { ... },
"driverDetails": { ... },
"inputDetails": { ... },
"outputDetails": { ... },
"upsDetails": { ... }
}
]
GET /api/ups-systems/kiosk
Returns a list of all UPS systems with their current status for kiosk mode. This endpoint does not require authentication and is specifically designed for public displays.
Response:
[
{
"id": 1,
"name": "ups1",
"nickname": "Server Room UPS",
"displayName": "Server Room UPS",
"upsName": "ups1",
"nutServerId": 1,
"model": "APC Smart-UPS 1500",
"status": "Online",
"batteryCharge": 100,
"batteryVoltage": 27.3,
"inputVoltage": 230.1,
"outputVoltage": 230.0,
"runtimeRemaining": 120,
"load": 30,
"temperature": 25.5,
"batteryDetails": { ... },
"deviceDetails": { ... },
"driverDetails": { ... },
"inputDetails": { ... },
"outputDetails": { ... },
"upsDetails": { ... }
}
]
GET /api/ups-systems/:id
Returns detailed information about a specific UPS system.
Response:
{
"id": 1,
"name": "ups1",
"nickname": "Server Room UPS",
"displayName": "Server Room UPS",
"upsName": "ups1",
"nutServerId": 1,
"model": "APC Smart-UPS 1500",
"status": "Online",
"batteryCharge": 100,
"batteryVoltage": 27.3,
"inputVoltage": 230.1,
"outputVoltage": 230.0,
"runtimeRemaining": 120,
"load": 30,
"temperature": 25.5,
"batteryDetails": { ... },
"deviceDetails": { ... },
"driverDetails": { ... },
"inputDetails": { ... },
"outputDetails": { ... },
"upsDetails": { ... }
}
POST /api/ups-systems
Adds a new UPS system.
Request Body:
{
"name": "ups3",
"nickname": "Network Closet UPS",
"nutServerId": 1,
"upsName": "ups3"
}
Response:
{
"message": "UPS system created",
"id": 4,
"name": "ups3",
"nickname": "Network Closet UPS",
"nutServerId": 1,
"upsName": "ups3"
}
PUT /api/ups-systems/:id
Updates a UPS system.
Request Body:
{
"name": "ups3",
"nickname": "Updated Network Closet UPS",
"nutServerId": 1,
"upsName": "ups3"
}
Response:
{
"message": "UPS system updated",
"id": 4,
"name": "ups3",
"nickname": "Updated Network Closet UPS",
"nutServerId": 1,
"upsName": "ups3"
}
PUT /api/ups-systems/:id/nickname
Updates just the nickname of a UPS system.
Request Body:
{
"nickname": "New Nickname"
}
Response:
{
"message": "UPS system nickname updated",
"id": 4,
"nickname": "New Nickname"
}
DELETE /api/ups-systems/:id
Deletes a UPS system (admin only).
Response:
{
"message": "UPS system deleted",
"id": 4
}
GET /api/ups-systems/:id/battery
Returns the battery charge history for a UPS system.
Query Parameters:
limit
(optional): Maximum number of records to return (default: 100)
Response:
[
{
"id": 1,
"ups_id": 1,
"charge_percent": 100,
"timestamp": "2025-02-27T12:00:00.000Z"
},
{
"id": 2,
"ups_id": 1,
"charge_percent": 99,
"timestamp": "2025-02-27T12:05:00.000Z"
}
]
POST /api/ups-systems/:id/battery
Manually records a battery charge percentage for a UPS system.
Request Body:
{
"chargePercent": 98
}
Response:
{
"message": "Battery charge recorded",
"id": 3,
"upsId": 1,
"chargePercent": 98,
"timestamp": "2025-02-27T12:10:00.000Z"
}
Endpoints for managing notification settings and sending notifications.
GET /api/notifications/settings
Returns the notification settings for the current user.
Response:
{
"discord_webhook_url": "https://discord.com/api/webhooks/...",
"slack_webhook_url": "https://hooks.slack.com/services/...",
"notifications_enabled": true,
"battery_notifications": true,
"low_battery_notifications": true,
"email_notifications": false,
"email_recipients": ""
}
POST /api/notifications/settings
Updates the notification settings for the current user.
Request Body:
{
"discord_webhook_url": "https://discord.com/api/webhooks/...",
"slack_webhook_url": "https://hooks.slack.com/services/...",
"notifications_enabled": true,
"battery_notifications": true,
"low_battery_notifications": true,
"email_notifications": true,
"email_recipients": "[email protected]"
}
Response:
{
"message": "Notification settings updated",
"discord_webhook_url": "https://discord.com/api/webhooks/...",
"slack_webhook_url": "https://hooks.slack.com/services/...",
"notifications_enabled": true,
"battery_notifications": true,
"low_battery_notifications": true,
"email_notifications": true,
"email_recipients": "[email protected]"
}
POST /api/notifications/test
Sends a test notification to Discord.
Request Body:
{
"discord_webhook_url": "https://discord.com/api/webhooks/..."
}
Response:
{
"message": "Test notification sent successfully"
}
POST /api/notifications/test-slack
Sends a test notification to Slack.
Request Body:
{
"slack_webhook_url": "https://hooks.slack.com/services/..."
}
Response:
{
"message": "Test notification sent successfully to Slack"
}
POST /api/notifications/test-email
Sends a test notification via email.
Request Body:
{
"email_recipients": "[email protected]"
}
Response:
{
"message": "Test notification sent successfully to email recipients"
}
GET /api/notifications/history
Returns the notification history for the current user.
Response:
[
{
"id": 1,
"user_id": 1,
"ups_id": 1,
"ups_name": "Server Room UPS",
"status": "On Battery",
"previous_status": "Online",
"created_at": "2025-02-27T12:00:00.000Z"
}
]
POST /api/notifications/ups-status
Sends a notification about a UPS status change.
Request Body:
{
"ups_id": 1,
"ups_name": "Server Room UPS",
"status": "On Battery",
"previous_status": "Online",
"discord_webhook_url": "https://discord.com/api/webhooks/...",
"slack_webhook_url": "https://hooks.slack.com/services/...",
"email_notifications": true,
"email_recipients": "[email protected]"
}
Response:
{
"message": "Notifications sent successfully"
}
Endpoints for system management.
GET /api/system/version
Returns the current application version.
Response:
{
"version": "1.8.1"
}
POST /api/system/update
Initiates a system update by pulling the latest Docker image and restarting (admin only).
Response:
{
"message": "Update initiated successfully",
"details": "The application will restart shortly. Please refresh the page after a minute."
}