-
-
Notifications
You must be signed in to change notification settings - Fork 2
API Reference
Complete REST API documentation for Source-License platform integration, license validation, and system management.
Source-License provides a comprehensive REST API for integrating license validation, order processing, and system management into your applications. The API supports JSON responses, JWT authentication, and webhooks for real-time notifications.
Production: https://yourdomain.com/api
Development: http://localhost:4567/api
Current API version: v1 (implicit in all endpoints)
Most API endpoints require JWT authentication. Obtain a token using the authentication endpoint:
Endpoint: POST /api/auth
Request:
POST /api/auth
Content-Type: application/json
{
"email": "admin@example.com",
"password": "your_password"
}
Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expires_at": "2024-01-15T15:30:00Z",
"user": {
"email": "admin@example.com",
"role": "admin"
}
}
Include the JWT token in the Authorization header:
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
For server-to-server integration, you can use API keys:
Header:
X-API-Key: your_api_key_here
Endpoint: GET /api/license/{license_key}/validate
Parameters:
-
license_key
(string): The license key to validate
Response:
{
"valid": true,
"status": "active",
"product": {
"id": 1,
"name": "My Software Pro",
"version": "1.0.0"
},
"license": {
"key": "XXXX-XXXX-XXXX-XXXX",
"expires_at": "2025-12-31T23:59:59Z",
"activations_used": 1,
"max_activations": 3,
"customer_email": "customer@example.com"
},
"validation_timestamp": "2024-01-15T10:30:00Z"
}
Error Response (Invalid License):
{
"valid": false,
"error": "license_not_found",
"message": "License key not found or invalid"
}
Error Response (Expired License):
{
"valid": false,
"error": "license_expired",
"message": "License has expired",
"expired_at": "2024-01-01T00:00:00Z"
}
Endpoint: GET /api/license/{license_key}/validate?machine_fingerprint={fingerprint}
Parameters:
-
license_key
(string): The license key to validate -
machine_fingerprint
(string): Unique machine identifier
Response:
{
"valid": true,
"status": "active",
"machine_authorized": true,
"activation_details": {
"machine_fingerprint": "unique_machine_id",
"activated_at": "2024-01-10T14:20:00Z",
"ip_address": "192.168.1.100"
},
"product": {
"id": 1,
"name": "My Software Pro"
},
"license": {
"key": "XXXX-XXXX-XXXX-XXXX",
"expires_at": "2025-12-31T23:59:59Z",
"activations_used": 1,
"max_activations": 3
}
}
Endpoint: POST /api/license/{license_key}/activate
Request:
POST /api/license/XXXX-XXXX-XXXX-XXXX/activate
Content-Type: application/json
{
"machine_fingerprint": "unique_machine_id",
"machine_name": "John's MacBook Pro",
"system_info": {
"os": "macOS 14.0",
"processor": "Apple M2",
"memory": "16GB",
"platform": "arm64"
},
"application_info": {
"version": "1.0.0",
"build": "1234"
}
}
Response (Success):
{
"success": true,
"activation_id": "12345",
"message": "License activated successfully",
"activation_details": {
"machine_fingerprint": "unique_machine_id",
"activated_at": "2024-01-15T10:30:00Z",
"ip_address": "192.168.1.100"
},
"license": {
"key": "XXXX-XXXX-XXXX-XXXX",
"activations_used": 2,
"max_activations": 3,
"remaining_activations": 1
}
}
Response (Activation Limit Reached):
{
"success": false,
"error": "activation_limit_reached",
"message": "Maximum number of activations reached",
"license": {
"activations_used": 3,
"max_activations": 3
}
}
Endpoint: POST /api/license/{license_key}/deactivate
Request:
POST /api/license/XXXX-XXXX-XXXX-XXXX/deactivate
Content-Type: application/json
{
"machine_fingerprint": "unique_machine_id"
}
Response:
{
"success": true,
"message": "License deactivated successfully",
"license": {
"activations_used": 1,
"max_activations": 3,
"remaining_activations": 2
}
}
Endpoint: GET /api/license/{license_key}
Authentication: Required
Response:
{
"license": {
"key": "XXXX-XXXX-XXXX-XXXX",
"status": "active",
"created_at": "2024-01-01T00:00:00Z",
"expires_at": "2025-12-31T23:59:59Z",
"activations_used": 1,
"max_activations": 3,
"customer_email": "customer@example.com"
},
"product": {
"id": 1,
"name": "My Software Pro",
"description": "Professional software license",
"version": "1.0.0"
},
"activations": [
{
"id": 1,
"machine_fingerprint": "unique_machine_id",
"machine_name": "John's MacBook Pro",
"activated_at": "2024-01-10T14:20:00Z",
"ip_address": "192.168.1.100",
"system_info": {
"os": "macOS 14.0",
"processor": "Apple M2"
}
}
]
}
Endpoint: POST /api/orders
Request:
POST /api/orders
Content-Type: application/json
{
"customer_email": "customer@example.com",
"items": [
{
"product_id": 1,
"quantity": 1
}
],
"billing_info": {
"name": "John Doe",
"company": "Acme Corp",
"address": {
"line1": "123 Main St",
"city": "New York",
"state": "NY",
"postal_code": "10001",
"country": "US"
}
}
}
Response:
{
"order": {
"id": "12345",
"status": "pending",
"customer_email": "customer@example.com",
"subtotal": 99.00,
"tax_total": 8.91,
"total": 107.91,
"currency": "USD",
"created_at": "2024-01-15T10:30:00Z"
},
"items": [
{
"product_id": 1,
"product_name": "My Software Pro",
"quantity": 1,
"unit_price": 99.00,
"total": 99.00
}
],
"payment_url": "https://checkout.stripe.com/pay/cs_...",
"payment_methods": ["stripe", "paypal"]
}
Endpoint: POST /api/orders/free
Request:
POST /api/orders/free
Content-Type: application/json
{
"customer_email": "customer@example.com",
"items": [
{
"product_id": 2,
"quantity": 1
}
]
}
Response:
{
"order": {
"id": "12346",
"status": "completed",
"customer_email": "customer@example.com",
"total": 0.00,
"currency": "USD"
},
"licenses": [
{
"key": "YYYY-YYYY-YYYY-YYYY",
"product_name": "Free Trial License",
"expires_at": "2024-02-15T00:00:00Z"
}
]
}
Endpoint: GET /api/orders/{order_id}
Authentication: Required
Response:
{
"order": {
"id": "12345",
"status": "completed",
"customer_email": "customer@example.com",
"subtotal": 99.00,
"tax_total": 8.91,
"total": 107.91,
"currency": "USD",
"payment_method": "stripe",
"created_at": "2024-01-15T10:30:00Z",
"completed_at": "2024-01-15T10:35:00Z"
},
"items": [
{
"product_id": 1,
"product_name": "My Software Pro",
"quantity": 1,
"unit_price": 99.00,
"total": 99.00
}
],
"licenses": [
{
"key": "XXXX-XXXX-XXXX-XXXX",
"product_name": "My Software Pro",
"expires_at": "2025-12-31T23:59:59Z",
"download_url": "https://yourdomain.com/download/secure_token"
}
],
"payment_details": {
"transaction_id": "pi_1234567890",
"payment_method": "visa",
"last4": "1234"
}
}
Endpoint: GET /api/products
Parameters:
-
status
(optional): Filter by status (active, inactive) -
category
(optional): Filter by category -
limit
(optional): Number of results (default: 50) -
offset
(optional): Pagination offset
Response:
{
"products": [
{
"id": 1,
"name": "My Software Pro",
"description": "Professional software license",
"price": 99.00,
"currency": "USD",
"license_type": "one_time",
"max_activations": 3,
"trial_period_days": 30,
"features": [
"Advanced features",
"Priority support",
"Free updates"
],
"created_at": "2024-01-01T00:00:00Z"
}
],
"pagination": {
"total": 5,
"limit": 50,
"offset": 0,
"has_more": false
}
}
Endpoint: GET /api/products/{product_id}
Response:
{
"product": {
"id": 1,
"name": "My Software Pro",
"description": "Professional software license with advanced features",
"price": 99.00,
"currency": "USD",
"license_type": "one_time",
"max_activations": 3,
"license_duration_days": null,
"trial_period_days": 30,
"setup_fee": 0.00,
"features": [
"Advanced reporting",
"API access",
"Priority support",
"Custom integrations"
],
"download_info": {
"has_download": true,
"file_size": "45.2 MB",
"supported_platforms": ["Windows", "macOS", "Linux"]
},
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-10T00:00:00Z"
}
}
Endpoint: GET /api/settings/{category}
Authentication: Required (Admin only)
Categories: app
, license
, payment
, email
, tax
, security
Example: GET /api/settings/license
Response:
{
"category": "license",
"settings": {
"default_license_format": "XXXX-XXXX-XXXX-XXXX",
"default_max_activations": 3,
"auto_generate_on_purchase": true,
"email_delivery_enabled": true,
"license_expiry_notification_days": 30
}
}
Endpoint: PUT /api/settings/{category}/{key}
Authentication: Required (Admin only)
Request:
PUT /api/settings/license/default_max_activations
Content-Type: application/json
{
"value": 5
}
Response:
{
"success": true,
"setting": {
"category": "license",
"key": "default_max_activations",
"value": 5,
"updated_at": "2024-01-15T10:30:00Z"
}
}
Endpoint: POST /api/webhook/stripe
Headers:
Stripe-Signature: t=1234567890,v1=signature_here
Supported Events:
-
payment_intent.succeeded
: Payment completed successfully -
payment_intent.payment_failed
: Payment failed -
invoice.payment_succeeded
: Subscription payment successful -
customer.subscription.updated
: Subscription status changed
Endpoint: POST /api/webhook/paypal
Supported Events:
-
PAYMENT.CAPTURE.COMPLETED
: Payment completed -
PAYMENT.CAPTURE.DENIED
: Payment denied -
BILLING.SUBSCRIPTION.ACTIVATED
: Subscription activated
Endpoint: GET /api/analytics/licenses
Authentication: Required (Admin only)
Parameters:
-
period
(optional): day, week, month, year (default: month) -
product_id
(optional): Filter by product
Response:
{
"period": "month",
"data": {
"total_licenses": 1250,
"active_licenses": 1100,
"expired_licenses": 150,
"activation_rate": 88.0,
"average_activations_per_license": 2.3
},
"trends": {
"new_licenses": 45,
"new_activations": 89,
"license_growth_rate": 3.6
}
}
Endpoint: GET /api/analytics/revenue
Authentication: Required (Admin only)
Response:
{
"period": "month",
"data": {
"total_revenue": 12500.00,
"orders_count": 125,
"average_order_value": 100.00,
"recurring_revenue": 2500.00
},
"trends": {
"revenue_growth": 15.2,
"order_growth": 8.5
},
"top_products": [
{
"product_id": 1,
"name": "My Software Pro",
"revenue": 7500.00,
"orders": 75
}
]
}
The API uses standard HTTP status codes:
-
200 OK
: Request successful -
201 Created
: Resource created successfully -
400 Bad Request
: Invalid request parameters -
401 Unauthorized
: Authentication required or invalid -
403 Forbidden
: Insufficient permissions -
404 Not Found
: Resource not found -
409 Conflict
: Resource conflict (e.g., duplicate license key) -
422 Unprocessable Entity
: Validation errors -
429 Too Many Requests
: Rate limit exceeded -
500 Internal Server Error
: Server error
{
"error": {
"code": "validation_error",
"message": "Invalid input parameters",
"details": {
"email": ["must be a valid email address"],
"product_id": ["must be a valid product ID"]
}
},
"request_id": "req_1234567890"
}
Code | Description |
---|---|
authentication_required |
Valid authentication token required |
invalid_token |
JWT token is invalid or expired |
insufficient_permissions |
User lacks required permissions |
license_not_found |
License key not found |
license_expired |
License has expired |
activation_limit_reached |
Maximum activations exceeded |
product_not_found |
Product ID not found |
order_not_found |
Order ID not found |
validation_error |
Request validation failed |
payment_processing_error |
Payment could not be processed |
rate_limit_exceeded |
Too many requests |
The API implements rate limiting to ensure fair usage:
Endpoint Type | Limit | Window |
---|---|---|
Authentication | 10 requests | 1 minute |
License Validation | 1000 requests | 1 hour |
License Operations | 100 requests | 1 hour |
Order Creation | 50 requests | 1 hour |
Admin API | 500 requests | 1 hour |
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 995
X-RateLimit-Reset: 1642678800
curl -X GET "https://yourdomain.com/api/license/XXXX-XXXX-XXXX-XXXX/validate" \
-H "Content-Type: application/json"
curl -X POST "https://yourdomain.com/api/license/XXXX-XXXX-XXXX-XXXX/activate" \
-H "Content-Type: application/json" \
-d '{
"machine_fingerprint": "unique_machine_id",
"system_info": {
"os": "Windows 11",
"processor": "Intel i7"
}
}'
const axios = require('axios');
class SourceLicenseAPI {
constructor(baseURL, apiKey = null) {
this.baseURL = baseURL;
this.apiKey = apiKey;
}
async validateLicense(licenseKey) {
try {
const response = await axios.get(
`${this.baseURL}/api/license/${licenseKey}/validate`
);
return response.data;
} catch (error) {
throw new Error(`License validation failed: ${error.response.data.error.message}`);
}
}
async activateLicense(licenseKey, machineFingerprint, systemInfo = {}) {
try {
const response = await axios.post(
`${this.baseURL}/api/license/${licenseKey}/activate`,
{
machine_fingerprint: machineFingerprint,
system_info: systemInfo
}
);
return response.data;
} catch (error) {
throw new Error(`License activation failed: ${error.response.data.error.message}`);
}
}
}
// Usage
const api = new SourceLicenseAPI('https://yourdomain.com');
const result = await api.validateLicense('XXXX-XXXX-XXXX-XXXX');
console.log('License valid:', result.valid);
import requests
class SourceLicenseAPI:
def __init__(self, base_url, api_key=None):
self.base_url = base_url
self.api_key = api_key
self.session = requests.Session()
if api_key:
self.session.headers.update({'X-API-Key': api_key})
def validate_license(self, license_key):
"""Validate a license key"""
response = self.session.get(
f"{self.base_url}/api/license/{license_key}/validate"
)
if response.status_code == 200:
return response.json()
else:
response.raise_for_status()
def activate_license(self, license_key, machine_fingerprint, system_info=None):
"""Activate a license on a machine"""
data = {
'machine_fingerprint': machine_fingerprint,
'system_info': system_info or {}
}
response = self.session.post(
f"{self.base_url}/api/license/{license_key}/activate",
json=data
)
if response.status_code == 200:
return response.json()
else:
response.raise_for_status()
# Usage
api = SourceLicenseAPI('https://yourdomain.com')
result = api.validate_license('XXXX-XXXX-XXXX-XXXX')
print(f"License valid: {result['valid']}")
Use the sandbox environment for testing:
Base URL: https://sandbox.yourdomain.com/api
The following test license keys are available in sandbox mode:
-
TEST-VALID-LICENSE-KEY
: Valid active license -
TEST-EXPIRED-LICENSE
: Expired license for testing -
TEST-MAXED-ACTIVATIONS
: License with maximum activations reached
This API reference provides complete documentation for integrating with Source-License. For additional support or questions, please refer to the Troubleshooting Guide or submit an issue on GitHub.