You can control your game servers from your game client, a custom backend service, or any other application by using the PlayFlow API. We provide two primary ways to interact with the API:
  • Unity SDK: A convenient C# wrapper for developers using Unity.
  • REST API: For all other game engines and custom backends.

Game Servers REST API Reference

Explore the full REST API for endpoints, parameters, and responses.

Unity SDK Examples

The following examples use the PlayflowServerApiClient class from the SDK.

Initialization

First, you need to initialize the client with your PlayFlow API key.
using PlayFlow.SDK.Servers;

// Your API key from the PlayFlow dashboard
string playflowApiKey = "YOUR_API_KEY_HERE"; 

private PlayflowServerApiClient _apiClient;

void Start()
{
    _apiClient = new PlayflowServerApiClient(playflowApiKey);
}

Starting a Game Server

To start a new server, you provide a configuration that specifies the server’s name, region, and any custom data you want to pass to it.
private async void StartNewServer()
{
    var serverRequest = new ServerCreateRequest
    {
        name = "MyCustomServer",
        region = "us-east",
        custom_data = new Dictionary<string, object>
        {
            { "map_name", "castle_siege" }
        }
    };

    try
    {
        ServerStartResponse response = await _apiClient.StartServerAsync(serverRequest);
        Debug.Log($"Server is starting! Instance ID: {response.instance_id}");
    }
    catch (PlayFlowApiException e)
    {
        Debug.LogError($"Failed to start server: {e.Message}");
    }
}

Stopping a Game Server

To stop a running server, you just need its unique instance_id.
private async void StopServer(string instanceId)
{
    try
    {
        ServerStopResponse response = await _apiClient.StopServerAsync(instanceId);
        Debug.Log($"Server stop initiated. Status: {response.status}");
    }
    catch (PlayFlowApiException e)
    {
        Debug.LogError($"Failed to stop server: {e.Message}");
    }
}

Listing Game Servers

You can get a list of all your currently running servers. This is perfect for building a server browser.
private async void ListAllServers()
{
    try
    {
        ServerList response = await _apiClient.ListServersAsync(includeLaunching: true);
        Debug.Log($"Found {response.total_servers} total servers.");

        foreach (var server in response.servers)
        {
            Debug.Log($"- Server: {server.name}, Status: {server.status}");
        }
    }
    catch (PlayFlowApiException e)
    {
        Debug.LogError($"Failed to list servers: {e.Message}");
    }
}