Skip to content

Repository files navigation

Enhance API

A modern, dependency-free PHP client for the Enhance control panel API.

  • Vanilla – zero runtime dependencies, only the curl and json extensions.
  • Complete – all 482 operations across 33 resources, covering the full Enhance API (v12.25.4).
  • Type-safe – typed DTOs, enums, and resource methods built on PHP 8.4 features (property hooks, readonly, backed enums).

Requirements

  • PHP 8.4 or higher
  • ext-curl, ext-json

Installation

composer require gosuccess/enhance-api

Quick start

useGoSuccess\Enhance\Enhance;
$enhance = Enhance::create(
host: 'https://cp.example.com/api',
orgId: 'your-organization-uuid',
accessToken: 'your-access-token',
);
// Read the API versionecho$enhance->install->orchdVersion();
// List the organization's plans (uses the configured organization id)$plans = $enhance->plans->getPlans();

Every API section is exposed as a resource on the Enhance object, e.g. $enhance->websites, $enhance->servers, $enhance->orgs, $enhance->plans, $enhance->subscriptions, $enhance->domains, $enhance->dns, $enhance->emails, $enhance->backups, $enhance->ssl, and so on.

Documentation & examples

  • docs/ – one reference page per resource, listing every method with its route, parameters, and a usage example.
  • examples/ – runnable scripts (account overview, error handling, a full create/read/delete lifecycle).

Working with DTOs

Request bodies are typed DTOs; only the properties you set are sent. Responses are hydrated into DTOs automatically.

useGoSuccess\Enhance\DTO\NewWebsite;
useGoSuccess\Enhance\Enum\PhpVersion;
useGoSuccess\Enhance\Enum\WebsiteKind;
$website = newNewWebsite();
$website->domain = 'example.test';
$website->phpVersion = PhpVersion::Php84;
$created = $enhance->websites->createWebsite($website, WebsiteKind::Normal);
echo$created->id; // NewResourceUuid::$id

By default, properties left as null are omitted from the request body. To clear a field via an update endpoint, mark it with setNull() so it is sent as an explicit null:

$update = newUpdateWebsite();
$update->setNull('phpVersion');
$enhance->websites->updateWebsite($update, $websiteId);

The organization id

Most endpoints are scoped to an organization. The orgId you pass to Enhance::create() is used by default, so you can omit it. Pass it explicitly to target a different organization (e.g. as an MO managing customers):

$enhance->websites->getWebsites(); // configured organization$enhance->websites->getWebsites(orgId: 'other-org-uuid'); // another organization

Pagination

Listing endpoints accept offset/limit. Paginator::items() transparently walks every page for you:

useGoSuccess\Enhance\Util\Paginator;
foreach (Paginator::items(
fn (int$offset, int$limit) => $enhance->websites->getWebsites(offset: $offset, limit: $limit),
) as$website) {
echo$website->id . "\n";
}

Configuration

Enhance::create() covers the common case. For finer control, build a Configuration and pass it to the constructor:

useGoSuccess\Enhance\Enhance;
useGoSuccess\Enhance\Client\Configuration;
$config = newConfiguration('https://cp.example.com/api', 'org-uuid', 'access-token');
$config->timeout = 60; // request timeout in seconds (default 30)$config->maxRetries = 3; // retries for transient failures (default 2)$config->verifySsl = true; // TLS verification (enabled by default)$enhance = newEnhance($config);

Error handling

Non-2xx responses throw a typed exception. All of them extend GoSuccess\Enhance\Exception\ApiException, which carries the status code and response body as context.

useGoSuccess\Enhance\Exception\ApiException;
useGoSuccess\Enhance\Exception\NotFoundException;
try {
$plan = $enhance->plans->getPlan(123);
} catch (NotFoundException$e) {
// 404
} catch (ApiException$e) {
echo$e->getMessage();
$context = $e->getContext(); // ['status' => int, 'body' => mixed]
}
StatusException
400BadRequestException
401UnauthorizedException
403ForbiddenException
404NotFoundException
409ConflictException
429RateLimitException
5xxServerException
transport errorRequestException

Redirects are never followed and are not treated as errors: the SSO endpoints document a 3xx as their success case, so the response is returned and its target can be read from Response::$location.

Custom HTTP client

The client talks to the API through GoSuccess\Enhance\Contract\HttpClientInterface. The default implementation (ApiClient) uses cURL, but you can inject your own — useful for testing or custom transports:

$enhance = newEnhance($config, $myHttpClient);

Architecture

src/
Enhance.php Entry point, one resource per API section
Client/ Configuration and the cURL ApiClient
Contract/ HttpClientInterface
Http/ Immutable Response
Resource/ 33 resources (482 methods)
DTO/ 364 hydratable data transfer objects
Enum/ 67 enums + HttpMethod/HttpStatusCode
Exception/ Typed exception hierarchy
Base/ AbstractResource, AbstractDto
Attribute/ ArrayItemType

Development

The Resource, DTO, and Enum classes were originally derived from the Enhance OpenAPI specification (v12.25.4) and are now maintained by hand.

composer cs:fix # apply coding standards
composer analyse # PHPStan
composer test# PHPUnit
composer check # all of the above

License

MIT

About

Enhance API Client

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages