API: Introduction
You can use the DatHost API to automate creation/deletion and control of servers if you for example want to integrate our game servers into your service. The API is a RESTful HTTP API which means that all interactions are made using regular HTTP requests, if you are logged in you can even try out the functionality in your web browser here.
To authenticate with our API use HTTP basic authentication with login email and password. You should send the basic auth header with every request. By default all actions are done against the account you authenticate to, if you are invited to another account you can add the HTTP header
Account-Email: <email> with the login email of the account which you like to do the action on.
For full API specification with all endpoints, check out our documentation
here.
NodeJS (Javascript) Example
This is a fully working NodeJS (JavaScript) program which creates a server, starts it and retrieves ip + port:
const FormData = require('form-data') const fetch = require('node-fetch') async function main() { const username = 'john@doe.com' const password = 'secretPassword' const headers = { authorization: `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`, } let body = new FormData() body.append('name', 'test') body.append('game', 'csgo') body.append('csgo_settings.rcon', 'test') body.append('csgo_settings.steam_game_server_login_token', 'B9184AB935BA3419258338383BCA3CA') let response = await fetch('https://dathost.net/api/0.1/game-servers', { method: 'POST', body, headers, }) let server = await response.json() await fetch(`https://dathost.net/api/0.1/game-servers/${server.id}/start`, { method: 'POST', headers, }) response = await fetch(`https://dathost.net/api/0.1/game-servers/${server.id}`, { headers, }) server = await response.json() console.log(`${server.ip}:${server.ports.game}`) } main()
Python example
This is a fully working Python program using the requests module which creates a server, starts it and retrieves ip + port:
import requests server = requests.post( "https://dathost.net/api/0.1/game-servers", data={ "name": "test", "game": "csgo", "csgo_settings.rcon": "test", "csgo_settings.steam_game_server_login_token": "B9184AB935BA3419258338383BCA3CA", }, auth=("john@doe.com", "secretPassword"), ).json() requests.post( "https://dathost.net/api/0.1/game-servers/%s/start" % server["id"], auth=("john@doe.com", "secretPassword"), ) server = requests.get( "https://dathost.net/api/0.1/game-servers/%s" % server["id"], auth=("john@doe.com", "secretPassword"), ).json() print("%s:%s" % (server["ip"], server["ports"]["game"]))