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
- Server Selection
- Error Handling
- 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;
using HathoraCloud.Models.Operations;
var sdk = new HathoraCloudSDK(
security: new Security() {
HathoraDevToken = "<YOUR_BEARER_TOKEN_HERE>",
},
appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2",
orgId: "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39");
CreateAppRequest req = new CreateAppRequest() {
AppConfig = new AppConfig() {
AppName = "minecraft",
AuthConfiguration = new AuthConfiguration() {},
},
};
using(var res = await sdk.AppsV2.CreateAppAsync(req))
{
// handle response
}
Available methods
CreateAppV1Deprecated- CreateAppV1Deprecated⚠️ DeprecatedDeleteAppV1Deprecated- DeleteAppV1Deprecated⚠️ DeprecatedGetAppInfoV1Deprecated- GetAppInfoV1Deprecated⚠️ DeprecatedGetAppsV1Deprecated- GetAppsV1Deprecated⚠️ DeprecatedUpdateAppV1Deprecated- UpdateAppV1Deprecated⚠️ Deprecated
- LoginAnonymous - LoginAnonymous
- LoginGoogle - LoginGoogle
- LoginNickname - LoginNickname
GetBalance- GetBalance⚠️ Deprecated- GetInvoices - GetInvoices
- GetPaymentMethod - GetPaymentMethod
- GetUpcomingInvoiceItems - GetUpcomingInvoiceItems
- GetUpcomingInvoiceTotal - GetUpcomingInvoiceTotal
- InitStripeCustomerPortalUrl - InitStripeCustomerPortalUrl
CreateBuildDeprecated- CreateBuildDeprecated⚠️ DeprecatedDeleteBuildDeprecated- DeleteBuildDeprecated⚠️ DeprecatedGetBuildInfoDeprecated- GetBuildInfoDeprecated⚠️ DeprecatedGetBuildsDeprecated- GetBuildsDeprecated⚠️ DeprecatedRunBuildDeprecated- RunBuildDeprecated⚠️ Deprecated
CreateBuildV2Deprecated- CreateBuildV2Deprecated⚠️ DeprecatedCreateBuildWithUploadUrlV2Deprecated- CreateBuildWithUploadUrlV2Deprecated⚠️ DeprecatedCreateWithMultipartUploadsV2Deprecated- CreateWithMultipartUploadsV2Deprecated⚠️ DeprecatedDeleteBuildV2Deprecated- DeleteBuildV2Deprecated⚠️ DeprecatedGetBuildInfoV2Deprecated- GetBuildInfoV2Deprecated⚠️ DeprecatedGetBuildsV2Deprecated- GetBuildsV2Deprecated⚠️ DeprecatedRunBuildV2Deprecated- RunBuildV2Deprecated⚠️ Deprecated
- CreateBuild - CreateBuild
- DeleteBuild - DeleteBuild
- GetBuild - GetBuild
- GetBuilds - GetBuilds
- RunBuild - RunBuild
CreateDeploymentV1Deprecated- CreateDeploymentV1Deprecated⚠️ DeprecatedGetDeploymentInfoV1Deprecated- GetDeploymentInfoV1Deprecated⚠️ DeprecatedGetDeploymentsV1Deprecated- GetDeploymentsV1Deprecated⚠️ DeprecatedGetLatestDeploymentV1Deprecated- GetLatestDeploymentV1Deprecated⚠️ Deprecated
CreateDeploymentV2Deprecated- CreateDeploymentV2Deprecated⚠️ DeprecatedGetDeploymentInfoV2Deprecated- GetDeploymentInfoV2Deprecated⚠️ DeprecatedGetDeploymentsV2Deprecated- GetDeploymentsV2Deprecated⚠️ DeprecatedGetLatestDeploymentV2Deprecated- GetLatestDeploymentV2Deprecated⚠️ Deprecated
- CreateDeployment - CreateDeployment
- GetDeployment - GetDeployment
- GetDeployments - GetDeployments
- GetLatestDeployment - GetLatestDeployment
GetPingServiceEndpointsDeprecated- GetPingServiceEndpointsDeprecated⚠️ Deprecated
- GetPingServiceEndpoints - GetPingServiceEndpoints
- GetFleetMetrics - GetFleetMetrics
- GetFleetRegion - GetFleetRegion
- GetFleets - GetFleets
- UpdateFleetRegion - UpdateFleetRegion
CreatePrivateLobbyDeprecated- CreatePrivateLobbyDeprecated⚠️ DeprecatedCreatePublicLobbyDeprecated- CreatePublicLobbyDeprecated⚠️ DeprecatedListActivePublicLobbiesDeprecatedV1- ListActivePublicLobbiesDeprecatedV1⚠️ Deprecated
CreateLobbyDeprecated- CreateLobbyDeprecated⚠️ DeprecatedCreateLocalLobby- CreateLocalLobby⚠️ DeprecatedCreatePrivateLobby- CreatePrivateLobby⚠️ DeprecatedCreatePublicLobby- CreatePublicLobby⚠️ DeprecatedGetLobbyInfo- GetLobbyInfo⚠️ DeprecatedListActivePublicLobbiesDeprecatedV2- ListActivePublicLobbiesDeprecatedV2⚠️ DeprecatedSetLobbyState- SetLobbyState⚠️ Deprecated
- CreateLobby - CreateLobby
- GetLobbyInfoByRoomId - GetLobbyInfoByRoomId
- GetLobbyInfoByShortCode - GetLobbyInfoByShortCode
- ListActivePublicLobbies - ListActivePublicLobbies
- DownloadLogForProcess - DownloadLogForProcess
- GetLogsForProcess - GetLogsForProcess
- SendVerificationEmail - SendVerificationEmail
GetMetricsDeprecated- GetMetricsDeprecated⚠️ Deprecated
- AcceptInvite - AcceptInvite
- GetOrgMembers - GetOrgMembers
- GetOrgPendingInvites - GetOrgPendingInvites
- GetOrgs - GetOrgs
- GetUsageLimits - GetUsageLimits
- GetUserPendingInvites - GetUserPendingInvites
- InviteUser - InviteUser
- RejectInvite - RejectInvite
- RescindInvite - RescindInvite
- UpdateUserInvite - UpdateUserInvite
GetProcessInfoDeprecated- GetProcessInfoDeprecated⚠️ DeprecatedGetRunningProcesses- GetRunningProcesses⚠️ DeprecatedGetStoppedProcesses- GetStoppedProcesses⚠️ Deprecated
CreateProcessV2Deprecated- CreateProcessV2Deprecated⚠️ DeprecatedGetLatestProcessesV2Deprecated- GetLatestProcessesV2Deprecated⚠️ DeprecatedGetProcessInfoV2Deprecated- GetProcessInfoV2Deprecated⚠️ DeprecatedGetProcessesCountExperimentalV2Deprecated- GetProcessesCountExperimentalV2Deprecated⚠️ DeprecatedStopProcessV2Deprecated- StopProcessV2Deprecated⚠️ Deprecated
- CreateProcess - CreateProcess
- GetLatestProcesses - GetLatestProcesses
- GetProcess - GetProcess
- GetProcessMetrics - GetProcessMetrics
- GetProcessesCountExperimental - GetProcessesCountExperimental
- StopProcess - StopProcess
CreateRoomDeprecated- CreateRoomDeprecated⚠️ DeprecatedDestroyRoomDeprecated- DestroyRoomDeprecated⚠️ DeprecatedGetActiveRoomsForProcessDeprecated- GetActiveRoomsForProcessDeprecated⚠️ DeprecatedGetConnectionInfoDeprecated- GetConnectionInfoDeprecated⚠️ DeprecatedGetInactiveRoomsForProcessDeprecated- GetInactiveRoomsForProcessDeprecated⚠️ DeprecatedGetRoomInfoDeprecated- GetRoomInfoDeprecated⚠️ DeprecatedSuspendRoomDeprecated- SuspendRoomDeprecated⚠️ Deprecated
- CreateRoom - CreateRoom
- DestroyRoom - DestroyRoom
- GetActiveRoomsForProcess - GetActiveRoomsForProcess
- GetConnectionInfo - GetConnectionInfo
- GetInactiveRoomsForProcess - GetInactiveRoomsForProcess
- GetRoomInfo - GetRoomInfo
- ResumeRoom - ResumeRoom
SuspendRoomV2Deprecated- SuspendRoomV2Deprecated⚠️ Deprecated- UpdateRoomConfig - UpdateRoomConfig
- CreateOrgToken - CreateOrgToken
- GetOrgTokens - GetOrgTokens
- RevokeOrgToken - RevokeOrgToken
Certain parameters are configured globally. These parameters may be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, These global values will be used as defaults on the operations that use them. 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 CreateApp
. 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 parameters are available.
Name | Type | Description |
---|---|---|
AppId | string | The AppId parameter. |
OrgId | string | The OrgId 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",
orgId: "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39");
CreateAppRequest req = new CreateAppRequest() {
AppConfig = new AppConfig() {
AppName = "minecraft",
AuthConfiguration = new AuthConfiguration() {},
},
};
using(var res = await sdk.AppsV2.CreateAppAsync(req))
{
// handle response
}
You can override the default server globally by passing a server index to the serverIndex: int
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 | Description |
---|---|---|
0 | https://api.hathora.dev |
|
1 | / |
using HathoraCloud;
using HathoraCloud.Models.Shared;
using HathoraCloud.Models.Operations;
var sdk = new HathoraCloudSDK(
serverIndex: 1,
security: new Security() {
HathoraDevToken = "<YOUR_BEARER_TOKEN_HERE>",
},
appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2",
orgId: "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39");
CreateAppRequest req = new CreateAppRequest() {
AppConfig = new AppConfig() {
AppName = "minecraft",
AuthConfiguration = new AuthConfiguration() {},
},
};
using(var res = await sdk.AppsV2.CreateAppAsync(req))
{
// handle response
}
The default server can also be overridden globally by passing a URL to the serverUrl: string
optional parameter when initializing the SDK client instance. For example:
using HathoraCloud;
using HathoraCloud.Models.Shared;
using HathoraCloud.Models.Operations;
var sdk = new HathoraCloudSDK(
serverUrl: "https://api.hathora.dev",
security: new Security() {
HathoraDevToken = "<YOUR_BEARER_TOKEN_HERE>",
},
appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2",
orgId: "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39");
CreateAppRequest req = new CreateAppRequest() {
AppConfig = new AppConfig() {
AppName = "minecraft",
AuthConfiguration = new AuthConfiguration() {},
},
};
using(var res = await sdk.AppsV2.CreateAppAsync(req))
{
// handle response
}
Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.
By default, an API error will raise a HathoraCloud.Models.Errors.SDKException
exception, which has the following properties:
Property | Type | Description |
---|---|---|
Message |
string | The error message |
StatusCode |
int | The raw HTTP response |
RawResponse |
HttpResponseMessage | The raw HTTP response |
Body |
string | The response content |
When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the CreateAppAsync
method throws the following exceptions:
Error Type | Status Code | Content Type |
---|---|---|
HathoraCloud.Models.Errors.ApiError | 401, 404, 422, 429 | application/json |
HathoraCloud.Models.Errors.ApiError | 500 | application/json |
HathoraCloud.Models.Errors.SDKException | 4XX, 5XX | */* |
using HathoraCloud;
using HathoraCloud.Models.Shared;
using System;
using HathoraCloud.Models.Errors;
using HathoraCloud.Models.Operations;
var sdk = new HathoraCloudSDK(
security: new Security() {
HathoraDevToken = "<YOUR_BEARER_TOKEN_HERE>",
},
appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2",
orgId: "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39");
CreateAppRequest req = new CreateAppRequest() {
AppConfig = new AppConfig() {
AppName = "minecraft",
AuthConfiguration = new AuthConfiguration() {},
},
};
try
{
using(var res = await sdk.AppsV2.CreateAppAsync(req))
{
// handle response
}
}
catch (Exception ex)
{
if (ex is ApiError)
{
// handle exception
}
else 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;
using HathoraCloud.Models.Operations;
var sdk = new HathoraCloudSDK(
security: new Security() {
HathoraDevToken = "<YOUR_BEARER_TOKEN_HERE>",
},
appId: "app-af469a92-5b45-4565-b3c4-b79878de67d2",
orgId: "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39");
CreateAppRequest req = new CreateAppRequest() {
AppConfig = new AppConfig() {
AppName = "minecraft",
AuthConfiguration = new AuthConfiguration() {},
},
};
using(var res = await sdk.AppsV2.CreateAppAsync(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",
orgId: "org-6f706e83-0ec1-437a-9a46-7d4281eb2f39");
CreateLobbyRequest req = new CreateLobbyRequest() {
CreateLobbyV3Params = new CreateLobbyV3Params() {
Region = Region.Seattle,
RoomConfig = "{\"name\":\"my-room\"}",
Visibility = LobbyVisibility.Private,
},
AppId = "app-af469a92-5b45-4565-b3c4-b79878de67d2",
RoomId = "2swovpy1fnunu",
ShortCode = "LFG4",
};
using(var res = await sdk.LobbiesV3.CreateLobbyAsync(
security: new CreateLobbySecurity() {
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!