API Usage Guides¶
Version: 1.0.0 | Last Updated: 2025-01-06 | Status: Stable
Overview¶
This section contains practical guides for working with the MBPanel API. Each guide covers specific use cases with code examples and best practices.
Available Guides¶
Authentication & Security¶
- Authentication Flow - Complete guide to JWT authentication, refresh tokens, and session management
- Permissions & RBAC - Understanding roles, permissions, and access control
- API Security Best Practices - Secure API integration patterns
Core Workflows¶
- Site Management - Create, configure, and manage WordPress sites
- Environment Lifecycle - Dev, stage, and production environment workflows
- Domain Management - Add domains, configure SSL, manage DNS
- Backup & Restore - Backup scheduling and restoration procedures
Advanced Topics¶
- Webhook Integration - Setting up and handling webhooks
- Pagination & Filtering - Efficient data retrieval patterns
- Error Handling - Common errors and troubleshooting
- Rate Limiting - Understanding and handling rate limits
Integration Examples¶
- Python Integration - Code examples in Python
- JavaScript Integration - Code examples in JavaScript
- cURL Examples - Command-line examples
Quick Start Example¶
import requests
# 1. Authenticate
response = requests.post('https://api.mbpanel.io/v1/auth/login', json={
'email': 'user@example.com',
'password': 'secure_password'
})
token = response.json()['access_token']
# 2. Make authenticated requests
headers = {'Authorization': f'Bearer {token}'}
response = requests.get(
'https://api.mbpanel.io/v1/sites',
headers=headers
)
sites = response.json()['data']
print(f"Found {len(sites)} sites")
Best Practices¶
1. Error Handling¶
Always handle API errors gracefully:
response = requests.get(url, headers=headers)
if response.status_code == 401:
# Refresh token
elif response.status_code == 429:
# Handle rate limiting
retry_after = int(response.headers.get('Retry-After', 60))
time.sleep(retry_after)
elif response.status_code >= 500:
# Server error - log and retry
2. Pagination¶
Use pagination for list endpoints:
def get_all_sites():
page = 1
all_sites = []
while True:
response = requests.get(
'https://api.mbpanel.io/v1/sites',
headers=headers,
params={'page': page, 'page_size': 100}
)
data = response.json()['data']
all_sites.extend(data)
if len(data) < 100:
break
page += 1
return all_sites
3. Request ID Tracking¶
Include request IDs for support:
4. Webhook Verification¶
Always verify webhook signatures:
import hmac
import hashlib
def verify_webhook(payload, signature, secret):
expected = hmac.new(
secret.encode(),
payload,
hashlib.sha256
).hexdigest()
return hmac.compare_digest(expected, signature)
Support¶
- Documentation: API Reference
- Issues: GitHub Issues
- Email: support@mbpanel.io