Create a server and a site
Order a server with WordPress on it and wait until it's ready.
2 min read Updated
Order a server with WordPress on it from your own code, wait until the site is live, and get the administrator's sign-in.
What you need
-
A token with
servers:read(View servers),servers:create(Create servers),sites:read(View sites) andsites:files(Files and logins). - An account that has agreed to card charges once, in the panel's Billing: a server is paid like one ordered in the panel, from the wallet first, then the default card (see Paying through the API).
1. Choose a plan that's in stock
List the cloud's plans in your region, with their prices and sizes, and what's in stock: a plan can be sold out in a region for a while. Neither needs a scope.
curl "https://api.rabbitflare.com/v1/clouds/digitalocean/plans?region=fra1" \
-H "Authorization: Bearer $RABBITFLARE_TOKEN" const res = await fetch("https://api.rabbitflare.com/v1/clouds/digitalocean/plans?region=fra1", {
headers: {
Authorization: `Bearer ${process.env.RABBITFLARE_TOKEN}`,
},
});
if (!res.ok) throw new Error(`Rabbitflare API error ${res.status}: ${await res.text()}`);
const { data, pagination } = await res.json();
console.log(data, pagination.nextCursor); import { Rabbitflare } from "@rabbitflare/api";
const rf = new Rabbitflare({ token: process.env.RABBITFLARE_TOKEN });
for await (const item of rf.catalog.plans.list({ cloud: "digitalocean", region: "fra1" })) {
console.log(item);
} <?php
$ch = curl_init('https://api.rabbitflare.com/v1/clouds/digitalocean/plans?region=fra1');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RABBITFLARE_TOKEN'),
],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($body === false || $status >= 400) {
throw new RuntimeException("Rabbitflare API error $status: $body");
}
$answer = json_decode($body, true);
print_r($answer['data']);
echo $answer['pagination']['nextCursor'] ?? 'Last page', PHP_EOL; import os
import requests
response = requests.get(
"https://api.rabbitflare.com/v1/clouds/digitalocean/plans",
headers={
"Authorization": "Bearer " + os.environ["RABBITFLARE_TOKEN"],
},
params={
"region": "fra1",
},
timeout=120,
)
response.raise_for_status()
answer = response.json()
print(answer["data"], answer["pagination"]["nextCursor"]) curl "https://api.rabbitflare.com/v1/clouds/digitalocean/availability" \
-H "Authorization: Bearer $RABBITFLARE_TOKEN" const res = await fetch("https://api.rabbitflare.com/v1/clouds/digitalocean/availability", {
headers: {
Authorization: `Bearer ${process.env.RABBITFLARE_TOKEN}`,
},
});
if (!res.ok) throw new Error(`Rabbitflare API error ${res.status}: ${await res.text()}`);
const { data } = await res.json();
console.log(data); import { Rabbitflare } from "@rabbitflare/api";
const rf = new Rabbitflare({ token: process.env.RABBITFLARE_TOKEN });
const data = await rf.catalog.availability.get({ cloud: "digitalocean" });
console.log(data); <?php
$ch = curl_init('https://api.rabbitflare.com/v1/clouds/digitalocean/availability');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RABBITFLARE_TOKEN'),
],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($body === false || $status >= 400) {
throw new RuntimeException("Rabbitflare API error $status: $body");
}
print_r(json_decode($body, true)['data']); import os
import requests
response = requests.get(
"https://api.rabbitflare.com/v1/clouds/digitalocean/availability",
headers={
"Authorization": "Bearer " + os.environ["RABBITFLARE_TOKEN"],
},
timeout=120,
)
response.raise_for_status()
print(response.json()["data"]) 2. Order the server, with its site
POST /v1/servers with the plan, and a first site in site: WordPress is installed on the server as soon
as it's ready. Like every order, it needs an Idempotency-Key: sent again with the same key (after a timeout, say), the order is still placed
once.
# Keep this key when you send the same request again (after a timeout, say), so it's only done once.
KEY=$(uuidgen)
curl -X POST "https://api.rabbitflare.com/v1/servers" \
-H "Authorization: Bearer $RABBITFLARE_TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $KEY" \
-d '{
"name": "Production",
"cloud": "digitalocean",
"region": "fra1",
"planId": "business",
"site": {
"name": "Shop",
"siteTitle": "Example Shop",
"adminUsername": "editor",
"adminEmail": "[email protected]"
}
}' import { randomUUID } from "node:crypto";
// Keep this key when you send the same request again (after a timeout, say), so it's only done once.
const idempotencyKey = randomUUID();
const res = await fetch("https://api.rabbitflare.com/v1/servers", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.RABBITFLARE_TOKEN}`,
"Content-Type": "application/json",
"Idempotency-Key": idempotencyKey,
},
body: JSON.stringify({
"name": "Production",
"cloud": "digitalocean",
"region": "fra1",
"planId": "business",
"site": {
"name": "Shop",
"siteTitle": "Example Shop",
"adminUsername": "editor",
"adminEmail": "[email protected]"
}
}),
});
if (!res.ok) throw new Error(`Rabbitflare API error ${res.status}: ${await res.text()}`);
const { data } = await res.json();
console.log(data); import { Rabbitflare } from "@rabbitflare/api";
const rf = new Rabbitflare({ token: process.env.RABBITFLARE_TOKEN });
// The SDK sends an Idempotency-Key and keeps it when it sends the request again, so it's only done once.
const data = await rf.servers.create({
name: "Production",
cloud: "digitalocean",
region: "fra1",
planId: "business",
site: {
name: "Shop",
siteTitle: "Example Shop",
adminUsername: "editor",
adminEmail: "[email protected]",
},
});
console.log(data); <?php
// Keep this key when you send the same request again (after a timeout, say), so it's only done once.
$idempotencyKey = bin2hex(random_bytes(16));
$ch = curl_init('https://api.rabbitflare.com/v1/servers');
curl_setopt_array($ch, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RABBITFLARE_TOKEN'),
'Content-Type: application/json',
'Idempotency-Key: ' . $idempotencyKey,
],
CURLOPT_POSTFIELDS => json_encode([
'name' => 'Production',
'cloud' => 'digitalocean',
'region' => 'fra1',
'planId' => 'business',
'site' => [
'name' => 'Shop',
'siteTitle' => 'Example Shop',
'adminUsername' => 'editor',
'adminEmail' => '[email protected]',
],
]),
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($body === false || $status >= 400) {
throw new RuntimeException("Rabbitflare API error $status: $body");
}
print_r(json_decode($body, true)['data']); import os
import uuid
import requests
# Keep this key when you send the same request again (after a timeout, say), so it's only done once.
idempotency_key = str(uuid.uuid4())
response = requests.post(
"https://api.rabbitflare.com/v1/servers",
headers={
"Authorization": "Bearer " + os.environ["RABBITFLARE_TOKEN"],
"Idempotency-Key": idempotency_key,
},
json={
"name": "Production",
"cloud": "digitalocean",
"region": "fra1",
"planId": "business",
"site": {
"name": "Shop",
"siteTitle": "Example Shop",
"adminUsername": "editor",
"adminEmail": "[email protected]",
},
},
timeout=120,
)
response.raise_for_status()
print(response.json()["data"])
The answer comes at once, with the server's status provisioning. It's usually ready in about 5 minutes: poll GET /servers/{serverId} every 10 seconds until status is active.
3. Wait for the server, then the site
Read the server until its status is active. The site is listed on the server from the start
(GET /v1/servers/{serverId}/sites), as queued: read it the
same way until it's active.
curl "https://api.rabbitflare.com/v1/sites/8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d" \
-H "Authorization: Bearer $RABBITFLARE_TOKEN" // Read the site every 10 seconds until it's live, for up to 10 minutes.
async function waitForSite(siteId) {
const deadline = Date.now() + 10 * 60_000;
while (Date.now() < deadline) {
const res = await fetch(`https://api.rabbitflare.com/v1/sites/${siteId}`, {
headers: { Authorization: `Bearer ${process.env.RABBITFLARE_TOKEN}` },
});
if (!res.ok) throw new Error(`Rabbitflare API error ${res.status}: ${await res.text()}`);
const { data: site } = await res.json();
if (site.status === "active") return site;
if (site.status === "failed") throw new Error(`The install failed: ${site.lastError}`);
await new Promise((resolve) => setTimeout(resolve, 10_000));
}
throw new Error("The site isn't live after 10 minutes");
}
const site = await waitForSite("8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d");
console.log(`${site.url} is live`); // Read the site every 10 seconds until it's live, for up to 10 minutes.
import { Rabbitflare } from "@rabbitflare/api";
const rf = new Rabbitflare({ token: process.env.RABBITFLARE_TOKEN });
const siteId = "8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d";
// It throws a RabbitflareWaitError if the install failed (its lastError says why), or the time ran out.
// Each read is given the wait's signal and the time left, so the wait's limit holds for it too.
const site = await rf.waitFor((options) => rf.sites.get({ siteId }, options), {
until: (s) => s.status === "active",
intervalMs: 10_000,
timeoutMs: 10 * 60_000,
});
console.log(`${site.url} is live`); <?php
// Read the site every 10 seconds until it's live, for up to 10 minutes.
function waitForSite(string $siteId): array
{
$deadline = time() + 10 * 60;
while (time() < $deadline) {
$ch = curl_init('https://api.rabbitflare.com/v1/sites/' . $siteId);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('RABBITFLARE_TOKEN')],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($body === false || $status >= 400) {
throw new RuntimeException("Rabbitflare API error $status: $body");
}
$site = json_decode($body, true)['data'];
if ($site['status'] === 'active') {
return $site;
}
if ($site['status'] === 'failed') {
throw new RuntimeException('The install failed: ' . $site['lastError']);
}
sleep(10);
}
throw new RuntimeException("The site isn't live after 10 minutes");
}
$site = waitForSite('8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d');
echo $site['url'], ' is live', PHP_EOL; import os
import time
import requests
def wait_for_site(site_id):
"""Read the site every 10 seconds until it's live, for up to 10 minutes."""
deadline = time.monotonic() + 10 * 60
while time.monotonic() < deadline:
response = requests.get(
f"https://api.rabbitflare.com/v1/sites/{site_id}",
headers={"Authorization": "Bearer " + os.environ["RABBITFLARE_TOKEN"]},
timeout=120,
)
response.raise_for_status()
site = response.json()["data"]
if site["status"] == "active":
return site
if site["status"] == "failed":
raise RuntimeError("The install failed: " + str(site["lastError"]))
time.sleep(10)
raise TimeoutError("The site isn't live after 10 minutes")
site = wait_for_site("8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d")
print(site["url"], "is live")
Or let webhooks tell you: server.ready and site.ready are sent when each is ready.
4. Sign in to WordPress
The WordPress administrator made with the site, with its password. It's a secret: show it to whoever asked, and don't log or store it (see the security checklist).
curl "https://api.rabbitflare.com/v1/sites/8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d/wordpress-login" \
-H "Authorization: Bearer $RABBITFLARE_TOKEN" const res = await fetch("https://api.rabbitflare.com/v1/sites/8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d/wordpress-login", {
headers: {
Authorization: `Bearer ${process.env.RABBITFLARE_TOKEN}`,
},
});
if (!res.ok) throw new Error(`Rabbitflare API error ${res.status}: ${await res.text()}`);
const { data } = await res.json();
console.log(data); import { Rabbitflare } from "@rabbitflare/api";
const rf = new Rabbitflare({ token: process.env.RABBITFLARE_TOKEN });
const data = await rf.sites.wordpressLogin.get({ siteId: "8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d" });
console.log(data); <?php
$ch = curl_init('https://api.rabbitflare.com/v1/sites/8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d/wordpress-login');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 120,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RABBITFLARE_TOKEN'),
],
]);
$body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
if ($body === false || $status >= 400) {
throw new RuntimeException("Rabbitflare API error $status: $body");
}
print_r(json_decode($body, true)['data']); import os
import requests
response = requests.get(
"https://api.rabbitflare.com/v1/sites/8a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d/wordpress-login",
headers={
"Authorization": "Bearer " + os.environ["RABBITFLARE_TOKEN"],
},
timeout=120,
)
response.raise_for_status()
print(response.json()["data"]) What can go wrong
| Code | Status | What it means | What to do |
|---|---|---|---|
plan_unavailable | 403, 409, 422 | The plan can't be had there: it isn't offered on this cloud or in this region, it's sold out there right now, or it isn't open to your account yet. | Choose another plan or region. GET /v1/clouds/{cloud}/availability says what's in stock. |
charges_not_authorized | 403 | The account hasn't agreed to card charges yet. | In the panel, open Billing and accept the terms once. Then try again. |
payment_method_required | 402 | There's no money in the wallet and no saved card to pay with. | Add funds to the wallet or save a card in the panel. |
card_declined | 402 | The card was declined. message gives the bank's reason. Nothing was created. | Use another card, or add funds to the wallet. |
payment_action_required | 402 | The bank wants the customer to confirm this payment, which can't happen through the API. Nothing was created. | Add funds to the wallet in the panel (wallet payments need no confirmation), or make this purchase in the panel. |
limit_reached | 403, 409 | A limit is reached: message says which (servers per account, snapshots per server, domains per site, …). | Delete something first, or contact support to raise the limit. |
After the first answer, a failure is a status: a server whose setup failed is failed, with the reason in lastError, and can be
set up again; a site whose install failed can be installed again. A refusal is kept with its
Idempotency-Key: once you've fixed the cause, order with a new key.
The whole script
All four steps in JavaScript (Node.js 18 or later; save it as an .mjs file). It takes the cheapest plan in stock, and waits up to 20
minutes for the server and 10 for the site.
// Orders a server with a WordPress site on it, waits until the site is live, and prints where to sign in.
import { randomUUID } from "node:crypto";
const API = "https://api.rabbitflare.com/v1";
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// Sends a request and gives back its data. Over a rate limit (429) it waits as long as Retry-After says, then sends
// the same request again; any other error is thrown with the API's code.
async function rabbitflare(method, path, body, headers = {}) {
for (;;) {
const res = await fetch(API + path, {
method,
headers: {
Authorization: `Bearer ${process.env.RABBITFLARE_TOKEN}`,
...(body ? { "Content-Type": "application/json" } : {}),
...headers,
},
body: body ? JSON.stringify(body) : undefined,
});
if (res.status === 429) {
await sleep((Number(res.headers.get("Retry-After")) || 1) * 1000);
continue;
}
const answer = res.status === 204 ? null : await res.json().catch(() => null);
if (!res.ok) throw Object.assign(new Error(answer?.error?.message ?? `HTTP ${res.status}`), { code: answer?.error?.code });
return answer?.data ?? null;
}
}
// Reads a server or a site every 10 seconds until it's active, for up to `minutes`.
async function waitUntilActive(path, minutes) {
const deadline = Date.now() + minutes * 60_000;
for (;;) {
const thing = await rabbitflare("GET", path);
if (thing.status === "active") return thing;
if (thing.status === "failed") throw new Error(`${thing.name} failed: ${thing.lastError}`);
if (Date.now() > deadline) throw new Error(`${thing.name} isn't ready after ${minutes} minutes`);
await sleep(10_000);
}
}
const CLOUD = "digitalocean";
const REGION = "fra1";
// 1. The cheapest plan in stock in the region.
const plans = await rabbitflare("GET", `/clouds/${CLOUD}/plans?region=${REGION}`);
const { regions } = await rabbitflare("GET", `/clouds/${CLOUD}/availability`);
const plan = plans
.filter((p) => regions[REGION]?.includes(p.id))
.sort((a, b) => a.priceMonthlyCents - b.priceMonthlyCents)[0];
if (!plan) throw new Error(`No plan is in stock in ${REGION} right now: choose another region`);
// 2. The server, with its first site, installed as soon as the server is ready. Sent again with the same
// Idempotency-Key (after a timeout, say), the order is still placed only once.
const idempotencyKey = randomUUID();
const server = await rabbitflare(
"POST",
"/servers",
{
name: "Production",
cloud: CLOUD,
region: REGION,
planId: plan.id,
site: { name: "Shop", siteTitle: "Example Shop", adminUsername: "editor", adminEmail: "[email protected]" },
},
{ "Idempotency-Key": idempotencyKey },
);
console.log(`Ordered ${server.name} on the ${plan.name} plan`);
// 3. Wait for the server (about 5 minutes), then for its site (1 to 2 minutes more).
await waitUntilActive(`/servers/${server.id}`, 20);
const [first] = await rabbitflare("GET", `/servers/${server.id}/sites`);
const site = await waitUntilActive(`/sites/${first.id}`, 10);
// 4. The WordPress administrator, to sign in with. Show the password to whoever asked; don't log it.
const login = await rabbitflare("GET", `/sites/${site.id}/wordpress-login`);
console.log(`${site.url} is live. Sign in at ${site.adminUrl} as ${login.username}, with the password ${login.password}`); Still have a question?
Our team answers support tickets about the API, and other developers answer in the community.