Hathora Cloud API: Welcome to the Hathora Cloud API documentation! Learn how to use the Hathora Cloud APIs to build and scale your game servers globally.
- SDK Installation
- SDK Example Usage
- Available Resources and Operations
- Global Parameters
- Error Handling
- Server Selection
- Authentication
The SDK can either be compiled using dotnet build
and the resultant .dll
file can be copied into your Unity project's Assets
folder, or you can copy the source code directly into your project.
The SDK relies on Newtonsoft's JSON.NET Package which can be installed via the Unity Package Manager.
To do so open the Package Manager via Window > Package Manager
and click the +
button then Add package from git URL...
and enter com.unity.nuget.newtonsoft-json
and click Add
.
using HathoraCloud;
using HathoraCloud.Models.Shared;
var sdk = new HathoraCloudSDK(
security: new Security() {
HathoraDevToken = "<YOUR_BEARER_TOKEN_HERE>",
},
appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2");
AppConfig req = new AppConfig() {
AppName = "minecraft",
AuthConfiguration = new AuthConfiguration() {},
};
using(var res = await sdk.AppsV1.CreateAppV1DeprecatedAsync(req))
{
// handle response
}
- CreateAppV1Deprecated - Create a new application.
- DeleteAppV1Deprecated - Delete an application using
appId
. Your organization will lose access to this application. - GetAppInfoV1Deprecated - Get details for an application using
appId
. - GetAppsV1Deprecated - Returns an unsorted list of your organization’s applications. An application is uniquely identified by an
appId
. - UpdateAppV1Deprecated - Update data for an existing application using
appId
.
- CreateApp - Create a new application.
- DeleteApp - Delete an application using
appId
. Your organization will lose access to this application. - GetApp - Get details for an application using
appId
. - GetApps - Returns an unsorted list of your organization’s applications. An application is uniquely identified by an
appId
. - UpdateApp - Update data for an existing application using
appId
.
- LoginAnonymous - Returns a unique player token for an anonymous user.
- LoginGoogle - Returns a unique player token using a Google-signed OIDC
idToken
. - LoginNickname - Returns a unique player token with a specified nickname for a user.
- GetBalance
- GetInvoices
- GetPaymentMethod
- GetUpcomingInvoiceItems
- GetUpcomingInvoiceTotal
- InitStripeCustomerPortalUrl
CreateBuildDeprecated- Creates a new build. Responds with abuildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build.⚠️ DeprecatedDeleteBuildDeprecated- Delete a build. All associated metadata is deleted.⚠️ DeprecatedGetBuildInfoDeprecated- Get details for a build.⚠️ DeprecatedGetBuildsDeprecated- Returns an array of builds for an application.⚠️ DeprecatedRunBuildDeprecated- Builds a game server artifact from a tarball you provide. Pass in thebuildId
generated fromCreateBuild()
.⚠️ Deprecated
- CreateBuildV2Deprecated - Creates a new build. Responds with a
buildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build. - CreateBuildWithUploadUrlV2Deprecated - Creates a new build with
uploadUrl
that can be used to upload the build to before callingrunBuild
. Responds with abuildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build. - CreateWithMultipartUploadsV2Deprecated - Creates a new build with optional
multipartUploadUrls
that can be used to upload larger builds in parts before callingrunBuild
. Responds with abuildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build. - DeleteBuildV2Deprecated - Delete a build. All associated metadata is deleted.
- GetBuildInfoV2Deprecated - Get details for a build.
- GetBuildsV2Deprecated - Returns an array of builds for an application.
- RunBuildV2Deprecated - Builds a game server artifact from a tarball you provide. Pass in the
buildId
generated fromCreateBuild()
.
- CreateBuild - Creates a new build with optional
multipartUploadUrls
that can be used to upload larger builds in parts before callingrunBuild
. Responds with abuildId
that you must pass toRunBuild()
to build the game server artifact. You can optionally pass in abuildTag
to associate an external version with a build. - DeleteBuild - Delete a build. All associated metadata is deleted. Be careful which builds you delete. This endpoint does not prevent you from deleting actively used builds. Deleting a build that is actively build used by an app's deployment will cause failures when creating rooms.
- GetBuild - Get details for a build.
- GetBuilds - Returns an array of builds for an application.
- RunBuild - Builds a game server artifact from a tarball you provide. Pass in the
buildId
generated fromCreateBuild()
.
CreateDeploymentV1Deprecated- Create a new deployment. Creating a new deployment means all new rooms created will use the latest deployment configuration, but existing games in progress will not be affected.⚠️ DeprecatedGetDeploymentInfoV1Deprecated- Get details for a deployment.⚠️ DeprecatedGetDeploymentsV1Deprecated- Returns an array of deployments for an application.⚠️ DeprecatedGetLatestDeploymentV1Deprecated- Get the latest deployment for an application.⚠️ Deprecated
- CreateDeploymentV2Deprecated - Create a new deployment. Creating a new deployment means all new rooms created will use the latest deployment configuration, but existing games in progress will not be affected.
- GetDeploymentInfoV2Deprecated - Get details for a deployment.
- GetDeploymentsV2Deprecated - Returns an array of deployments for an application.
- GetLatestDeploymentV2Deprecated - Get the latest deployment for an application.
- CreateDeployment - Create a new deployment. Creating a new deployment means all new rooms created will use the latest deployment configuration, but existing games in progress will not be affected.
- GetDeployment - Get details for a deployment.
- GetDeployments - Returns an array of deployments for an application.
- GetLatestDeployment - Get the latest deployment for an application.
GetPingServiceEndpointsDeprecated- Returns an array of V1 regions with a host and port that a client can directly ping. Open a websocket connection towss://<host>:<port>/ws
and send a packet. To calculate ping, measure the time it takes to get an echo packet back.⚠️ Deprecated
- GetPingServiceEndpoints - Returns an array of all regions with a host and port that a client can directly ping. Open a websocket connection to
wss://<host>:<port>/ws
and send a packet. To calculate ping, measure the time it takes to get an echo packet back.
CreatePrivateLobbyDeprecated-⚠️ DeprecatedCreatePublicLobbyDeprecated-⚠️ DeprecatedListActivePublicLobbiesDeprecatedV1-⚠️ Deprecated
CreateLobbyDeprecated- Create a new lobby for an application. A lobby object is a wrapper around a room object. With a lobby, you get additional functionality like configuring the visibility of the room, managing the state of a match, and retrieving a list of public lobbies to display to players.⚠️ DeprecatedCreateLocalLobby-⚠️ DeprecatedCreatePrivateLobby-⚠️ DeprecatedCreatePublicLobby-⚠️ DeprecatedGetLobbyInfo- Get details for a lobby.⚠️ DeprecatedListActivePublicLobbiesDeprecatedV2- Get all active lobbies for a an application. Filter by optionally passing in aregion
. Use this endpoint to display all public lobbies that a player can join in the game client.⚠️ DeprecatedSetLobbyState- Set the state of a lobby. State is intended to be set by the server and must be smaller than 1MB. Use this endpoint to store match data like live player count to enforce max number of clients or persist end-game data (i.e. winner or final scores).⚠️ Deprecated
- CreateLobby - Create a new lobby for an application. A lobby object is a wrapper around a room object. With a lobby, you get additional functionality like configuring the visibility of the room, managing the state of a match, and retrieving a list of public lobbies to display to players.
- GetLobbyInfoByRoomId - Get details for a lobby.
- GetLobbyInfoByShortCode - Get details for a lobby. If 2 or more lobbies have the same
shortCode
, then the most recently created lobby will be returned. - ListActivePublicLobbies - Get all active lobbies for a given application. Filter the array by optionally passing in a
region
. Use this endpoint to display all public lobbies that a player can join in the game client.
- DownloadLogForProcess - Download entire log file for a stopped process.
GetLogsForApp- Returns a stream of logs for an application usingappId
.⚠️ DeprecatedGetLogsForDeployment- Returns a stream of logs for a deployment usingappId
anddeploymentId
.⚠️ Deprecated- GetLogsForProcess - Returns a stream of logs for a process using
appId
andprocessId
.
- GetMetrics - Get metrics for a process using
appId
andprocessId
.
- AcceptInvite
- GetOrgMembers
- GetOrgPendingInvites
- GetOrgs - Returns an unsorted list of all organizations that you are a member of (an accepted membership invite). An organization is uniquely identified by an
orgId
. - GetUserPendingInvites
- InviteUser
- RejectInvite
- RescindInvite
GetProcessInfoDeprecated- Get details for a process.⚠️ DeprecatedGetRunningProcesses- Retrieve 10 most recently started process objects for an application. Filter the array by optionally passing in aregion
.⚠️ DeprecatedGetStoppedProcesses- Retrieve 10 most recently stopped process objects for an application. Filter the array by optionally passing in aregion
.⚠️ Deprecated
- CreateProcessV2Deprecated - Creates a process without a room. Use this to pre-allocate processes ahead of time so that subsequent room assignment via CreateRoom() can be instant.
- GetLatestProcessesV2Deprecated - Retrieve the 10 most recent processes objects for an application. Filter the array by optionally passing in a
status
orregion
. - GetProcessInfoV2Deprecated - Get details for a process.
- GetProcessesCountExperimentalV2Deprecated - Count the number of processes objects for an application. Filter by optionally passing in a
status
orregion
. - StopProcessV2Deprecated - Stops a process immediately.
- CreateProcess - Creates a process without a room. Use this to pre-allocate processes ahead of time so that subsequent room assignment via CreateRoom() can be instant.
- GetLatestProcesses - Retrieve the 10 most recent processes objects for an application. Filter the array by optionally passing in a
status
orregion
. - GetProcess - Get details for a process.
- GetProcessesCountExperimental - Count the number of processes objects for an application. Filter by optionally passing in a
status
orregion
. - StopProcess - Stops a process immediately.
CreateRoomDeprecated-⚠️ DeprecatedDestroyRoomDeprecated-⚠️ DeprecatedGetActiveRoomsForProcessDeprecated-⚠️ DeprecatedGetConnectionInfoDeprecated-⚠️ DeprecatedGetInactiveRoomsForProcessDeprecated-⚠️ DeprecatedGetRoomInfoDeprecated-⚠️ DeprecatedSuspendRoomDeprecated-⚠️ Deprecated
- CreateRoom - Create a new room for an existing application. Poll the
GetConnectionInfo()
endpoint to get connection details for an active room. - DestroyRoom - Destroy a room. All associated metadata is deleted.
- GetActiveRoomsForProcess - Get all active rooms for a given process.
- GetConnectionInfo - Poll this endpoint to get connection details to a room. Clients can call this endpoint without authentication.
- GetInactiveRoomsForProcess - Get all inactive rooms for a given process.
- GetRoomInfo - Retreive current and historical allocation data for a room.
SuspendRoomV2Deprecated- Suspend a room. The room is unallocated from the process but can be rescheduled later using the sameroomId
.⚠️ Deprecated- UpdateRoomConfig
- CreateOrgToken - Create a new organization token.
- GetOrgTokens - List all organization tokens for a given org.
- RevokeOrgToken - Revoke an organization token.
A parameter is configured globally. This parameter may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed.
For example, you can set appId
to "app-af469a92-5b45-4565-b3c4-b79878de67d2"
at SDK initialization and then you do not have to pass the same value on calls to operations like DeleteAppV1Deprecated
. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration.
The following global parameter is available.
Name | Type | Required | Description |
---|---|---|---|
appId | string | The AppId parameter. |
using HathoraCloud;
using HathoraCloud.Models.Shared;
using HathoraCloud.Models.Operations;
var sdk = new HathoraCloudSDK(
security: new Security() {
HathoraDevToken = "<YOUR_BEARER_TOKEN_HERE>",
},
appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2");
DeleteAppV1DeprecatedRequest req = new DeleteAppV1DeprecatedRequest() {};
using(var res = await sdk.AppsV1.DeleteAppV1DeprecatedAsync(req))
{
// handle response
}
You can override the default server globally by passing a server index to the serverIndex: number
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://api.hathora.dev |
None |
1 | https:/// |
None |
The default server can also be overridden globally by passing a URL to the serverUrl: str
optional parameter when initializing the SDK client instance. For example:
Handling errors in this SDK should largely match your expectations. All operations return a response object or thow an exception. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate type.
Error Object | Status Code | Content Type |
---|---|---|
HathoraCloud.Models.Errors.ApiError | 401,422,429,500 | application/json |
HathoraCloud.Models.Errors.SDKException | 4xx-5xx | / |
using HathoraCloud;
using HathoraCloud.Models.Shared;
using System;
using HathoraCloud.Models.Errors;
var sdk = new HathoraCloudSDK(
security: new Security() {
HathoraDevToken = "<YOUR_BEARER_TOKEN_HERE>",
},
appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2");
AppConfig req = new AppConfig() {
AppName = "minecraft",
AuthConfiguration = new AuthConfiguration() {},
};
try
{
using(var res = await sdk.AppsV1.CreateAppV1DeprecatedAsync(req))
{
// handle response
}
}
catch (Exception ex)
{
if (ex is ApiError)
{
// handle exception
}
else if (ex is HathoraCloud.Models.Errors.SDKException)
{
// handle exception
}
}
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
HathoraDevToken |
http | HTTP Bearer |
You can set the security parameters through the security
optional parameter when initializing the SDK client instance. For example:
using HathoraCloud;
using HathoraCloud.Models.Shared;
var sdk = new HathoraCloudSDK(
security: new Security() {
HathoraDevToken = "<YOUR_BEARER_TOKEN_HERE>",
},
appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2");
AppConfig req = new AppConfig() {
AppName = "minecraft",
AuthConfiguration = new AuthConfiguration() {},
};
using(var res = await sdk.AppsV1.CreateAppV1DeprecatedAsync(req))
{
// handle response
}
Some operations in this SDK require the security scheme to be specified at the request level. For example:
using HathoraCloud;
using HathoraCloud.Models.Operations;
using HathoraCloud.Models.Shared;
var sdk = new HathoraCloudSDK(appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2");
CreatePrivateLobbyDeprecatedRequest req = new CreatePrivateLobbyDeprecatedRequest() {};
using(var res = await sdk.LobbiesV1.CreatePrivateLobbyDeprecatedAsync(
security: new CreatePrivateLobbyDeprecatedSecurity() {
PlayerAuth = "<YOUR_BEARER_TOKEN_HERE>",
},
req))
{
// handle response
}
This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.
While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release!