[comment]: # ({3a2a8d58-3a2a8d58})
# script.execute

[comment]: # ({/3a2a8d58-3a2a8d58})

[comment]: # ({60a9dbe3-60a9dbe3})
### 説明

`object script.execute(object parameters)`

このメソッドで、ホストまたはイベントでスクリプトを実行できます。

::: noteclassic
このメソッドはどのタイプのユーザーでも利用可能です。このメソッドを呼び出す権限は、ユーザーロール設定で取り消すことができます。詳しくは[ユーザーの役割](/manual/web_interface/frontend_sections/administration/user_roles)を参照してください。
:::

[comment]: # ({/60a9dbe3-60a9dbe3})

[comment]: # ({962e590e-e4fa8ac7})
### パラメータ

`(object)` 実行するスクリプトのIDと、ホストIDまたはイベントIDのいずれかを含むパラメーター。

|パラメータ|[タイプ](/manual/api/reference_commentary#data_types)|説明|
|--|--|------|
|**scriptid**<br>(必須)|string|実行するスクリプトのID|
|hostid|string|スクリプトを実行するホストのID|
|eventid|string|スクリプトを実行するイベントのID|

[comment]: # ({/962e590e-e4fa8ac7})

[comment]: # ({47d23fd5-dde54e60})
### 戻り値

`(object)` スクリプトの実行結果を返します。

|プロパティ|[タイプ](/manual/api/reference_commentary#data_types)|説明|
|--|--|------|
|response|string|スクリプトが正常に実行されたか。<br><br>可能な値 - `success`|
|value|string|スクリプトの出力|
|debug|object|Webhook スクリプトが実行される場合、[デバッグ オブジェクト](/manual/api/reference/script/object#Debug) が含まれます。 他のスクリプト タイプの場合、空のオブジェクトが含まれます。|

[comment]: # ({/47d23fd5-dde54e60})

[comment]: # ({b41637d2-b41637d2})
### 例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({719944b8-03cb1cf3})
#### Webhookスクリプトを実行する

HTTPリクエストを外部サービスに送信するWebhookスクリプトを実行します

Request:

```json
{
    "jsonrpc": "2.0",
    "method": "script.execute",
    "params": {
        "scriptid": "4",
        "hostid": "30079"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "response": "success",
        "value": "{\"status\":\"sent\",\"timestamp\":\"1611235391\"}",
        "debug": {
            "logs": [
                 {
                     "level": 3,
                     "ms": 480,
                     "message": "[Webhook Script] HTTP status: 200."
                 }
             ],
             "ms": 495
        }
    },
    "id": 1
}
```

[comment]: # ({/719944b8-03cb1cf3})

[comment]: # ({36041e06-baebff97})
#### カスタムスクリプト実行

ホストで"ping"スクリプトを実行します。

Request:

```json
{
    "jsonrpc": "2.0",
    "method": "script.execute",
    "params": {
        "scriptid": "1",
        "hostid": "30079"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "response": "success",
        "value": "PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.\n64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.074 ms\n64 bytes from 127.0.0.1: icmp_req=2 ttl=64 time=0.030 ms\n64 bytes from 127.0.0.1: icmp_req=3 ttl=64 time=0.030 ms\n\n--- 127.0.0.1 ping statistics ---\n3 packets transmitted, 3 received, 0% packet loss, time 1998ms\nrtt min/avg/max/mdev = 0.030/0.044/0.074/0.022 ms\n",
        "debug": []
    },
    "id": 1
}
```

[comment]: # ({/36041e06-baebff97})

[comment]: # ({e7dc45a5-e7dc45a5})
### ソース

CScript::execute() in *ui/include/classes/api/services/CScript.php*.

[comment]: # ({/e7dc45a5-e7dc45a5})
