Knowledge Base

API Access for Developers

Want to automate your hosting management? The Enhance API lets you programmatically control websites, email, databases, and more. Time to unleash your inner developer!

What is the Enhance API?

The Enhance API follows the OpenAPI 3.0 specification, which means:

  • Well-documented endpoints
  • Standardised request/response formats
  • Easy integration with existing tools
  • Code generation for any language

Getting API Credentials

Creating API Keys

  1. Log into Enhance
  2. Navigate to Settings > API or Developer
  3. Click + Create API Key
  4. Give your key a descriptive name (e.g., "Deployment Script")
  5. Set permissions (which endpoints the key can access)
  6. Copy and securely store your API key

[SCREENSHOT: API key creation form with name and permission settings]

Security Warning: Treat API keys like passwords. Never commit them to Git, share them publicly, or include them in client-side code!

API Key Permissions

Configure what each key can do:

Permission Access Level
Read Only GET endpoints only
Read/Write GET, POST, PUT, DELETE
Full Access Everything including user management
Custom Select specific endpoints

Authentication

API Key Authentication

Include your API key in request headers:

curl -H "Authorization: Bearer YOUR_API_KEY" \
  https://api.enhance.com/v1/websites

OAuth 2.0 (If Available)

Some installations support OAuth for more secure integrations:

curl -H "Authorization: Bearer OAUTH_ACCESS_TOKEN" \
  https://api.enhance.com/v1/websites

API Endpoints Overview

Common Endpoints

Endpoint Method Description
/websites GET List all websites
/websites POST Create new website
/websites/{id} GET Get website details
/websites/{id} PUT Update website
/websites/{id} DELETE Delete website
/emails GET List email accounts
/emails POST Create email account
/databases GET List databases
/databases POST Create database
/domains GET List domains
/backups GET List backups
/backups POST Create backup

Making API Requests

Using cURL

List all websites:

curl -X GET \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  https://api.enhance.com/v1/websites

Create a new website:

curl -X POST \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"domain": "newsite.com", "php_version": "8.2"}' \
  https://api.enhance.com/v1/websites

Update a website:

curl -X PUT \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"php_version": "8.3"}' \
  https://api.enhance.com/v1/websites/123

Using PHP

<?php

$apiKey = 'YOUR_API_KEY';
$baseUrl = 'https://api.enhance.com/v1';

// List websites
$ch = curl_init();
curl_setopt_array($ch, [
    CURLOPT_URL => "$baseUrl/websites",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer $apiKey",
        "Content-Type: application/json"
    ]
]);

$response = curl_exec($ch);
$websites = json_decode($response, true);
curl_close($ch);

foreach ($websites['data'] as $site) {
    echo $site['domain'] . "\n";
}

Using Python

import requests

API_KEY = 'YOUR_API_KEY'
BASE_URL = 'https://api.enhance.com/v1'

headers = {
    'Authorization': f'Bearer {API_KEY}',
    'Content-Type': 'application/json'
}

# List websites
response = requests.get(f'{BASE_URL}/websites', headers=headers)
websites = response.json()

for site in websites['data']:
    print(site['domain'])

# Create a website
new_site = {
    'domain': 'newsite.com',
    'php_version': '8.2'
}
response = requests.post(f'{BASE_URL}/websites', headers=headers, json=new_site)
print(response.json())

Using JavaScript/Node.js

const axios = require('axios');

const API_KEY = 'YOUR_API_KEY';
const BASE_URL = 'https://api.enhance.com/v1';

const client = axios.create({
  baseURL: BASE_URL,
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  }
});

// List websites
async function listWebsites() {
  const response = await client.get('/websites');
  return response.data;
}

// Create website
async function createWebsite(domain, phpVersion = '8.2') {
  const response = await client.post('/websites', {
    domain,
    php_version: phpVersion
  });
  return response.data;
}

// Usage
listWebsites().then(sites => {
  sites.data.forEach(site => console.log(site.domain));
});

[SCREENSHOT: API response in a terminal or API client like Postman]

Response Formats

Successful Response

{
  "status": "success",
  "data": {
    "id": 123,
    "domain": "example.com",
    "php_version": "8.2",
    "status": "active",
    "created_at": "2025-01-27T10:00:00Z"
  }
}

List Response with Pagination

{
  "status": "success",
  "data": [...],
  "meta": {
    "total": 50,
    "page": 1,
    "per_page": 20,
    "total_pages": 3
  },
  "links": {
    "next": "/websites?page=2",
    "prev": null
  }
}

Error Response

{
  "status": "error",
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "The domain field is required",
    "details": {
      "domain": ["This field cannot be empty"]
    }
  }
}

Common API Operations

Website Management

Create website with full configuration:

curl -X POST \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "domain": "newsite.com",
    "php_version": "8.2",
    "webserver": "nginx",
    "document_root": "/public_html"
  }' \
  https://api.enhance.com/v1/websites

Get website details:

curl -H "Authorization: Bearer $API_KEY" \
  https://api.enhance.com/v1/websites/123

Email Management

Create email account:

curl -X POST \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "email": "hello",
    "domain": "example.com",
    "password": "SecurePassword123!",
    "quota": 1024
  }' \
  https://api.enhance.com/v1/emails

Database Management

Create database:

curl -X POST \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "myapp_production",
    "website_id": 123
  }' \
  https://api.enhance.com/v1/databases

Backup Operations

Create on-demand backup:

curl -X POST \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "website_id": 123,
    "type": "full"
  }' \
  https://api.enhance.com/v1/backups

Restore from backup:

curl -X POST \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "backup_id": 456,
    "target": "files"
  }' \
  https://api.enhance.com/v1/backups/restore

Rate Limiting

The API has rate limits to prevent abuse:

Tier Requests/Minute Requests/Hour
Standard 60 1,000
Premium 300 5,000

Handling Rate Limits

When rate limited, you'll receive:

{
  "status": "error",
  "error": {
    "code": "RATE_LIMITED",
    "message": "Too many requests",
    "retry_after": 30
  }
}

Headers will include:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1706355600
Retry-After: 30

Best Practices for Rate Limits

  1. Implement exponential backoff
  2. Cache responses where appropriate
  3. Batch operations when possible
  4. Monitor your usage

Webhooks (If Available)

Get notified when events occur:

Setting Up Webhooks

  1. Go to API > Webhooks
  2. Click + Add Webhook
  3. Enter your endpoint URL
  4. Select events to subscribe to:
    • website.created
    • website.deleted
    • backup.completed
    • ssl.renewed
  5. Save

[SCREENSHOT: Webhook configuration form]

Webhook Payload Example

{
  "event": "backup.completed",
  "timestamp": "2025-01-27T10:15:30Z",
  "data": {
    "backup_id": 789,
    "website_id": 123,
    "size": 524288000,
    "status": "success"
  }
}

Error Handling

Common Error Codes

Code Meaning Resolution
400 Bad Request Check request format
401 Unauthorized Check API key
403 Forbidden Check permissions
404 Not Found Resource doesn't exist
422 Validation Error Check input data
429 Rate Limited Slow down requests
500 Server Error Try again later

Robust Error Handling (Python Example)

import requests
import time

def api_request(method, endpoint, data=None, retries=3):
    for attempt in range(retries):
        try:
            response = requests.request(
                method,
                f'{BASE_URL}{endpoint}',
                headers=headers,
                json=data
            )

            if response.status_code == 429:
                retry_after = int(response.headers.get('Retry-After', 30))
                time.sleep(retry_after)
                continue

            response.raise_for_status()
            return response.json()

        except requests.exceptions.RequestException as e:
            if attempt == retries - 1:
                raise
            time.sleep(2 ** attempt)  # Exponential backoff

API Documentation

Accessing API Docs

  1. Visit your Enhance API documentation URL
  2. Or use the OpenAPI spec directly

OpenAPI Specification

Download the spec for code generation:

curl https://api.enhance.com/v1/openapi.json > enhance-api.json

Generate client code:

# Using OpenAPI Generator
openapi-generator generate -i enhance-api.json -g python -o ./enhance-client

Next Steps: Having issues? Check our Troubleshooting Guide.

Please rate this article to help us improve our Knowledge Base.

0 0