HTTP APIs

You can use the raw HTTP APIs to manage trigger configurations.

Using the API

The Triggers Admin API documentation contains a detailed description of admin operations, such as creating, reading, and deleting triggers.

The 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 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 triggers

You can set up a trigger configuration by sending the following request:

curl 'https://services.api.unity.com/triggers/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/configs' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>' \
--data '{
  "name": "example-trigger-name",
  "eventType": "com.unity.services.scheduler.example-event.v1",
  "actionType": "cloud-code",
  "actionUrn": "urn:ugs:cloud-code:MyTestScript"
  "filter": "data[\"parameter\"] == \"value\""
}'

A successful response contains information about the trigger configuration. For example:

{
  "id": "12675a97-5166-4a7e-bee4-6c3a856026a8",
  "createdAt": "2023-08-25T14:01:16Z",
  "updatedAt": "2023-08-25T14:01:16Z",
  "name": "example-trigger-name",
  "projectId": "0ea7b997-b8bc-4125-97f9-e082e0cbf355",
  "environmentId": "de4504b7-70ca-475a-8862-00b5150f1d56",
  "eventType": "com.unity.services.scheduler.example-event.v1",
  "actionType": "cloud-code",
  "actionUrn": "urn:ugs:cloud-code:MyTestScript",
  "filter": "data['parameter'] == 'value'"
}
  • id: The trigger configuration ID.
  • createdAt: The date and time when the trigger configuration was created.
  • updatedAt: The date and time when the trigger configuration was last updated.
  • name: The trigger configuration name.
  • projectId: The associated project ID.
  • environmentId: The associated environment ID.
  • eventType: The event type that triggers the trigger configuration.
  • actionType: The type of the action to be executed when the trigger is fired. Currently, only cloud-code is supported.
  • actionUrn: Defines what should be invoked when the trigger is fired. For example, urn:ugs:cloud-code:TestScriptinvokes the TestScript Cloud Code script, or urn:ugs:cloud-code:TestModule/TestFunction invokes the TestFunction function in the TestModule Cloud Code module.
  • filter: An optional field that defines a condition that must be met for the trigger to fire. If the condition isn't met, the trigger doesn't fire. For more information, refer to Filters.

You can use the id to delete the trigger.

Given you associated the trigger with an existing Cloud Code script or module, emitting the event with the specified eventType fires the trigger, executing the associated Cloud Code script or module.

Retrieve triggers

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

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

The response could look as follows:

{
  "configs": [
    {
      "id": "c5cc255e-93e5-4ac8-9b9a-f16a94892fff",
      "createdAt": "2023-08-25T14:07:56Z",
      "updatedAt": "2023-08-25T14:07:56Z",
      "name": "example-trigger-name-3",
      "eventType": "com.unity.services.scheduler.other-event.v1",
      "actionType": "cloud-code",
      "actionUrn": "urn:ugs:cloud-code:TestModule/TestEndpoint"
    },
    {
      "id": "acf63347-4523-427b-937b-d73943d542dd",
      "createdAt": "2023-08-25T14:07:31Z",
      "updatedAt": "2023-08-25T14:07:31Z",
      "name": "example-trigger-name-2",
      "eventType": "com.unity.services.authentication.signed-up.v1",
      "actionType": "cloud-code",
      "actionUrn": "urn:ugs:cloud-code:TestModule/TestEndpoint"
    },
    {
      "id": "12675a97-5166-4a7e-bee4-6c3a856026a8",
      "createdAt": "2023-08-25T14:01:16Z",
      "updatedAt": "2023-08-25T14:01:16Z",
      "name": "example-trigger-name",
      "eventType": "com.unity.services.scheduler.example-event.v1",
      "actionType": "cloud-code",
      "actionUrn": "urn:ugs:cloud-code:MyTestScript",
      "filter": "data['parameter'] == 'value'"
    }
  ],
  "limit": 100,
  "after": ""
}

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

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

The response would then be:

{
  "configs": [
    {
      "id": "c5cc255e-93e5-4ac8-9b9a-f16a94892fff",
      "createdAt": "2023-08-25T14:07:56Z",
      "updatedAt": "2023-08-25T14:07:56Z",
      "name": "example-trigger-name-3",
      "eventType": "com.unity.services.scheduler.other-event.v1",
      "actionType": "cloud-code",
      "actionUrn": "urn:ugs:cloud-code:TestModule/TestEndpoint"
    },
    {
      "id": "acf63347-4523-427b-937b-d73943d542dd",
      "createdAt": "2023-08-25T14:07:31Z",
      "updatedAt": "2023-08-25T14:07:31Z",
      "name": "example-trigger-name-2",
      "eventType": "com.unity.services.scheduler.another-event.v1",
      "actionType": "cloud-code",
      "actionUrn": "urn:ugs:cloud-code:TestModule/TestEndpoint"
    }
  ],
  "limit": 2,
  "after": "<TOKEN>"
}

Using the after token, you can get the next page of results. For example:

curl 'https://services.api.unity.com/triggers/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/configs?limit=2&after=<TOKEN>' \
--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'

The last trigger is returned:

{
  "configs": [
    {
      "id": "12675a97-5166-4a7e-bee4-6c3a856026a8",
      "createdAt": "2023-08-25T14:01:16Z",
      "updatedAt": "2023-08-25T14:01:16Z",
      "name": "example-trigger-name",
      "eventType": "com.unity.services.scheduler.example-event.v1",
      "actionType": "cloud-code",
      "actionUrn": "urn:ugs:cloud-code:MyTestScript",
      "filter": "data['parameter'] == 'value'"
    }
  ],
  "limit": 2,
  "after": ""
}

Delete triggers

You can delete the trigger configuration by sending the following request:

curl --request DELETE 'https://services.api.unity.com/triggers/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/configs/<CONFIG_ID>' \
--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'

An empty response indicates a successful deletion.