HTTP APIs

You can use the raw HTTP APIs to manage Cloud Code modules.

Using the API

  • The Admin API documentation contains a detailed description of admin operations, such as creating, reading, updating, and deleting modules.
  • The Client API documentation contains a detailed description of client-facing operations, such as running a module.

Both API documents include information on authentication, endpoints, and request and response formats, along with examples. You can download them in OpenAPI format and use them to set up your own automation.

To use the Admin API, authenticate using a service account.

Authorization header

To authenticate the requests, use Basic Authentication. Create a service account and base64 encode the <KEY_ID>:<SECRET_KEY> and use it as the value of the Authorization header.

--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>' \

Deploy modules

Before you can deploy a module, you need to create it. If you are deploying the module using the API, it's likely you want to follow the manual workflow. You can deploy a module zip to the remote environment by sending the following request:

curl 'https://services.api.unity.com/cloud-code/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/modules' \
--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>' \
--form 'name="Module"' \
--form 'tags="{}"' \
--form 'language="CS"' \
--form 'file=@"Module.zip"'

Note: Storage limits apply. Check Cloud Code Limits.

Once you have deployed the module, you can start calling the module endpoints.

Update modules

You can update the module file, its tags or both by sending the following request:

curl--request PATCH 'https://services.api.unity.com/cloud-code/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/modules/<MODULE_NAME>' \
--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>' \
--form 'tags="{}"' \
--form 'file=@"Module.zip"'

The calls to the module endpoints will use the updated module file.

Retrieve modules

You can inspect the module you deployed by sending the following request:

curl --location 'https://services.api.unity.com/cloud-code/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/modules/<MODULE_NAME>' \
--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'

The response could look as follows:

{
  "name": "string",
  "language": "CS",
  "tags": {
    "property1": "string",
    "property2": "string"
  },
  "signedDownloadURL": "string",
  "dateCreated": "2022-04-05T09:12:13Z",
  "dateModified": "2022-04-05T09:12:13Z"
}

The response contains the following fields:

  • name: the name of the module.
  • language: the language of the module. Cloud Code modules currently support only C#.
  • tags: the custom user tags, defined as key value pairs
  • signedDownloadURL: the URL to download the module zip file.
  • dateCreated: the date when the module was created.
  • dateModified: the date when the module was last modified.

To preview all the modules you have deployed, send the following request:

curl 'https://services.api.unity.com/cloud-code/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/modules' \
--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'

The response could look as follows:

{
    "results": [
        {
            "name": "Module",
            "language": "CS",
            "signedDownloadURL": "example.com",
            "dateCreated": "2023-04-24T14:06:02Z",
            "dateModified": "2023-04-24T14:06:02Z"
        },
        {
            "name": "AnotherModule",
            "language": "CS",
            "signedDownloadURL": "example.com",
            "dateCreated": "2023-06-20T10:54:55Z",
            "dateModified": "2023-06-20T13:55:22Z"
        },
        {
            "name": "OtherModule",
            "language": "CS",
            "signedDownloadURL": "example.com",
            "dateCreated": "2023-03-28T10:18:21Z",
            "dateModified": "2023-03-28T10:18:21Z"
        }
    ],
    "links": {
        "next": null
    },
    "nextPageToken": ""
}

You can also use pagination by setting query parameters. For example, to get the first two modules, send the following request:

curl 'https://services.api.unity.com/cloud-code/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/modules?limit=2' \
--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'

The response would then be:

{
    "results": [
        {
            "name": "PostmanTest",
            "language": "CS",
            "signedDownloadURL": "example.com",
            "dateCreated": "2023-04-24T14:06:02Z",
            "dateModified": "2023-04-24T14:06:02Z"
        },
        {
            "name": "TestModule",
            "language": "CS",
            "signedDownloadURL": "example.com",
            "dateCreated": "2023-06-20T10:54:55Z",
            "dateModified": "2023-06-20T13:55:22Z"
        }
    ],
    "links": {
        "next": "/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/modules?after=<TOKEN>&limit=2"
    },
    "nextPageToken": "<TOKEN>"
}

Following the next link would allow you to get the next two modules.

Delete modules

You can delete the module by sending the following request:

curl --request DELETE 'https://services.api.unity.com/cloud-code/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/modules/<MODULE_NAME>' \
--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'

An empty response indicates a successful deletion.