Cloud Code Admin API
Overview
This is the API specification for the Unity Cloud Code Admin service that enables
game developers to create and edit server-side code for their games.
Rate limits
The API has rate limiting in place. The endpoints are limited to 60 requests per second and 1000 requests per thirty minutes on a per-project and per-IP basis.
The API responds with a HTTP status code if the rate limit is
exceeded.
429The API also responds with a header to use in conjunction with a client's retry logic.
The value is the number of seconds until the API accepts a request for the given project and IP.
Retry-AfterUseful links
Download OpenAPI specification:
List scripts
Get a list of the Cloud Code scripts for a project environment
Authorizations
ServiceAccount (cloud_code.scripts.list)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.scripts.list
Code samples for "List scripts":
Request example
curl -X GET \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/scripts"
Response example
{ "results": [ { "name": "string", "type": "string", "language": "JS", "published": true, "lastPublishedDate": "2022-04-05T09:12:13Z", "lastPublishedVersion": 0 } ], "links": { "next": "string" }}
Create script
Create a Cloud Code script for a project environment
Authorizations
ServiceAccount (cloud_code.scripts.create)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.scripts.create
Code samples for "Create script":
Request example
curl -X POST \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ -H "Content-Type: application/json" \ -d '{ "name": "string", "type": "string", "params": [], "code": "string", "language": "JS"}' \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/scripts"
Response example
{ "type": "string", "title": "string", "status": 0, "requestId": "6203fac6-6579-4a71-a659-e20655580408", "code": 0, "detail": "string", "instance": "string", "details": [ {} ]}
Get script
Get a Cloud Code script for a project environment
Authorizations
ServiceAccount (cloud_code.scripts.get)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.scripts.get
Code samples for "Get script":
Request example
curl -X GET \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/scripts/{scriptName}"
Response example
{ "name": "test-3", "type": "API", "language": "JS", "activeScript": { "code": "module.exports=async (cloudCode) =>{cloudCode.logger.info('this message confirms that the logging client is functional!'); return cloudCode.params.someThing;}", "params": [ { "name": "someThing", "type": "STRING", "required": true } ], "version": 2, "datePublished": "2021-07-23T16:08:35Z" }, "versions": [ { "code": "module.exports=async (cloudCode) =>{cloudCode.logger.info('this message confirms that the logging client is functional!'); return cloudCode.params.someThing;}", "params": [ { "name": "someThing", "type": "STRING", "required": true } ], "isDraft": true, "version": null, "dateUpdated": "2021-07-23T15:59:32Z" }, { "code": "module.exports=async (cloudCode) =>{cloudCode.logger.info('this message confirms that the logging client is functional!'); return cloudCode.params.someThing;}", "params": [ { "name": "someThing", "type": "STRING", "required": true } ], "isDraft": false, "version": 2, "dateUpdated": "2021-07-23T16:08:35Z", "dateCreated": "2021-07-23T16:08:35Z" }, { "code": "module.exports=async (cloudCode) =>{cloudCode.logger.info('this message confirms that the logging client is functional!'); return cloudCode.params.someThing;}", "params": [ { "name": "someThing", "type": "STRING", "required": true } ], "isDraft": false, "version": 1, "dateUpdated": "2021-07-23T15:59:58Z", "dateCreated": "2021-07-23T15:59:58Z" } ], "params": [ { "name": "someThing", "type": "STRING", "required": true } ]}
Update script
Update a Cloud Code script for a project environment
Authorizations
ServiceAccount (cloud_code.scripts.update)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.scripts.update
Code samples for "Update script":
Request example
curl -X PATCH \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ -H "Content-Type: application/json" \ -d '{ "params": [], "code": "string"}' \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/scripts/{scriptName}"
Response example
{ "$ref": "#/components/examples/GatewayUnauthorizedErrorResponse"}
Delete script
Delete a Cloud Code script for a project environment.
Authorizations
ServiceAccount (cloud_code.scripts.delete)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.scripts.delete
Code samples for "Delete script":
Request example
curl -X DELETE \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/scripts/{scriptName}"
Response example
{ "$ref": "#/components/examples/GatewayUnauthorizedErrorResponse"}
Publish script
Publish a Cloud Code script for a project environment. You can't republish the active script, or publish a script with compiliaton errors.
Authorizations
ServiceAccount (cloud_code.scripts.publish)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.scripts.publish
Code samples for "Publish script":
Request example
curl -X POST \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ -H "Content-Type: application/json" \ -d '{ "version": 0}' \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/scripts/{scriptName}/publish"
Response example
{ "version": 0, "datePublished": "2022-04-05T09:12:13Z"}
List modules
Get a list of Cloud Code modules within a project environment.
This endpoint supports token-based pagination.
UGS CLI
You an also list modules through the UGS CLI with the
list modules command.
Authorizations
ServiceAccount (cloud_code.modules.list)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.modules.list
Code samples for "List modules":
Request example
curl -X GET \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/modules"
Response example
{ "results": [ { "name": "string", "language": "CS", "tags": {}, "signedDownloadURL": "string", "dateCreated": "2022-04-05T09:12:13Z", "dateModified": "2022-04-05T09:12:13Z" } ], "links": { "next": "string" }, "nextPageToken": "string"}
Create module
Create Cloud Code module metadata and assemblies within a project
environment.
Creating, updating, or deleting a module is not instant as changes roll
out gradually. This ensures that there are never any periods of downtime
in which Cloud Code is not available to serve requests.
Size limits
- A module cannot exceed the size of 10 MB.
- The combined size of all modules in your project cannot exceed 128 MB.
- You can't have more than 20 modules across all your environments.
Exceeding the individual module size limit results in a HTTP response
with error code . Exceeding the total number or size limits
across all environments in your project result to a response with code
.
429507UGS CLI
You can also create a module through the UGS CLI with the
deploy command.
Authorizations
ServiceAccount (cloud_code.modules.create)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.modules.create
Request body for "Create module"
Media Type:
multipart/form-dataA set of user-defined tags in the form of string key-value pairs.
Use these if you need to add additional metadata related to the module.
For example, if you want to automate deployment of modules with some
synchronization mechanism, you can use user-defined tags for marking
version or ownership to avoid conflicts.
ZIP archive file containing the module assemblies packaged for the
linux-x64 runtime in ReadyToRun (R2R) format. For further detail,
see Manual packaging.
Code samples for "Create module":
Request example
curl -X POST \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ -H "Content-Type: multipart/form-data" \ -d '{"name":"string","language":"CS","tags":{},"file":"string"}' \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/modules"
Response example
{ "dateCreated": "2022-04-05T09:12:13Z"}
Get module
Get useful information about a Cloud Code module within a project
environment. This information does not include the compiled module
package last uploaded when creating or updating a module.
UGS CLI
You can also get information about a module through the UGS CLI with the
get module command.
Authorizations
ServiceAccount (cloud_code.modules.get)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.modules.get
Code samples for "Get module":
Request example
curl -X GET \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/modules/{moduleName}"
Response example
{ "name": "string", "language": "CS", "tags": {}, "signedDownloadURL": "string", "dateCreated": "2022-04-05T09:12:13Z", "dateModified": "2022-04-05T09:12:13Z", "endpoints": { "endpoint1": { "parameters": { "name": "System.String", "age": "System.Int32" }, "returnType": "System.String" }, "endpoint2": { "parameters": { "name": "System.String", "age": "System.Int32" }, "returnType": "System.String" } }, "hasError": true, "errorMessage": "string"}
Delete module
Delete a Cloud Code module within a project environment.
Creating, updating, or deleting a module is not instant as changes roll
out gradually. This ensures that there are never any periods of downtime
in which Cloud Code is not available to serve requests.
UGS CLI
You can also delete a module through the UGS CLI with the
delete module command.
Authorizations
ServiceAccount (cloud_code.modules.delete)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.modules.delete
Code samples for "Delete module":
Request example
curl -X DELETE \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/modules/{moduleName}"
Response example
{ "$ref": "#/components/examples/ModuleNameMissingErrorResponse"}
Update module
Change Cloud Code module metadata and assemblies within a project
environment.
Creating, updating, or deleting a module is not instant as changes roll
out gradually. This ensures that there are never any periods of downtime
in which Cloud Code is not available to serve requests.
Size limits
- A module cannot exceed the size of 10 MB.
- The combined size of all modules in your project cannot exceed 128 MB.
Exceeding the individual module size limit results in a HTTP response
with error code . Exceeding the total number limit across all
environments in your project result to a response with code .
429507UGS CLI
You can also update a module through the UGS CLI with the
deploy command.
Authorizations
ServiceAccount (cloud_code.modules.update)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.modules.update
Request body for "Update module"
Media Type:
multipart/form-dataA set of user-defined tags in the form of string key-value pairs.
Use these if you need to add additional metadata related to the module.
For example, if you want to automate deployment of modules with some
synchronization mechanism, you can use user-defined tags for marking
version or ownership to avoid conflicts.
ZIP archive file containing the module assemblies packaged for the
linux-x64 runtime in ReadyToRun (R2R) format. For further detail,
see Manual packaging.
Code samples for "Update module":
Request example
curl -X PATCH \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ -H "Content-Type: multipart/form-data" \ -d '{"tags":{},"file":"string"}' \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/modules/{moduleName}"
Response example
{ "dateModified": "2022-04-05T09:12:13Z"}
Get module spec
Get the OpenAPI specification for a given Cloud Code module
Authorizations
ServiceAccount (cloud_code.modules.get)
HTTP: ServiceAccount
To get started with authentication, visit the Service Account Authentication section.
HTTP Authorization Scheme: basic
Required scopes: cloud_code.modules.get
Code samples for "Get module spec":
Request example
curl -X GET \ -H "Authorization: Basic <YOUR_CREDENTIALS>" \ "https://services.api.unity.com/cloud-code/v1/projects/{projectId}/environments/{environmentId}/modules/{moduleName}/spec"
Response example
"openapi: 3.0.1\ninfo:\n title: ApiSpecExample OpenApi Specification\n version: 1.0.0\nservers:\n - url: https://cloud-code.services.api.unity.com/v1/projects/ApiSpecExample/modules/ApiSpecExample\npaths:\n /HelloWorld:\n post:\n description: HelloWorld POST\n requestBody:\n content:\n application/json:\n schema:\n type: object\n properties:\n params:\n type: object\n properties:\n name:\n type: string\n responses:\n '200':\n description: OK\n content:\n application/json:\n schema:\n properties:\n output:\n type: string\n /SendItem:\n post:\n description: SendItem POST\n requestBody:\n content:\n application/json:\n schema:\n type: object\n properties:\n params:\n type: object\n properties:\n item:\n $ref: '#/components/schemas/ApiSpecGenerationTest.Item'\n playerId:\n type: string\n responses:\n '200':\n description: OK\n content:\n application/json:\n schema:\n properties:\n output:\n type: object\n additionalProperties: false\n /GenerateLoot:\n post:\n description: GenerateLoot POST\n requestBody:\n content:\n application/json:\n schema:\n type: object\n properties:\n params:\n type: object\n properties:\n level:\n type: integer\n format: int32\n responses:\n '200':\n description: OK\n content:\n application/json:\n schema:\n properties:\n output:\n type: array\n items:\n $ref: '#/components/schemas/ApiSpecGenerationTest.Item'\ncomponents:\n schemas:\n ApiSpecGenerationTest.Item:\n properties:\n Name:\n type: string\n OwnerId:\n type: string\n Attributes:\n type: object\n additionalProperties:\n type: integer\n format: int32\n securitySchemes:\n BearerAuth:\n type: http\n scheme: bearer\nsecurity:\n - { }"