API clients (SDKs)

Ready-made clients for the ScalPanel API in Python, PHP and TypeScript, generated from the API contract.

ScalPanel has clients for its API in three languages. They are generated from the API contract, so they cover every endpoint and change together with it. Each endpoint is one method named after its operation, for example listSites or list_sites. You pass the path parameters first, then the JSON body, then the query parameters.

LanguageDownloadNeeds
Pythonscalpanel-python.zipPython 3.9 or newer; nothing else
PHPscalpanel-php.zipPHP 8.1 or newer with curl and json
TypeScript / JavaScriptscalpanel-typescript.zipNode 18 or newer, or any runtime with fetch

Create an API token first: see Authentication. Give it only the scopes your script needs.

Note: Use the admin panel address (port 2087) for provider and reseller work and the hosting panel address (port 2083) for a customer's own account. A token works on both; what it may do depends on its owner and scopes.

Python

Unzip the archive and install it with pip install ./scalpanel-python, or copy the scalpanel folder into your project.

from scalpanel import Client, ScalPanelError

api = Client("https://panel.example.com:2083", token="spt_...")
me = api.get_session()
for site in api.list_sites(me["tenant"]["id"])["items"]:
    print(site["name"], site["status"])

try:
    api.get_site("site_does_not_exist")
except ScalPanelError as e:
    print(e.status, e.code, e.request_id)  # 404 NOT_FOUND ...

PHP

Unzip the archive and add it to Composer as a path repository, or require the file directly.

<?php
require 'scalpanel-php/src/Client.php';

$api = new ScalPanel\Client('https://panel.example.com:2087', getenv('SCALPANEL_TOKEN'));
$accounts = $api->listTenantChildren($providerId, ['kind' => 'account', 'limit' => 100]);

try {
    $api->getSite('site_does_not_exist');
} catch (ScalPanel\ApiException $e) {
    echo $e->status, ' ', $e->errorCode, ' ', $e->requestId, "\n";
}

TypeScript

Unzip the archive, build it with npm run build (TypeScript), or import src/index.ts from a bundler. Request bodies, query parameters and answers are typed from the contract.

import { ScalPanelClient, ScalPanelError } from "./scalpanel-typescript/src/index.js";

const api = new ScalPanelClient({ baseUrl: "https://panel.example.com:2083", token: process.env.SCALPANEL_TOKEN! });
const me = await api.getSession();
const { items } = await api.listSites(me.tenant.id);

Behaviour

  • JSON answers are returned decoded. Downloads such as backups come back as bytes (Python), a string (PHP) or an ArrayBuffer (TypeScript). 204 No Content returns nothing.
  • Errors are raised with the HTTP status, the problem code, its detail, the request_id and the violations. Use the code in your scripts.
  • Path parameters are URL-encoded; an empty value, . or .. is refused before anything is sent.
  • The clients do not follow redirects and send the token only to the address you gave them.

Safe retries

idempotent(key) returns a copy of the client whose POST requests carry an Idempotency-Key. If the call times out, call it again on the same copy: the panel creates the thing once and answers the retry with the first response.

order = api.idempotent("order-1042-create")
site = order.create_site(account_id, {"name": "shop"})  # safe to repeat after a timeout

In PHP it is $api->idempotent('order-1042-create'), in TypeScript api.idempotent("order-1042-create").