Skip to content

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

Core Workflows

Advanced Topics

Integration 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:

response = requests.get(url, headers=headers)
request_id = response.headers.get('X-Request-ID')

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