# SharePanel API Reference Complete API documentation for integrating SharePanel into your applications. ## Base URL ``` https://api.sharepanel.host ``` ## Authentication All API endpoints (except authentication) require an API key. ### Getting an API Key 1. Authenticate with your SharePanel credentials 2. Receive your API key 3. Include API key in all subsequent requests ### Authentication Endpoint **GET/POST** `/api?mode=auth&email={email}&password={password}` **Parameters:** - `mode` (required): Set to `auth` - `email` (required): Your SharePanel email - `password` (required): Your SharePanel password - `name` (optional): Custom name for the API key **Response:** ```json { "status": "success", "message": "Authentication successful", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "api_key": "your_api_key_here" } } ``` ## Rate Limiting Rate limits are enforced based on your subscription plan: | Plan | Daily Requests | Per Minute | Max Payload | |------|---------------|------------|-------------| | Free | 100 | 10 | 1 MB | | Basic | 1,000 | 30 | 5 MB | | Pro | 10,000 | 100 | 15 MB | | Enterprise | 50,000 | 500 | 50 MB | Rate limit headers are included in responses: - `X-RateLimit-Limit`: Maximum requests - `X-RateLimit-Remaining`: Remaining requests - `X-RateLimit-Reset`: Reset time ## Request Methods The API supports both GET and POST requests. For POST requests, you can send parameters either as: - URL query parameters - JSON body (Content-Type: application/json) - Form data ## User Profile ### Get User Profile **GET/POST** `/api?mode=profile&api_key={api_key}&action=view` **Response:** ```json { "status": "success", "message": "Profile retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "id": 123, "username": "username", "email": "user@example.com", "bio": "User bio", "pfp": "profile_picture_url", "plan": "pro", "org_limit": 10, "instance_limit": 25, "verified": 1, "balance": 100.00, "created_at": "2023-01-01 12:00:00", "filelimit": 1000, "storagelimit": 100, "first_name": "John", "last_name": "Doe", "phone": "1234567890", "address": "123 Main St" } } ``` ### Update Profile **POST** `/api?mode=profile&api_key={api_key}&action=update` **Parameters:** - `bio` (optional): Update bio - `pfp` (optional): Update profile picture URL - `first_name` (optional): Update first name - `last_name` (optional): Update last name - `phone` (optional): Update phone number - `address` (optional): Update address **Response:** ```json { "status": "success", "message": "Profile updated successfully", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ### Get Profile Statistics **GET/POST** `/api?mode=profile&api_key={api_key}&action=stats` **Response:** ```json { "status": "success", "message": "Statistics retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "org_count": 5, "instance_count": 12, "active_instances": 8, "invoice_count": 15, "total_spent": 250.00 } } ``` ## Organizations ### List Organizations **GET/POST** `/api?mode=orgs&api_key={api_key}&action=list` **Response:** ```json { "status": "success", "message": "Organizations retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "id": 1, "title": "Organization Name", "path": "organization-name", "admin_id": 123, "contact": "contact@example.com", "created_by": 123, "isAdmin": 1, "permissionlevel": 3 } ] } ``` ### View Organization Details **GET/POST** `/api?mode=orgs&api_key={api_key}&action=view&org_id={org_id}` **Parameters:** - `org_id` (required): Organization ID **Response:** ```json { "status": "success", "message": "Organization retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "id": 1, "title": "Organization Name", "path": "organization-name", "admin_id": 123, "contact": "contact@example.com", "created_by": 123, "member_count": 5, "instance_count": 3 } } ``` ### Create Organization **POST** `/api?mode=orgs&api_key={api_key}&action=new` **Parameters:** - `title` (optional): Organization title (default: "New Organization") - `path` (optional): Organization path (auto-generated from title if not provided) - `contact` (optional): Contact email **Response:** ```json { "status": "success", "message": "Organization created successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "org_id": 1 } } ``` ### Update Organization **POST** `/api?mode=orgs&api_key={api_key}&action=update&org_id={org_id}` **Parameters:** - `org_id` (required): Organization ID - `title` (optional): Update title - `path` (optional): Update path - `contact` (optional): Update contact email **Response:** ```json { "status": "success", "message": "Organization updated successfully", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ### Delete Organization **POST** `/api?mode=orgs&api_key={api_key}&action=delete&org_id={org_id}` **Parameters:** - `org_id` (required): Organization ID to delete **Response:** ```json { "status": "success", "message": "Organization deleted successfully", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ### List Organization Members **GET/POST** `/api?mode=orgs&api_key={api_key}&action=members&org_id={org_id}` **Parameters:** - `org_id` (required): Organization ID **Response:** ```json { "status": "success", "message": "Members retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "memberID": 123, "organization_id": 1, "isAdmin": 1, "permissionlevel": 3, "username": "username", "email": "user@example.com", "pfp": "profile_picture_url" } ] } ``` ## Instances ### List Instances **GET/POST** `/api?mode=instances&api_key={api_key}&action=list` **Parameters:** - `type` (optional): Filter by type (`SNCS`, `SMS`, or `all` - default: `all`) - `status` (optional): Filter by status (`active`, `sleep`, `dead`) **Response:** ```json { "status": "success", "message": "Instances retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "id": 1, "instance_name": "Instance Name", "instance_path": "instance-path", "created_at": "2023-01-01 12:00:00", "status": "active", "instance_type": "default", "type": "SNCS" } ] } ``` ### View Instance Details **GET/POST** `/api?mode=instances&api_key={api_key}&action=view&instance_id={instance_id}` **Parameters:** - `instance_id` (required): Instance ID **Response:** ```json { "status": "success", "message": "Instance retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "id": 1, "instance_name": "Instance Name", "instance_path": "instance-path", "created_at": "2023-01-01 12:00:00", "status": "active", "instance_type": "default", "user_id": 123 } } ``` ### Update Instance Status **POST** `/api?mode=instances&api_key={api_key}&action=update_status&instance_id={instance_id}&status={status}` **Parameters:** - `instance_id` (required): Instance ID - `status` (required): New status (`active`, `sleep`, or `dead`) **Response:** ```json { "status": "success", "message": "Instance status updated successfully", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ### Delete Dead Instances **POST** `/api?mode=instances&api_key={api_key}&action=delete_dead` **Response:** ```json { "status": "success", "message": "3 dead instances deleted successfully", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ### Awaken All Instances **POST** `/api?mode=instances&api_key={api_key}&action=awaken_all` **Response:** ```json { "status": "success", "message": "5 instances awakened successfully", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ### Sleep All Instances **POST** `/api?mode=instances&api_key={api_key}&action=sleep_all` **Response:** ```json { "status": "success", "message": "5 instances put to sleep successfully", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ## Billing ### Get Account Balance **GET/POST** `/api?mode=billing&api_key={api_key}&action=balance` **Response:** ```json { "status": "success", "message": "Balance retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "balance": 100.50, "currency": "USD" } } ``` ### List Invoices **GET/POST** `/api?mode=billing&api_key={api_key}&action=invoices` **Parameters:** - `status` (optional): Filter by status (`pending`, `paid`, `overdue`) - `limit` (optional): Number of results (default: 50) - `offset` (optional): Pagination offset (default: 0) **Response:** ```json { "status": "success", "message": "Invoices retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "id": 1, "invoice_number": "INV-20240101-ABC123", "total_amount": 50.00, "status": "paid", "created_at": "2024-01-01 12:00:00", "paid_at": "2024-01-01 12:30:00" } ] } ``` ### Get Invoice Details **GET/POST** `/api?mode=billing&api_key={api_key}&action=invoice&invoice_id={invoice_id}` **Parameters:** - `invoice_id` (required): Invoice ID **Response:** ```json { "status": "success", "message": "Invoice retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "id": 1, "invoice_number": "INV-20240101-ABC123", "total_amount": 50.00, "status": "paid", "created_at": "2024-01-01 12:00:00", "paid_at": "2024-01-01 12:30:00" } } ``` ### Get Transactions **GET/POST** `/api?mode=billing&api_key={api_key}&action=transactions` **Parameters:** - `limit` (optional): Number of results (default: 50) - `offset` (optional): Pagination offset (default: 0) **Response:** ```json { "status": "success", "message": "Transactions retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "id": 1, "transaction_id": "INV-20240101-ABC123", "amount": 50.00, "status": "completed", "date": "2024-01-01 12:00:00", "type": "invoice" } ] } ``` ### Get Purchases **GET/POST** `/api?mode=billing&api_key={api_key}&action=purchases` **Parameters:** - `limit` (optional): Number of results (default: 50) - `offset` (optional): Pagination offset (default: 0) **Response:** ```json { "status": "success", "message": "Purchases retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "id": 1, "item_id": "app-123", "item_type": "app", "purchase_type": "one_time", "price": 25.00, "tokens_paid": 25.00, "created_at": "2024-01-01 12:00:00" } ] } ``` ### List Available Plans **GET/POST** `/api?mode=billing&api_key={api_key}&action=plans` **Response:** ```json { "status": "success", "message": "Plans retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "id": 1, "name": "free", "price": 0.00, "org_limit": 1, "instance_limit": 1, "filelimit": 1000, "storagelimit": 100, "description": "Free plan", "features": "Basic features" } ] } ``` ## Analytics ### Get Analytics Overview **GET/POST** `/api?mode=analytics&api_key={api_key}&action=overview` **Response:** ```json { "status": "success", "message": "Analytics overview retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "total_orgs": 5, "total_instances": 12, "active_instances": 8, "total_invoices": 15, "total_spent": 250.00, "current_balance": 100.50, "active_api_keys": 2 } } ``` ### Get API Usage Statistics **GET/POST** `/api?mode=analytics&api_key={api_key}&action=usage` **Parameters:** - `period` (optional): Number of days (default: 30) **Response:** ```json { "status": "success", "message": "Usage statistics retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "date": "2024-01-01", "request_count": 150, "unique_endpoints": 8, "avg_response_time": 0.125, "success_count": 145, "error_count": 5 } ] } ``` ### Get Activity Logs **GET/POST** `/api?mode=analytics&api_key={api_key}&action=activity` **Parameters:** - `limit` (optional): Number of results (default: 50) - `offset` (optional): Pagination offset (default: 0) **Response:** ```json { "status": "success", "message": "Activity logs retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "id": 1, "user_id": 123, "action": "organization_created", "resource_type": "organization", "resource_id": 5, "details": {"org_name": "My Org"}, "ip_address": "192.168.1.1", "created_at": "2024-01-01 12:00:00" } ] } ``` ### Get Spending Analytics **GET/POST** `/api?mode=analytics&api_key={api_key}&action=spending` **Parameters:** - `period` (optional): Number of days (default: 30) **Response:** ```json { "status": "success", "message": "Spending analytics retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "date": "2024-01-01", "invoice_count": 3, "total_spent": 75.00 } ] } ``` ## Notifications ### List Notifications **GET/POST** `/api?mode=notifications&api_key={api_key}&action=list` **Parameters:** - `unread_only` (optional): Set to `true` to get only unread notifications - `limit` (optional): Number of results (default: 50) - `offset` (optional): Pagination offset (default: 0) **Response:** ```json { "status": "success", "message": "Notifications retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "id": 1, "title": "New Invoice", "message": "Your invoice INV-123 has been generated", "type": "info", "is_read": 0, "link": "/billing/invoice/1", "created_at": "2024-01-01 12:00:00" } ] } ``` ### Get Unread Count **GET/POST** `/api?mode=notifications&api_key={api_key}&action=unread_count` **Response:** ```json { "status": "success", "message": "Unread count retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "count": 5 } } ``` ### Mark Notification as Read **POST** `/api?mode=notifications&api_key={api_key}&action=mark_read` **Parameters:** - `notification_id` (optional): Specific notification ID (if omitted, marks all as read) **Response:** ```json { "status": "success", "message": "Notification marked as read", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ### Delete Notification **POST** `/api?mode=notifications&api_key={api_key}&action=delete¬ification_id={notification_id}` **Parameters:** - `notification_id` (required): Notification ID to delete **Response:** ```json { "status": "success", "message": "Notification deleted successfully", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ## API Keys ### List API Keys **GET/POST** `/api?mode=api_keys&api_key={api_key}&action=list` **Response:** ```json { "status": "success", "message": "API keys retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "id": 1, "name": "API Key for username", "created_at": "2024-01-01 12:00:00", "last_used_at": "2024-01-01 14:00:00", "expires_at": null, "is_active": 1, "permissions": "read,write" } ] } ``` ### Create API Key **POST** `/api?mode=api_keys&api_key={api_key}&action=create` **Parameters:** - `name` (optional): Name for the API key (default: "New API Key") - `permissions` (optional): Permissions (default: "read,write") - `expires_at` (optional): Expiration date (ISO 8601 format) **Response:** ```json { "status": "success", "message": "API key created successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "api_key": "new_api_key_here" } } ``` ### Delete API Key **POST** `/api?mode=api_keys&api_key={api_key}&action=delete&key_id={key_id}` **Parameters:** - `key_id` (required): API key ID to delete **Response:** ```json { "status": "success", "message": "API key deleted successfully", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ### Get API Key Usage **GET/POST** `/api?mode=api_keys&api_key={api_key}&action=usage&key_id={key_id}` **Parameters:** - `key_id` (required): API key ID **Response:** ```json { "status": "success", "message": "API key usage retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "total_requests": 1500, "active_days": 30, "endpoints_used": 12, "last_request": "2024-01-01 14:00:00", "avg_response_time": 0.125, "success_count": 1450, "error_count": 50 } } ``` ## Statistics ### Get Overview Statistics **GET/POST** `/api?mode=stats&api_key={api_key}&type=overview` **Response:** ```json { "status": "success", "message": "Statistics retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "orgs": 5, "total_instances": 12, "active_instances": 8, "asleep_instances": 2, "dead_instances": 2, "total_invoices": 15, "paid_invoices": 12, "pending_invoices": 3, "api_keys": 2, "balance": 100.50, "total_spent": 250.00 } } ``` ### Get Instance Statistics **GET/POST** `/api?mode=stats&api_key={api_key}&type=instances` **Response:** ```json { "status": "success", "message": "Instance statistics retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "total": 12, "active": 8, "asleep": 2, "dead": 2, "types": 3 } } ``` ### Get Organization Statistics **GET/POST** `/api?mode=stats&api_key={api_key}&type=organizations` **Response:** ```json { "status": "success", "message": "Organization statistics retrieved successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": { "total": 5, "admin_count": 3 } } ``` ## Search ### Search **GET/POST** `/api?mode=search&api_key={api_key}&query={query}` **Parameters:** - `query` (required): Search query - `type` (optional): Filter by type (`organizations`, `instances`, or `all` - default: `all`) **Response:** ```json { "status": "success", "message": "Search completed successfully", "timestamp": "2024-01-01T12:00:00+00:00", "data": [ { "type": "organization", "id": 1, "name": "My Organization", "path": "my-organization", "created_at": "2024-01-01 12:00:00" }, { "type": "instance", "id": 5, "name": "My Instance", "path": "my-instance", "created_at": "2024-01-01 12:00:00", "status": "active" } ] } ``` ## Error Handling All API errors return a JSON response with status "error": ```json { "status": "error", "message": "Error message here", "timestamp": "2024-01-01T12:00:00+00:00" } ``` ### Common Error Messages - `"Invalid or expired API key"` - `"Rate limit exceeded. Please try again later."` - `"Email and password are required"` - `"Invalid email or password"` - `"Organization ID is required"` - `"You do not have permission to delete this organization"` - `"Organization limit reached for your plan"` - `"Invalid mode. Available modes: auth, profile, orgs, instances, billing, analytics, notifications, api_keys, search, stats"` - `"Invalid action for [mode] mode"` ### HTTP Status Codes - `200`: Success - `400`: Bad Request - `401`: Unauthorized - `403`: Forbidden - `404`: Not Found - `429`: Too Many Requests (Rate Limit Exceeded) - `500`: Internal Server Error ## Code Examples ### PHP ```php 'orgs', 'api_key' => $apiKey, 'action' => 'new', 'title' => 'My Organization', 'contact' => 'contact@example.com' ]; $context = stream_context_create([ 'http' => [ 'method' => 'POST', 'header' => 'Content-Type: application/x-www-form-urlencoded', 'content' => http_build_query($orgData) ] ]); $response = file_get_contents('https://api.sharepanel.host/api', false, $context); $result = json_decode($response, true); ?> ``` ### Python ```python import requests # Authenticate email = "user@example.com" password = "password" auth_url = f"https://api.sharepanel.host/api?mode=auth&email={email}&password={password}" response = requests.get(auth_url) data = response.json() api_key = data['data']['api_key'] # Get profile profile_url = f"https://api.sharepanel.host/api?mode=profile&api_key={api_key}&action=view" response = requests.get(profile_url) profile = response.json() # Create organization (POST with JSON) org_data = { 'mode': 'orgs', 'api_key': api_key, 'action': 'new', 'title': 'My Organization', 'contact': 'contact@example.com' } response = requests.post('https://api.sharepanel.host/api', json=org_data) result = response.json() ``` ### JavaScript ```javascript // Authenticate const email = "user@example.com"; const password = "password"; const authUrl = `https://api.sharepanel.host/api?mode=auth&email=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}`; fetch(authUrl) .then(response => response.json()) .then(data => { const apiKey = data.data.api_key; // Get profile const profileUrl = `https://api.sharepanel.host/api?mode=profile&api_key=${encodeURIComponent(apiKey)}&action=view`; return fetch(profileUrl); }) .then(response => response.json()) .then(profile => { console.log(profile); }); // Create organization (POST with JSON) const orgData = { mode: 'orgs', api_key: apiKey, action: 'new', title: 'My Organization', contact: 'contact@example.com' }; fetch('https://api.sharepanel.host/api', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(orgData) }) .then(response => response.json()) .then(result => { console.log(result); }); ``` ### cURL ```bash # Authenticate curl "https://api.sharepanel.host/api?mode=auth&email=user@example.com&password=password" # Get profile curl "https://api.sharepanel.host/api?mode=profile&api_key=YOUR_API_KEY&action=view" # Create organization (POST) curl -X POST "https://api.sharepanel.host/api" \ -H "Content-Type: application/json" \ -d '{ "mode": "orgs", "api_key": "YOUR_API_KEY", "action": "new", "title": "My Organization", "contact": "contact@example.com" }' ``` ## Best Practices 1. **Store API Keys Securely**: Never commit API keys to version control. Use environment variables or secure key management systems. 2. **Handle Errors**: Always check response status and handle errors appropriately. 3. **Respect Rate Limits**: Implement exponential backoff when rate limits are exceeded. 4. **Use HTTPS**: Always use secure connections (HTTPS) for all API requests. 5. **Validate Input**: Validate all parameters before sending requests to avoid errors. 6. **Cache Responses**: Cache responses when appropriate to reduce API calls and improve performance. 7. **Monitor Usage**: Regularly check your API usage statistics to stay within rate limits. 8. **Use POST for Mutations**: Use POST requests for create, update, and delete operations. 9. **Include Timestamps**: All responses include timestamps - use them for logging and debugging. 10. **User-Specific Data**: All endpoints return only data belonging to the authenticated user. No admin or platform-wide data is accessible. ## Support For API support: - Email: api@sharepanel.host - Documentation: Full docs at /docs/index.html - Support Tickets: Submit through ticket system ## Changelog ### Version 2.0 (Current) - Added comprehensive billing endpoints - Added analytics endpoints - Added notifications management - Added API key management - Added search functionality - Added statistics endpoints - Enhanced profile management - Enhanced organization management - Enhanced instance management - Removed webhooks (no user-facing UI) - All endpoints return user-specific data only (no admin access) ### Version 1.0 - Basic authentication - Profile viewing - Organization listing and creation - Instance listing and management