HTTP APIs
Manage trigger configurations using raw HTTP APIs and the Triggers Admin API.
Read time 3 minutesLast updated 18 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>Authorization--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>' \
Deploy triggers
You can set up a trigger configuration by sending the following request:A successful response contains information about the trigger configuration. For example: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\""}'
{ "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'"}
- : The trigger configuration ID.
id - : The date and time when the trigger configuration was created.
createdAt - : The date and time when the trigger configuration was last updated.
updatedAt - : The trigger configuration name.
name - : The associated project ID.
projectId - : The associated environment ID.
environmentId - : The event type that triggers the trigger configuration.
eventType - : The type of the action to be executed when the trigger is fired. Currently, only
actionTypeis supported.cloud-code - : Defines what should be invoked when the trigger is fired. For example,
actionUrninvokes theurn:ugs:cloud-code:TestScriptCloud Code script, orTestScriptinvokes theurn:ugs:cloud-code:TestModule/TestFunctionfunction in theTestFunctionCloud Code module.TestModule - : 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.
filter
ideventTypeRetrieve triggers
To check the trigger configuration, send the following request:The response could look as follows:curl 'https://services.api.unity.com/triggers/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/configs/<CONFIG_ID>' \--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'
To preview all the triggers you have deployed, send the following request:{ "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"}
The response could look as follows:curl 'https://services.api.unity.com/triggers/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/configs' \--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'
You can also use pagination by setting query parameters. For example, to get the first two configurations, send the following request:{ "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": ""}
The response would then be:curl 'https://services.api.unity.com/triggers/v1/projects/<PROJECT_ID>/environments/<ENVIRONMENT_ID>/configs?limit=2' \--header 'Authorization: Basic <SERVICE_ACCOUNT_CREDENTIALS_ENCODED>'
Using the{ "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>"}
afterThe last trigger is returned: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>'
{ "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:An empty response indicates a successful deletion.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>'