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 below.

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: with the login email of the account which you like to do the action on.

If you have any questions or suggestions get in touch with [email protected]

Examples

Here are examples in JavaScript and Python on how to create a server, start it and retrieve ip+port.
The Python example requires the package requests.

const FormData = require('form-data')
const fetch = require('node-fetch')

async function main() {
  const username = '[email protected]'
  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()
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=("[email protected]", "secretPassword"),
).json()

requests.post(
    "https://dathost.net/api/0.1/game-servers/%s/start" % server["id"],
    auth=("[email protected]", "secretPassword"),
)

server = requests.get(
    "https://dathost.net/api/0.1/game-servers/%s" % server["id"],
    auth=("[email protected]", "secretPassword"),
).json()

print("%s:%s" % (server["ip"], server["ports"]["game"]))