Web API overview
A built-in HTTP API for player stats, matches, the server list, drain and config editing.
The web API is a small HTTP server inside the MineDuels plugin. It answers JSON. Use it from dashboards, Discord bots, deploy scripts and your own website.
What you can do with it:
- Read any player's stats, live state and match history, online or not.
- List running matches on every server, and finished matches with filters.
- Read kit and overall leaderboards.
- See every server in the network with its players, free arenas, queues and drain flag.
- Start or stop drain on this server or on any other server of the network.
- Read, edit and bulk edit config files, then reload them, in one request.
It is off by default, listens on 127.0.0.1 only, and refuses every request that has no API key.
Quick start
- Open
plugins/MineDuels/webapi.ymland setenabled: true. - Restart the server. The console prints the address:
[MineDuels] Web API listening on http://127.0.0.1:8765/v1- Create a key in the console or in game:
/md web key create dashboard readKey dashboard (read) created. Copy it now, it is not shown again:
mdk_Qm9k1s2yQeW3uYb0n8kz1V5lGq7cAa4m9H2xTt6RjLw- Call the API:
curl -H "Authorization: Bearer mdk_Qm9k1s2yQeW3uYb0n8kz1V5lGq7cAa4m9H2xTt6RjLw" \
http://127.0.0.1:8765/v1/status{
"ok": true,
"data": {
"version": "0.10.0",
"server": "lobby-1",
"crossServer": true,
"role": "lobby",
"online": 42,
"runningMatches": 7,
"draining": false,
"uptimeSeconds": 86400,
"databaseQueue": 0,
"web": { "served": 120, "refused": 3 }
}
}The address
Every endpoint lives under the base URL:
http://<host>:<port><base-path>/<endpoint>With the defaults that is http://127.0.0.1:8765/v1/<endpoint>. Change host, port and base-path in webapi.yml. Run /md web url to print the address the server uses.
| You want to call it from | Use |
|---|---|
| The same machine | http://127.0.0.1:8765/v1 (default) |
| Another machine on your network | Set host: 0.0.0.0, open the port, use http://<server-ip>:8765/v1 |
| The internet | Put HTTPS in front of it, for example https://api.example.com/v1 |
Opening http://127.0.0.1:8765/v1 in a browser without a key shows the endpoint list, so you can check that the address is right.
Response format
Every answer is JSON with an ok flag.
{ "ok": true, "data": { "...": "..." } }{ "ok": false, "error": { "code": "unauthorized", "message": "the key is not valid" } }The HTTP status carries the result too: 200 success, 4xx your request, 5xx the server. See errors.
All endpoints
All paths are relative to the base URL. The scope is the lowest key scope that may call it.
| Method and path | Scope | What it returns |
|---|---|---|
GET / | none | Endpoint list and version |
GET /status | read | This server's state |
GET /servers | read | Every server of the network |
GET /kits | read | Kit names |
GET /arenas | read | Arena template names |
GET /queues | read | Players waiting per queue |
GET /parties | read | Parties on this server |
GET /tournaments | read | The running or waiting tournament |
GET /drain | read | Drain state of this server and the network |
GET /players/{id} | read | Stats and live state of a player |
GET /players/{id}/stats | read | Stored stats of a player |
GET /players/{id}/matches | read | A player's finished matches |
GET /leaderboards/{kit} | read | Ranked leaderboard, or overall |
GET /matches/running | read | Running matches on every server |
GET /matches | read | Finished matches with filters |
GET /matches/{id} | read | One finished match |
GET /config | read | Editable config files |
GET /config/{file} | admin | A config file, secrets hidden |
POST /drain/start | write | Start drain here or on another server |
POST /drain/stop | write | Stop drain |
POST /reload | write | Reload the config files |
PUT /config/{file} | admin | Replace a config file |
PATCH /config | admin | Bulk edit config values |
Where to go next
- Setup: every
webapi.ymloption and the one-server cross-server setup. - Authentication: keys and scopes.
- Rate limits and errors: what protects the server and how to handle
429. - Examples: curl, Node.js and Python scripts.