Skip to Content
Reference

API keys and the REST API

Create an API key, choose what it may do, and make the first request to /api/v1 with curl.

By the end of this page you will have an API key and the first answer from the site's REST API. A key is for a bot, a script or your own service that reads and changes site data. A game server does not use a key; it connects with a GameLink token, see connecting a server.

Only the site owner creates keys (the admin.boss permission).

Create a key

Open the keys page

Open AdminDeveloperAPI access and click "Create API key". The "Developer" section of the sidebar is collapsed by default.

The Create API key window with the access choice

Name the key and choose its access

In "Name", write who will use the key, for example "Discord bot". Key names are unique.

In "What the key may do", choose "Read only", "Full access" or "Custom". "Full access" lets the key change everything you can change. "Custom" opens a table of resources where each one gets "No access", "Read" or "Read + write". You cannot give a key more than you have yourself: such rows are not in the table.

Copy the key

Click "Create API key". A "Copy the API key now" card appears with the key and a copy button. The key is shown once; the site stores only its hash.

The key is lost

You cannot view it again. Click "Regenerate" on the key: you get a new one, and the old one stops working at once.

First request

The key goes in the Authorization header after the word Bearer. There is no other way to pass it. A request to the API root works with any active key and shows what that key can reach:

curl -H "Authorization: Bearer <KEY>" https://<YOUR_DOMAIN>/api/v1
{"data":{"version":"v1","granted_scopes":["servers:read"],"config_namespaces":[],"resources":["servers"]},"meta":{},"errors":[]}

The server list needs servers:read. curl reads the square brackets in filter[...] as a glob, so add the -g flag:

curl -g -H "Authorization: Bearer <KEY>" "https://<YOUR_DOMAIN>/api/v1/servers?per_page=10&sort=name&filter[enabled]=1"
{"data":[{"id":1,"name":"Public #1","ip":"203.0.113.10","port":27015,"mod":"730","display_ip":null,"panel_connection_id":null,"panel_identifier":null,"ranks":"default","ranks_premier":false,"ranks_format":"webp","proxies":null,"enabled":true}],"meta":{"page":1,"per_page":10,"total":1},"errors":[]}

The server's RCON password never appears in a response.

401 invalid_token

The key is unknown, disabled or regenerated. Check that you copied all of it and that the key shows "Key is active" in the admin panel.

403 insufficient_scope

The key lacks a scope, and the response names it: This key is missing the required scope 'servers:read'. Open the key in the admin panel and give it access to that resource.

Key scopes

A scope is written as <resource>:read or <resource>:write. Write includes read. The core resources:

ResourceWhat it holdsWrite
usersusersyes
rolesrolesyes
serversgame serversyes
playersplayersno
currenciescurrenciesyes
payment-gatewayspayment providersyes
promocodespromo codesyes
pagespagesyes
navbar-items, footer-itemsmenu and footeryes
redirectsredirectsyes
notification-templatesnotification templatesyes
modulesmodulesno

Writing to a core resource means a PATCH of an existing record only. The core does not let the API create or delete records.

Site settings are split into the groups config.app, config.assets, config.auth, config.lang, config.lk, config.mail, config.profile and config.search. Some fields are marked sensitive: to change them, a key also needs config.sensitive:write. In the key table it is called "Security settings (debug, CSRF, 2FA, payment checks)", and "Full access" does not include it.

Modules add their own resources, and their scopes show up in the key table by themselves.

Reference

Next

On this page