Call to Cloud Code API
Call out to the Cloud Code API to run your scripts. Refer to Cloud Code API documentation for more information.
Authentication
Refer to Authentication to authenticate as a player or a trusted client using a service-account or a stateless token. Use the received token as a bearer token for HTTP authentication in the request header:
Authorization: Bearer <BEARER_TOKEN>
Run script request
Call out to the Cloud Code API by sending a POST request to:
https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/scripts/<SCRIPT_NAME>
Define the path parameters:
projectId
- The ID of the project.scriptName
- The name of the script.
A simple cURL command could look like this:
curl --request POST 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/scripts/<SCRIPT_NAME>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <BEARER_TOKEN>'
Request payload
You can define parameters in your script. These parameters are passed in the request body.
If the script has no parameters, you can pass in an empty params
object.
{
"params": {
"numericParam": 123,
"stringParam": "abcdef",
"booleanParam": true,
"jsonParam": {
"key": "value"
}
}
}
A complete cURL command could look like this:
curl --request POST 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/scripts/<SCRIPT_NAME>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <BEARER_TOKEN>' \
--data-raw '{
"params": {
"numericParam": 123,
"stringParam": "abcdef",
"booleanParam": true,
"jsonParam": {
"key": "value"
}
}
}'
Sample output
This is an example output of a script that returns a playerInfo
object.
{
"output": {
"playerInfo": {
"playerID": "TestUser",
"userName": "TestUserName",
"displayName": "Name",
"email": "test@test.com",
"country": null,
"deviceType": null,
"platform": "IOS",
"dateCreated": "string"
}
}
}