Skip to content

Calling the API ​

Base URL ​

The base URL is your server address and port (30120 by default) followed by the gateway's resource name:

http://<your-server-ip>:30120/tm_api/<resource>/<path>

A resource named players that registered /online is served at /tm_api/players/online.

Authentication ​

Every request except an OPTIONS preflight needs:

Authorization: Bearer <api_key>

A missing header or a wrong token gets 401 Unauthorized.

Response format ​

Every JSON response uses the same envelope.

json
{ "success": true, "data": { } }
json
{ "success": false, "error": "message" }

An unknown route returns 404, and a handler that throws returns 500 with Internal server error (the real error is written to the server console).

Built in routes ​

MethodPathDescription
GET/tm_api/pingHealth check. Returns plain text API_OK.
GET/tm_api/Lists every registered route with method, path, description and owner.

curl ​

bash
curl -H "Authorization: Bearer your-secret-key" \
     http://localhost:30120/tm_api/players/online

curl -X POST \
     -H "Authorization: Bearer your-secret-key" \
     -H "Content-Type: application/json" \
     -d '{"reason":"AFK"}' \
     http://localhost:30120/tm_api/players/5/kick

Node.js ​

js
const BASE_URL = 'http://localhost:30120/tm_api'
const API_KEY = 'your-secret-key'

async function api(path, body) {
  const res = await fetch(`${BASE_URL}${path}`, {
    method: body ? 'POST' : 'GET',
    headers: {
      Authorization: `Bearer ${API_KEY}`,
      'Content-Type': 'application/json',
    },
    body: body ? JSON.stringify(body) : undefined,
  })
  return res.json()
}

const { data } = await api('/players/online')
await api('/players/5/kick', { reason: 'AFK' })

Python ​

python
import requests

BASE_URL = 'http://localhost:30120/tm_api'
HEADERS = {'Authorization': 'Bearer your-secret-key'}

players = requests.get(f'{BASE_URL}/players/online', headers=HEADERS).json()['data']
result = requests.post(f'{BASE_URL}/players/5/kick', json={'reason': 'AFK'}, headers=HEADERS).json()