[comment]: # translation:outdated

[comment]: # ({8961fc33-8961fc33})
# script.create

[comment]: # ({/8961fc33-8961fc33})

[comment]: # ({a2df1a0f-d7a51ffa})
### Описание

`object script.create(объект/массив scripts)`

Этот метод позволяет создавать новые сценарии.

::: noteclassic
Этот метод доступен только пользователю с типом доступа *Супер-администратор*.
Разрешения на вызов метода можно отозвать в настройках ролей пользователя.
Дополнительную информацию см. в разделе [Роли пользователей](/manual/web_interface/frontend_sections/users/user_roles).
:::

[comment]: # ({/a2df1a0f-d7a51ffa})

[comment]: # ({bcb9a453-bcb9a453})
### Параметры

`(объект/массив)` Создаваемые скрипты.

Этот метод принимает скрипты со [стандартными
свойствами скрипта](/manual/api/reference/script/object#script).

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

[comment]: # ({15216b8d-15216b8d})
### Возвращаемые значения

`(объект)` Возвращает объект, который содержит ID созданных скриптов, указанных в 
свойстве `scriptids`. Порядок возвращаемых ID совпадает с порядком
переданных скриптов.

[comment]: # ({/15216b8d-15216b8d})

[comment]: # ({b41637d2-b41637d2})
### Примеры

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

[comment]: # ({new-55d911d7})
#### Создание скрипта

Создание скрипта, который перезапускает сервер. Этот скрипт будет
требовать права записи к узлу сети и будет отображать сообщение
подтверждения в веб-интерфейсе до выполнения команды.

Запрос:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "script.create",
    "params": {
        "name": "Reboot server",
        "command": "reboot server 1",
        "host_access": 3,
        "confirmation": "Are you sure you would like to reboot the server?"
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Ответ:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "scriptids": [
            "3"
        ]
    },
    "id": 1
}
```

[comment]: # ({/new-55d911d7})

[comment]: # ({new-16a09744})
### Исходный код

CScript::create() в
*frontends/php/include/classes/api/services/CScript.php*.

[comment]: # ({/new-16a09744})

[comment]: # ({new-0e2eb663})
#### Create a custom script

Create a custom script that will reboot a server. The script will
require write access to the host and will display a configuration
message before running in the frontend.

Request:

``` {.java}
{
    "jsonrpc": "2.0",
    "method": "script.create",
    "params": {
        "name": "Reboot server",
        "command": "reboot server 1",
        "confirmation": "Are you sure you would like to reboot the server?",
        "scope": 2,
        "type": 0
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

``` {.java}
{
    "jsonrpc": "2.0",
    "result": {
        "scriptids": [
            "4"
        ]
    },
    "id": 1
}
```

[comment]: # ({/new-0e2eb663})

[comment]: # ({new-c363dc9b})
#### Create an URL type script

Create an URL type script that for host scope and remains in same window and has confirmation text.

Request:

```json
{
    "jsonrpc": "2.0",
    "method": "script.create",
    "params": {
        "name": "URL script",
        "type": 6,
        "scope": 2,
        "url": "http://zabbix/ui/zabbix.php?action=host.edit&hostid={HOST.ID}",
        "confirmation": "Edit host {HOST.NAME}?",
        "new_window": 0
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "scriptids": [
            "56"
        ]
    },
    "id": 1
}
```

[comment]: # ({/new-c363dc9b})

[comment]: # ({new-83bd22b0})
#### Create a URL type script with manual input

Create a URL type script for event scope that opens in a new window and has manual input.

[Request](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "script.create",
    "params": {
        "name": "URL script with manual input",
        "type": 6,
        "scope": 4,
        "url": "http://zabbix/ui/zabbix.php?action={MANUALINPUT}",
        "new_window": 1,
        "manualinput": 1,
        "manualinput_prompt": "Select a page to open:",
        "manualinput_validator": "dashboard.view,script.list,actionlog.list",
        "manualinput_validator_type": 1
    },
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "scriptids": [
            "57"
        ]
    },
    "id": 1
}
```

[comment]: # ({/new-83bd22b0})

[comment]: # ({8c09f129-8c09f129})
### Источник

CScript::create() в *ui/include/classes/api/services/CScript.php*.

[comment]: # ({/8c09f129-8c09f129})
