Documentation

Support

Triggers

HTTP APIs

Manage trigger configurations using raw HTTP APIs and the Triggers Admin API.
Read time 4 minutesLast updated 3 hours ago

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. Supported values are
    cloud-code
    and
    webhook
    . For webhook triggers, include a
    webhook
    object in the request body; refer to Webhooks.
  • actionUrn
    : The definition for what you invoke when the trigger is fired. For example,
    urn:ugs:cloud-code:TestScript
    invokes 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.

Create a webhook trigger

To send event payloads to an external URL instead of running Cloud Code, create a trigger with
actionType: webhook
and a
webhook
object:
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": "notify-score-webhook", "eventType": "com.unity.services.leaderboards.score-submitted.v1", "actionType": "webhook", "actionUrn": "urn:ugs:webhook", "webhook": { "url": "https://example.com/events", "method": "POST", "headers": { "Content-Type": "application/json" }, "payloadTemplate": "{\"event\": \"score-submitted\", \"data\": {{.}}}" }}'
When the event is fired, the Triggers service sends an HTTP request to the configured URL. Failed deliveries can be managed from the dead letter queue. For full webhook configuration options, refer to Webhooks.

Retrieve triggers

To check the trigger configuration, send the following request:
curl 'https://services.api.unity.com/triggers/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/configs/<CONFIG_ID>' \--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'
The response could look as follows:
{ "id": "ad06a027-d0e6-47d9-bf84-ad7d20ed5a66", "createdAt": "2024-07-30T15:59:08Z", "updatedAt": "2024-07-30T15:59:08Z", "name": "test-leaderboard-trigger", "projectId": "0ea7b997-b8bc-4125-97f9-e082e0cbf355", "environmentId": "c9acf5d7-d53b-4bc7-b622-7b63c1ee6dc7", "eventType": "com.unity.services.leaderboards.score-submitted.v1", "actionType": "cloud-code", "actionUrn": "urn:ugs:cloud-code:test-score-script", "filter": "data['score'] > 1000 || data['score'] > 56"}
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 following code is an example response:
{ "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.