Cloud Code
Overview
This is the API specification for the Unity Cloud Code service that enables
game developers to run custom server-side code for their games.
Limits
The combined size of the request body cannot exceed 1 MB.
POSTThe combined size of the response body cannot exceed 2 MiB.
The API has rate limiting in place. Request are limited on a per-player
basis to 600 requests per minute which would allow for a sustained 10 requests per second.
The API responds with a HTTP status code if the rate limit is
exceeded.
429It will also respond with a header to be used in conjunction with a client's retry logic.
The value is the number of seconds until a request for the given player will be accepted.
Retry-AfterModules
You can deploy a Cloud Code module with the UGS CLI by using the
deploy command, or by using the Cloud Code admin APIs. Cloud Code
modules are C# projects built either with .NET Core or .NET Framework.
A Cloud Code module can have one or more Cloud Code functions, which are
defined with the attribute . For example, the
following code represents a Cloud Code module named with a
function named . accepts a single string parameter
called .
CloudCodeFunctionHelloWorldSayHelloSayHellonamepublic class HelloWorld{ [CloudCodeFunction("SayHello")] public string SayHello(string name) { return $"Hello, {name}!"; }}
Scripts
You can create a Cloud Code script in the UGS dashboard, or by using the
Cloud Code admin APIs.
Useful Links
Download OpenAPI specification:
Run script
Run a Cloud Code script for a project.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
ServiceAccount
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: bearer
Code samples for "{title}":
Request example
curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "params": {}}' \ "https://cloud-code.services.api.unity.com/v1/projects/{projectId}/scripts/{scriptId}"
Response example
{ "output": { "playerInfo": { "playerID": "TestUser", "userName": "TestUserName", "displayName": "Name", "email": "test@test.com", "country": null, "deviceType": null, "platform": "IOS", "dateCreated": "string" } }}
Run module function
Run a Cloud Code function from a module for a project.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
ServiceAccount
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: bearer
Code samples for "{title}":
Request example
curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Content-Type: application/json" \ -d '{ "params": {}}' \ "https://cloud-code.services.api.unity.com/v1/projects/{projectId}/modules/{moduleId}/{functionId}"
Response example
{ "output": true}
Create a player subscription token
Create a subscription token for player messages.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
ServiceAccount
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: bearer
Code samples for "{title}":
Request example
curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Authorization: Bearer <YOUR_TOKEN>" \ "https://cloud-code.services.api.unity.com/v1/projects/{projectId}/subscriptions/tokens/player"
Response example
{ "channel": "$cloud-code!!!player-YL9Ia3mKqq0s620EsWhcc3PW2U3D!!!fc1099a0-a0af-44fe-9c0c-b4b068a090cc!!!b90c4336-189e-494f-82e6-ca4c774cbaec", "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImNsb3VkLWNvZGU6YWY2ZjlmMzItMGEwMy00MjM5LWI4MTQtOWZhZGZmYmU1NjA5IiwidHlwIjoiSldUIn0.eyJlbnZpcm9ubWVudE..."}
Create a project subscription token
Create a subscription token for project messages.
Authorizations
Client
HTTP: Client
HTTP Authorization Scheme: bearer
ServiceAccount
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: bearer
Code samples for "{title}":
Request example
curl -X POST \ -H "Authorization: Bearer <YOUR_TOKEN>" \ -H "Authorization: Bearer <YOUR_TOKEN>" \ "https://cloud-code.services.api.unity.com/v1/projects/{projectId}/subscriptions/tokens/project"
Response example
{ "channel": "$cloud-code!!!project!!!fc1099a0-a0af-44fe-9c0c-b4b068a090cc!!!b90c4336-189e-494f-82e6-ca4c774cbaec", "token": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImNsb3VkLWNvZGU6YWY2ZjlmMzItMGEwMy00MjM5LWI4MTQtOWZhZGZmYmU1NjA5IiwidHlwIjoiSldUIn0.eyJlbnZpcm9ubWVudE..."}