Web API Module
Web API Module
Section titled “Web API Module”The Web API Module provides a comprehensive REST API for external integrations and web interfaces.
🚀 Features
Section titled “🚀 Features”Core Functionality
Section titled “Core Functionality”- REST API - Full REST API implementation
- Authentication - Token-based authentication
- Rate Limiting - Prevent API abuse
- CORS Support - Cross-origin requests
- JSON Responses - Structured API responses
Advanced Features
Section titled “Advanced Features”- Player Management - Player information and history
- Moderation Actions - Ban, mute, kick via API
- Case Management - Case lookup and management
- IP Analysis - IP-based player analysis
- Alt Detection - Find alternate accounts
- Statistics - Server and moderation statistics
📋 API Endpoints
Section titled “📋 API Endpoints”Authentication
Section titled “Authentication”Generate Token
Section titled “Generate Token”/zenith token generate [duration]Examples:
/zenith token generate # Permanent token/zenith token generate 1h # 1 hour token/zenith token generate 7d # 7 day tokenUsing Tokens
Section titled “Using Tokens”Authorization: Bearer your-token-hereExample:
curl -H "Authorization: Bearer zm_a1b2c3d4e5f6" \ "http://server:3000/zenith/api/player/getinfo?name=Player123"Player Information
Section titled “Player Information”GET /player/getinfo
Section titled “GET /player/getinfo”Get detailed player information.
Parameters:
name(string) - Player nameuuid(string) - Player UUID
Example:
curl -H "Authorization: Bearer your-token" \ "http://server:3000/zenith/api/player/getinfo?name=Player123"GET /player/history
Section titled “GET /player/history”Get player’s punishment history.
Parameters:
name(string) - Player nameuuid(string) - Player UUIDlimit(int) - Max results (default: 50, max: 100)offset(int) - Skip results (default: 0)
Example:
curl -H "Authorization: Bearer your-token" \ "http://server:3000/zenith/api/player/history?name=Player123&limit=10"Moderation Actions
Section titled “Moderation Actions”POST /ban
Section titled “POST /ban”Ban a player via API.
Parameters:
player(string) - Player namereason(string) - Ban reasonduration(string) - Duration (optional)
Example:
curl -X POST -H "Authorization: Bearer your-token" \ "http://server:3000/zenith/api/ban?player=Player123?reason=Cheating&duration=7d"POST /mute
Section titled “POST /mute”Mute a player via API.
Parameters:
player(string) - Player namereason(string) - Mute reasonduration(string) - Duration (optional)
Example:
curl -X POST -H "Authorization: Bearer your-token" \ "http://server:3000/zenith/api/mute?player=Player123?reason=Spam&duration=1h"POST /warn
Section titled “POST /warn”Warn a player via API.
Parameters:
player(string) - Player nametemplate(string) - Template namereason(string) - Optional custom reason
Example:
curl -X POST -H "Authorization: Bearer your-token" \ "http://server:3000/zenith/api/warn?player=Player123&template=spam?reason=Excessive chat spam"GET /warn/history
Section titled “GET /warn/history”Get warning history for a player.
Parameters:
player(string) - Player namelimit(int) - Max results (default: 50, max: 100)offset(int) - Skip results (default: 0)
Example:
curl -H "Authorization: Bearer your-token" \ "http://server:3000/zenith/api/warn/history?player=Player123&limit=10"GET /warn/templates
Section titled “GET /warn/templates”Get available warning templates.
Example:
curl -H "Authorization: Bearer your-token" \ "http://server:3000/zenith/api/warn/templates"⚙️ Configuration
Section titled “⚙️ Configuration”Module Settings
Section titled “Module Settings”enabled: true
settings: port: 3000 host: "0.0.0.0" rate-limit: 100 rate-limit-window: 60 cors-enabled: true cors-origins: - "http://localhost:3000" - "https://yourdomain.com"Authentication Settings
Section titled “Authentication Settings”auth: token-length: 32 token-expiry: 30d require-permission: "zenith.api.access"Rate Limiting
Section titled “Rate Limiting”rate-limiting: enabled: true requests-per-minute: 100 burst-limit: 20 whitelist: - "127.0.0.1" - "::1"🔐 Permissions
Section titled “🔐 Permissions”Required Permissions
Section titled “Required Permissions”| Permission | Description |
|---|---|
zenith.api.access | Access to API |
zenith.api.token.use | Use token commands |
zenith.api.token.generate | Generate tokens |
zenith.api.token.list | List tokens |
zenith.api.token.revoke | Revoke tokens |
Permission Examples
Section titled “Permission Examples”permissions: - zenith.api.access: true - zenith.api.token.use: true - zenith.api.token.generate: true - zenith.api.token.list: true - zenith.api.token.revoke: trueWhat they can do:
- ✅ Full API access
- ✅ Generate tokens
- ✅ Manage tokens
- ✅ Use all endpoints
permissions: - zenith.api.access: true - zenith.api.token.use: true - zenith.api.token.generate: trueWhat they can do:
- ✅ Use API endpoints
- ✅ Generate tokens
- ❌ Manage existing tokens
📊 Database Schema
Section titled “📊 Database Schema”API Tokens Table
Section titled “API Tokens Table”CREATE TABLE zn_api_tokens ( id INT PRIMARY KEY AUTO_INCREMENT, token VARCHAR(64) UNIQUE NOT NULL, created_by VARCHAR(36) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, expires_at TIMESTAMP NULL, last_used TIMESTAMP NULL, active BOOLEAN DEFAULT TRUE);🔧 API Examples
Section titled “🔧 API Examples”JavaScript/Node.js
Section titled “JavaScript/Node.js”const axios = require('axios');
const api = axios.create({ baseURL: 'http://your-server-ip:3000/zenith/api', headers: { 'Authorization': 'Bearer your-token-here', 'Content-Type': 'application/json' }});
// Get player informationasync function getPlayer(player) { try { const response = await api.get(`/player/getinfo?name=${player}`); return response.data; } catch (error) { console.error('Error:', error.response.data); }}
// Ban a playerasync function banPlayer(player, reason, duration) { try { const response = await api.post(`/ban?player=${player}?reason=${reason}&duration=${duration}`); return response.data; } catch (error) { console.error('Error:', error.response.data); }}Python
Section titled “Python”import requests
API_BASE = 'http://your-server-ip:3000/zenith/api'HEADERS = { 'Authorization': 'Bearer your-token-here', 'Content-Type': 'application/json'}
def get_player(player): response = requests.get(f'{API_BASE}/player/getinfo?name={player}', headers=HEADERS) return response.json()
def ban_player(player, reason, duration=None): params = {'player': player, 'reason': reason} if duration: params['duration'] = duration response = requests.post(f'{API_BASE}/ban', params=params, headers=HEADERS) return response.json()🛠️ Troubleshooting
Section titled “🛠️ Troubleshooting”Common Issues
Section titled “Common Issues”Issue: API not responding
- Check if module is enabled
- Verify port is not in use
- Check firewall settings
- Ensure server is running
Issue: Authentication failed
- Check token validity
- Verify token permissions
- Check token expiration
- Regenerate token if needed
Issue: Rate limit exceeded
- Check rate limit settings
- Wait for rate limit reset
- Use whitelisted IPs
- Increase rate limit if needed
Debug Mode
Section titled “Debug Mode”Enable debug mode for detailed logging:
debug: enabled: true console: true file: true📈 Performance
Section titled “📈 Performance”Optimization Tips
Section titled “Optimization Tips”- Use MySQL/MariaDB for large servers
- Enable connection pooling
- Monitor API usage
- Implement caching
Monitoring
Section titled “Monitoring”- Track API usage
- Monitor response times
- Check error rates
- Review rate limiting
Need help with the Web API Module? Join our Discord: https://discord.gg/2qCMn6KHj4