Documentation

REST API and command line

4 min read Updated From the StackRegent manual

The REST API offers every action of the panel. Scripts and billing systems call it over HTTPS with an API key. On the server itself, stackregent.exe can call the same API and has commands for recovery and maintenance.

Create an API key#

  1. Go to Tools & Settings › Remote API (REST) (under Server Management).
  2. Click Create key.
  3. Enter a Name, for example billing system.
  4. Under Allowed from, you can enter IP addresses or networks, separated by commas, for example 203.0.113.10, 198.51.100.0/24. Empty means anywhere. IP Access Restriction Management still applies.
  5. Under Expires, enter after how many days the key stops working. 0 means never.
  6. Click Create. The key starts with sr_ and is shown once. Copy it now.

The API keys list shows each key's name, the start of the key, Acts as, Allowed from, Last used and Expires. Click the bin icon to delete a key. Scripts that use it stop working at once.

What a key may do#

KeyCreated underRights
AdministratorTools & Settings › Remote API (REST)The same as the administrator who created it. If that administrator is restricted, restricted mode applies to the key too.
ResellerAccount › API Keys in the reseller's panelThe same as the reseller's login. Needs the reseller plan permission Use the REST API.
CustomerAccount › API Keys in the customer's panelThe same as the customer's login. Needs the plan permission Ability to use the REST API on one of their subscriptions.

Only the account owner sees the API Keys tab. Customer and reseller keys cannot log in as other accounts, change passwords or manage API keys.

Call the API#

Send the key in the Authorization header as a bearer token, or in an X-API-Key header. Requests and answers are JSON.

curl -H "Authorization: Bearer sr_..." https://panel.example.com:9443/api/subscriptions

curl -X POST -H "Authorization: Bearer sr_..." -H "Content-Type: application/json" \
     -d '{"status":"suspended"}' https://panel.example.com:9443/api/subscriptions/12/status

The Examples card on the Remote API page shows these calls with your server's address filled in.

OpenAPI description#

Click OpenAPI description on the Remote API page, or request /api/openapi.json. The request needs a logged-in session or an API key. The file is an OpenAPI 3 description of every endpoint, with its parameters. Load it into an OpenAPI tool to browse the endpoints or generate a client. The panel has no built-in API playground; use curl, your OpenAPI tool, or stackregent api on the server.

Errors come back with an HTTP status of 400 or above and a JSON body with an error message. For form-style calls, the body may also list the fields that failed.

The stackregent command#

stackregent.exe is in the bin folder of the installation, normally C:\Program Files\StackRegent\bin. Run it in an administrator command prompt or PowerShell on the server.

Everyday and recovery commands#

CommandWhat it does
stackregent versionPrints the version.
stackregent api GET /api/subscriptionsCalls the REST API as the main administrator. The method is GET, POST, PUT or DELETE. For POST and PUT, add a JSON body, or @file.json to read it from a file. For each call, a key is made that lasts one minute and works only from the server itself; it is removed after the call.
stackregent admin-passwordSets a new random password for admin and prints it. Use -login NAME for another administrator. It also turns off two-factor authentication and closes that administrator's sessions.
stackregent admin-add LOGINAdds a support administrator and prints its password once.
stackregent admin-remove LOGINRemoves an administrator. You cannot remove the main administrator.
stackregent sessions-purgeLogs out everyone who is logged in to the panel.
stackregent ip-access-resetLets administrators log in from any address again, after an IP access restriction locks you out.
stackregent firewall-resetTurns off Panic Mode and access limits, and disables your own firewall rules.
stackregent panel-url-resetClears Customize Panel URL, so the panel answers on every host name again.
stackregent panel-port HTTPS [HTTP]Moves the panel to other ports (1024–65535). It checks that the ports are free, updates the firewall rules and restarts the panel.
stackregent license-set KEYSets the licence key. You can also put the key in STACKREGENT_LICENSE_KEY and leave the argument out.
stackregent license-checkChecks the licence now and prints its state.
stackregent website-apply DOMAINApplies one website's hosting settings again and prints the task log.
stackregent run-task KIND [JSON]Queues a panel task, waits for it and prints its log. JSON parameters can also come from @file.
stackregent site-run ID PROGRAM [ARGS]Runs a program as a website's subscription user. ID is the domain's ID. It prints the output.
stackregent dkim-verify FILE [DNS-SERVER]Checks the DKIM signatures of a saved message.

Migration agent#

stackregent migration-agent --allow NEW-SERVER-IP runs on a Plesk for Windows server so that a StackRegent server can migrate from it. Other options are --port (default 9445) and --key, which keeps a fixed key. See Migration.

Commands used by the installer and services#

The installer and the Windows services use setup, migrate (updates the panel database schema), service-install, service-remove, service-restart NAME, web, task and guard. You normally do not run these yourself. To upgrade, re-run the installer instead.

Troubleshooting#

  • 401 "invalid API key": the key is wrong, has expired, or is used from an address outside Allowed from.
  • A customer cannot create keys: none of their subscriptions' plans has Ability to use the REST API.
  • stackregent api fails to connect: check that the StackRegent service is running (see Monitoring and troubleshooting).
Was this article helpful?

Something missing? Ask in the community or open a ticket.