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",
  "endpoints": {
    "ModuleEndpoint": {
      "parameters": {
        "parameter1": "System.String",
        "parameter2": "System.String"
      },
      "returnType": "System.Void"
    }
  },
  "hasError": true,
  "errorMessage": "error message"
}

The response contains the following fields:

FieldDescription
nameThe name of the module.
languageThe language of the module. Cloud Code modules only support C#.
tagsThe custom user tags, defined as key-value pairs.
signedDownloadURLThe URL to download the module zip file.
dateCreatedThe date the module was created.
dateModifiedThe date the module was last modified.
endpointsThe list of endpoints defined in the module, defined as key-value pairs. Each endpoint contains the list of parameters as key-value pairs and the endpoint return type.
hasErrorThis displays if the module has an error, such as an error in generating the endpoints, or an error in the module.
errorMessageThe error message if the module has an error. This is only included if the module has an error.

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.

Modules API spec

To retrieve the Open API spec for a given module, you can send the following request:

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

For an example, refer to the Admin API specification.

The response mime type is in text/html format. To download the openAPI specification in yaml format, you can download the spec from the Modules page in the Unity Cloud Dashboard. For more information, refer to using the Unity Cloud Dashboard.