API Reference
Complete documentation for the CyberLicense v1 REST API. All API endpoints return JSON responses and use standard HTTP status codes.
📋 Table of Contents
- Base URL
- Authentication
- License API
- Customer API
- Products API
- Audit Log API
- Export API
- 2FA API
- Automated Actions API
- BuiltByBit Integration API
- Webhooks API
- Error Handling
- Rate Limiting
Base URL
All API endpoints are prefixed with /api:
http://localhost:3000/api
Note: The API does not use versioning (no /v1 prefix). All endpoints are directly under /api.
Authentication
Admin Authentication
Admin APIs require authentication via Discord OAuth session. After logging in through the web interface, a session cookie is created and used for subsequent API requests.
Session Requirements:
- Valid Discord OAuth session
- Admin user must be registered in the database
- Session expires after 24 hours (configurable)
Customer Authentication
Customer APIs require authentication via Discord OAuth session. Customers log in through the customer portal, and their session is used for API requests.
Public API Authentication
Some endpoints (like license validation) are public and don't require authentication. However, they may be subject to rate limiting.
JWT Tokens (Optional)
For programmatic access, you can use JWT tokens. Configure JWT in config.yml and use the token in the Authorization header:
Authorization: Bearer <jwt-token>
License API
Endpoints for license management and validation.
POST /api/license/validate
Validates a software license. This is the primary endpoint for license validation in your applications.
Authentication: None (public endpoint, but rate limited)
Request Body:
{
"key": "LIC-ABC123-XYZ789",
"ip": "192.168.1.1", // Optional: IP address of the client
"hwid": "HWID-123456" // Optional: Hardware ID of the client
}
Success Response (200):
{
"success": true,
"valid": true,
"license": {
"key": "LIC-ABC123-XYZ789",
"active": true,
"expiresAt": "2024-12-31T23:59:59.000Z",
"ipLimit": 1,
"hwidLimit": 1,
"usedIps": ["192.168.1.1"],
"usedHwids": ["HWID-123456"],
"licenseType": "fixed"
}
}
Error Response (400/403):
{
"success": false,
"valid": false,
"error": "License not found" | "License expired" | "License suspended" | "IP limit exceeded" | "HWID limit exceeded" | "License revoked"
}
Possible Error Messages:
"License not found"- The license key doesn't exist"License expired"- The license has expired"License suspended"- The license is suspended"License revoked"- The license has been revoked"IP limit exceeded"- Too many IP addresses are using this license"HWID limit exceeded"- Too many hardware IDs are using this license"License not active"- The license is not active
Rate Limit: Configurable in config.yml (default: 200 requests per 15 minutes)
Example Usage:
curl -X POST http://localhost:3000/api/license/validate \
-H "Content-Type: application/json" \
-d '{
"key": "LIC-ABC123-XYZ789",
"ip": "192.168.1.1",
"hwid": "HWID-123456"
}'
POST /api/license/rotate
Rotates a license key (generates a new key for an existing license). The old key becomes invalid.
Authentication: Admin only
Request Body:
{
"key": "LIC-ABC123-XYZ789"
}
Response (200):
{
"success": true,
"oldKey": "LIC-ABC123-XYZ789",
"newKey": "LIC-DEF456-UVW012"
}
Error Response (404):
{
"success": false,
"error": "License not found"
}
POST /api/license/clear
Clears IP/HWID usage restrictions for a license. This allows the license to be used from new IP addresses and hardware IDs.
Authentication: Admin only
Request Body:
{
"key": "LIC-ABC123-XYZ789"
}
Response (200):
{
"success": true,
"message": "License restrictions cleared"
}
Error Response (404):
{
"success": false,
"error": "License not found"
}
Customer API
Endpoints for customer self-service portal. Customers can view their licenses, usage statistics, and manage their account.
Base URL: /api/customer
Authentication: Customer session (Discord OAuth)
GET /api/customer/licenses/:licenseId
Gets all licenses for the authenticated customer.
Response (200):
{
"success": true,
"licenses": [
{
"_id": "...",
"key": "LIC-ABC123",
"product": {
"_id": "...",
"name": "My Product"
},
"active": true,
"expiresAt": "2024-12-31T23:59:59.000Z",
"licenseType": "fixed",
"ipLimit": 1,
"hwidLimit": 1,
"usedIps": ["192.168.1.1"],
"usedHwids": ["HWID-123456"]
}
]
}
Gets detailed information about a specific license for the authenticated customer.
Response (200):
{
"success": true,
"license": {
"_id": "...",
"key": "LIC-ABC123",
"product": {
"_id": "...",
"name": "My Product",
"description": "Product description"
},
"active": true,
"expiresAt": "2024-12-31T23:59:59.000Z",
"licenseType": "fixed",
"usageStats": {
"totalRequests": 150,
"successfulRequests": 145,
"blockedRequests": 5,
"lastUsed": "2024-01-15T10:30:00.000Z",
"uniqueIPs": 3,
"uniqueHWIDs": 2
}
}
}
Error Response (404):
{
"success": false,
"error": "License not found"
}
GET /api/customer/licenses/:licenseId/usage
Gets usage statistics for a license.
Query Parameters:
startDate(string, optional): Start date in ISO 8601 formatendDate(string, optional): End date in ISO 8601 format
Response (200):
{
"success": true,
"usage": {
"total": 150,
"byStatus": {
"success": 145,
"blocked": 5,
"invalid": 0
},
"dailyStats": {
"2024-01-01": {
"success": 10,
"blocked": 0,
"invalid": 0
}
},
"requests": [
{
"_id": "...",
"ipAddress": "192.168.1.1",
"hwid": "HWID-123456",
"status": "success",
"createdAt": "2024-01-01T00:00:00.000Z"
}
]
}
}
GET /api/customer/licenses/stats
Gets general license statistics for the authenticated customer.
Response (200):
{
"success": true,
"stats": {
"totalLicenses": 5,
"activeLicenses": 3,
"expiredLicenses": 1,
"suspendedLicenses": 1,
"totalRequests": 500,
"successfulRequests": 480,
"byType": {
"fixed": 3,
"trial": 1,
"consumption": 1,
"enterprise": 0
}
}
}
GET /api/customer/licenses/:licenseId/credits
Gets credit balance for a consumption-based license.
Response (200):
{
"success": true,
"credits": {
"total": 1000,
"used": 350,
"remaining": 650
}
}
Error Response (400):
{
"success": false,
"error": "License is not a consumption-based license"
}
Products API
Endpoints for product management. Products represent software products or applications that licenses are issued for.
Base URL: /api/products
Authentication: Admin only
GET /api/products
Gets all products.
Query Parameters:
includeCounts(boolean, optional): Include license counts for each product (default:false)activeOnly(boolean, optional): Return only active products (default:false)
Response (200):
{
"success": true,
"products": [
{
"_id": "...",
"name": "My Product",
"description": "Product description",
"isActive": true,
"licensePrefix": "LIC",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
],
"count": 1
}
Response with counts (200):
When includeCounts=true:
{
"success": true,
"products": [
{
"_id": "...",
"name": "My Product",
"description": "Product description",
"isActive": true,
"licensePrefix": "LIC",
"licenseCount": 10,
"activeLicenseCount": 8,
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
],
"count": 1
}
Error Response (401):
{
"success": false,
"error": "Unauthorized"
}
Example Usage:
# Get all products
curl -X GET http://localhost:3000/api/products \
-H "Cookie: connect.sid=..."
# Get all products with license counts
curl -X GET "http://localhost:3000/api/products?includeCounts=true" \
-H "Cookie: connect.sid=..."
# Get only active products with counts
curl -X GET "http://localhost:3000/api/products?activeOnly=true&includeCounts=true" \
-H "Cookie: connect.sid=..."
GET /api/products/:id
Gets a single product by ID.
Query Parameters:
includeCounts(boolean, optional): Include license counts for the product (default:false)
Response (200):
{
"success": true,
"product": {
"_id": "...",
"name": "My Product",
"description": "Product description",
"isActive": true,
"licensePrefix": "LIC",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
}
Response with counts (200):
When includeCounts=true:
{
"success": true,
"product": {
"_id": "...",
"name": "My Product",
"description": "Product description",
"isActive": true,
"licensePrefix": "LIC",
"licenseCount": 10,
"activeLicenseCount": 8,
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
}
Error Response (401):
{
"success": false,
"error": "Unauthorized"
}
Error Response (404):
{
"success": false,
"error": "Product not found"
}
Example Usage:
# Get product by ID
curl -X GET http://localhost:3000/api/products/507f1f77bcf86cd799439011 \
-H "Cookie: connect.sid=..."
# Get product with license counts
curl -X GET "http://localhost:3000/api/products/507f1f77bcf86cd799439011?includeCounts=true" \
-H "Cookie: connect.sid=..."
Audit Log API
Endpoints to view system audit logs. All administrative actions are automatically logged.
Base URL: /api/audit
Authentication: Admin only
GET /api/audit
Gets audit logs with optional filters.
Query Parameters:
userId(string, optional): Filter by admin user IDresourceType(string, optional): Filter by resource type (license,customer,product,admin,transaction,notification,system)resourceId(string, optional): Filter by resource IDaction(string, optional): Filter by action (create,update,delete,view,login,logout,export,import,revoke,activate,suspend)startDate(string, optional): Start date in ISO 8601 formatendDate(string, optional): End date in ISO 8601 formatsuccess(boolean, optional): Filter by success statuslimit(number, optional): Number of results (default: 100, max: 1000)skip(number, optional): Skip results for pagination (default: 0)
Response (200):
{
"success": true,
"auditLogs": [
{
"_id": "...",
"userId": "...",
"action": "create",
"resourceType": "license",
"resourceId": "...",
"changes": {
"before": {},
"after": {
"key": "LIC-123",
"active": true
}
},
"ip": "192.168.1.1",
"userAgent": "Mozilla/5.0...",
"success": true,
"createdAt": "2024-01-01T00:00:00.000Z"
}
],
"count": 150,
"total": 150
}
GET /api/audit/:id
Gets a single audit log entry by ID.
Response (200):
{
"success": true,
"auditLog": {
"_id": "...",
"userId": "...",
"action": "create",
"resourceType": "license",
"resourceId": "...",
"changes": {
"before": {},
"after": { ... }
},
"ip": "192.168.1.1",
"userAgent": "Mozilla/5.0...",
"success": true,
"createdAt": "2024-01-01T00:00:00.000Z"
}
}
Export API
Endpoints to export data in CSV and PDF formats.
Base URL: /api/export
Authentication: Admin only
GET /api/export/licenses/csv
Exports licenses in CSV format.
Query Parameters:
product(string, optional): Filter by product IDcustomer(string, optional): Filter by customer IDactive(boolean, optional): Filter by active statuslicenseType(string, optional): Filter by type (fixed,trial,consumption,enterprise)
Response: Downloadable CSV file
Headers:
Content-Type: text/csvContent-Disposition: attachment; filename=licenses-{timestamp}.csv
Example:
curl -X GET "http://localhost:3000/api/export/licenses/csv?active=true" \
-H "Cookie: session=..." \
-o licenses.csv
GET /api/export/licenses/pdf
Exports licenses in PDF format.
Query Parameters: Same as CSV export
Response: Downloadable PDF file
Headers:
Content-Type: application/pdfContent-Disposition: attachment; filename=licenses-{timestamp}.pdf
GET /api/export/transactions/csv
Exports transactions in CSV format.
Query Parameters:
customer(string, optional): Filter by customer IDstatus(string, optional): Filter by status (pending,processing,completed,failed,refunded,cancelled)startDate(string, optional): Start date in ISO 8601 formatendDate(string, optional): End date in ISO 8601 format
Response: Downloadable CSV file