KVM Server API

Examples

Use the KVM Server API with curl and JavaScript.

Preparation

Create a token in the Customer Center and assign the required scopes for your server. Never publish real tokens in examples.

export K2H_API_BASE='https://api.key2host.com/api/v1'
export K2H_SERVER_ID='YOUR-SERVER-UUID'
export K2H_API_TOKEN='YOUR_API_TOKEN'

Retrieve server and IP information

curl --fail-with-body "$K2H_API_BASE/servers/$K2H_SERVER_ID" \
  -H "Authorization: Bearer $K2H_API_TOKEN"

curl --fail-with-body "$K2H_API_BASE/servers/$K2H_SERVER_ID/ips" \
  -H "Authorization: Bearer $K2H_API_TOKEN"

Rename a server

curl --fail-with-body -X PATCH "$K2H_API_BASE/servers/$K2H_SERVER_ID" \
  -H "Authorization: Bearer $K2H_API_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"kind":"name","value":"Production server"}'

Start a server

curl --fail-with-body -X POST "$K2H_API_BASE/servers/$K2H_SERVER_ID/actions" \
  -H "Authorization: Bearer $K2H_API_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"action":"start"}'

Use {"action":"stop","confirmed":true} for a normal shutdown. Reset and kill also require confirmation and may lose unsaved data.

Retrieve statistics, network, and traffic

curl --fail-with-body "$K2H_API_BASE/servers/$K2H_SERVER_ID/statistics?range=day" \
  -H "Authorization: Bearer $K2H_API_TOKEN"

curl --fail-with-body "$K2H_API_BASE/servers/$K2H_SERVER_ID/network" \
  -H "Authorization: Bearer $K2H_API_TOKEN"

curl --fail-with-body "$K2H_API_BASE/servers/$K2H_SERVER_ID/traffic" \
  -H "Authorization: Bearer $K2H_API_TOKEN"

Install an app

This operation erases all existing server data. Use a new request UUID for every operation.

curl --fail-with-body -X POST "$K2H_API_BASE/servers/$K2H_SERVER_ID/app" \
  -H "Authorization: Bearer $K2H_API_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"requestId":"6c186b6a-2f36-4c63-9f04-01ab27a63c22","appId":"nextcloud","confirmDataLoss":true}'

JavaScript on your backend

const base = process.env.K2H_API_BASE || 'https://api.key2host.com/api/v1'
const serverId = process.env.K2H_SERVER_ID
const token = process.env.K2H_API_TOKEN

const response = await fetch(`${base}/servers/${encodeURIComponent(serverId)}`, {
  headers: { Authorization: `Bearer ${token}` }
})

if (!response.ok) {
  throw new Error(`Request failed: ${response.status}`)
}

console.log(await response.json())

Run API calls on your backend so the token is never delivered to website visitors. Handle HTTP 429 with fewer requests and delayed retries.