Server API
Server API Lab
The Lab is a place to write a bot for the Server API and run it against a test server, with a full dashboard, before you point it at a real one. Open it from the Server API page once you are approved.
#Projects
- The Lab home lists your projects. You can have up to 20.
- New project starts from the starter bot, one of the examples (server and players, looking up a player, making a case and more), or an empty project with just the
uplink()helper. - Each project has its own code and its own test server, and both are saved to your account.
#Code, Dashboard and Docs
| View | What it shows |
|---|---|
| Code | The editor with bot.js and webhook.js, a terminal and a list of every call your code made. |
| Dashboard | A full test dashboard for the test server: players, cases, sessions and shifts. You can act on it too, like sending a mod call from a player. |
| Docs | The v1 and v2 docs, next to your code. |
#Running your code
- Press Run to run
bot.js. It runs like Node in a sandbox: usefetch,process.env.UPLINK_APIandprocess.env.UPLINK_KEY. Top-levelawaitworks. webhook.jsgets the test server's events, so you can test your webhook handler without hosting anything.- The test key can be v1 or v2. If your code makes changes with a v1 key, the Lab warns you before it runs.
- Errors are checked while you type and shown in the margin.
The uplink() helper in every project
const API = process.env.UPLINK_API;
const KEY = process.env.UPLINK_KEY;
async function uplink(path, { method = "GET", body } = {}) {
const res = await fetch(`${API}${path}`, {
method,
headers: { authorization: `Bearer ${KEY}`, "content-type": "application/json" },
body: body ? JSON.stringify(body) : undefined,
});
const data = await res.json();
if (!res.ok) throw new Error(`${res.status} ${data.error?.message ?? "Request failed"}`);
return data;
}#Calling your real server
Switch Target to My server and paste a key from the Server API page. The key stays in that tab only and is never saved. Changes your code makes are real.
#Exporting
Export downloads uplink-bot.zip: bot.js, webhook.js, a webhook server, package.json and a README. Put your real key in its environment and run it anywhere Node runs.