# Cloud Code API 호출

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

스크립트를 실행하려면 Cloud Code API를 호출합니다. 자세한 내용은 [Cloud Code API 기술 자료](https://services.docs.unity.com/cloud-code/v1/index.html#tag/cloud-code/operation/runscript)를 참고하십시오.

## 인증##authentication

서비스 계정이나 상태 비보존 토큰을 사용하여 플레이어 또는 신뢰할 수 있는 클라이언트로 인증하려면 [인증](../authentication)을 참고하십시오. 받은 토큰을 요청 헤더에서 HTTP 인증을 위한 bearer 토큰으로 사용합니다.

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

## 스크립트 요청 실행##run-script-request

POST 요청을 다음으로 보내 Cloud Code API를 호출합니다.

```http request
https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/scripts/<SCRIPT_NAME>
```

다음과 같이 경로 파라미터를 정의합니다.

* `projectId` - 프로젝트 ID입니다.
* `scriptName` - 스크립트 이름입니다.

간단한 cURL 커맨드는 다음과 같습니다.

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

스크립트에서 파라미터를 정의할 수 있습니다. 이러한 파라미터는 요청 본문에서 전달됩니다. 스크립트에 파라미터가 없는 경우 빈 `params` 오브젝트를 전달할 수 있습니다.

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

완전한 cURL 커맨드는 다음과 같습니다.

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

다음은 `playerInfo` 오브젝트를 반환하는 스크립트 출력 예시입니다.

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