KyPanelDocs

Developers

Billing integration

Connect a billing system: provisioning, suspension, plan changes, usage and sign-on.

A billing system needs a handful of calls. Create an admin API token for it (Ky Admin › Development › Manage API Tokens), with the accounts and packages areas, read and change, and limit it to the billing server's IP.

The lifecycle

Billing actionAPICLI
CreatePOST /api/v1/accounts {username, domain, password, contact_email, package_id} → 202 {account, job_id}ky accounts create
SuspendPOST /api/v1/accounts/{id}/suspend {reason}ky accounts suspend
UnsuspendPOST /api/v1/accounts/{id}/unsuspendky accounts unsuspend
TerminateDELETE /api/v1/accounts/{id}?confirm=USERNAMEky accounts terminate --yes
Change packagePUT /api/v1/accounts/{id}/package {package_id}ky accounts package
Change passwordPOST /api/v1/accounts/{id}/password {new_password}ky accounts password
UsageGET /api/v1/accounts/{id} (disk, bandwidth, counts) and GET /api/v1/accounts/{id}/usageky accounts show
Sign the customer inPOST /api/v1/accounts/{id}/sso → {url}ky accounts sso
List packagesGET /api/v1/packagesky packages list

Store the account's id (returned on creation) on your side; usernames and main domains can change.

Before creating, GET /api/v1/accounts-check?username=…&domain=… tells you whether the username and domain are free, so you can suggest another name before the order goes through.

Waiting for provisioning

Creation, suspension, termination and package changes are background jobs. Either:

  • poll GET /api/v1/jobs/{job_id} until it's succeeded or failed; or
  • add a server webhook for job.completed and job.failed and match data.job_id.

Keeping in sync

Changes made by admins in the panel (a suspension, a plan change, a termination) reach your system through webhooks: account.suspended, account.unsuspended, account.package_changed, account.terminated, account.password_changed.

Errors to handle

ProblemMeaning
409 limit-reachedA reseller's account limit, or a package limit.
400 validation with fields.username / fields.domainTaken, reserved or invalid.
402 license-readonlyThe server's KyPanel license lapsed: provisioning is paused.
403 token-scope / 403 token-ipThe token can't do this, or is used from another IP.

Moving existing customers

To bring accounts from another server into KyPanel and keep billing them, use the import tools, then look the imported accounts up by username (GET /api/v1/accounts?q=USERNAME) to store their ids.