# Call to Cloud Code API

> Invoke scripts by making HTTP requests to the Cloud Code REST API.

Call out to the Cloud Code API to run your scripts. Refer to [Cloud Code API documentation](https://services.docs.unity.com/cloud-code/v1/index.html#tag/cloud-code/operation/runscript) for more information.

## Authentication

Refer to [Authentication](../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:

```bash
Authorization: Bearer <BEARER_TOKEN>
```

## Run script request

Call out to the Cloud Code API by sending a POST request to:

```http request
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:

```bash
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.

```json
{
  "params": {
    "numericParam": 123,
    "stringParam": "abcdef",
    "booleanParam": true,
    "jsonParam": {
      "key": "value"
    }
  }
}
```

A complete cURL command could look like this:

```bash
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.

```json
{
  "output": {
    "playerInfo": {
      "playerID": "TestUser",
      "userName": "TestUserName",
      "displayName": "Name",
      "email": "test@test.com",
      "country": null,
      "deviceType": null,
      "platform": "IOS",
      "dateCreated": "string"
    }
  }
}
```
