[comment]: # translation:outdated

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

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

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

`object script.create(object/array scripts)`

Šī metode ļauj izveidot jaunus skriptus.

::: noteclassic
Šī metode ir pieejama tikai *Super admin* lietotāja tipam.
Atļaujas izsaukt šo metodi var tikt atsauktas lietotāja lomas iestatījumos. Skatiet
[Lietotāju
lomas](/manual/web_interface/frontend_sections/users/user_roles)
papildinformācijai.
:::

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

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

`(object/array)` Skripti, ko izveidot.

Metode pieņem skriptus ar [standarta skripta
īpašībām](/manual/api/reference/script/object#script).

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

[comment]: # ({15216b8d-15216b8d})
### Atgrieztās vērtības

`(object)` Atgriež objektu, kas satur izveidoto skriptu ID
īpašībā `scriptids`. Atgriezto ID secība atbilst
nodoto skriptu secībai.

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

[comment]: # ({b41637d2-b41637d2})
### Piemēri

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

[comment]: # ({71603cb8-55d911d7})
#### Izveidot webhook skriptu

Izveidojiet webhook skriptu, kas nosūta HTTP pieprasījumu uz ārēju servisu.

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "script.create",
    "params": {
        "name": "Webhook script",
        "command": "try {\n var request = new HttpRequest(),\n response,\n data;\n\n request.addHeader('Content-Type: application/json');\n\n response = request.post('https://localhost/post', value);\n\n try {\n response = JSON.parse(response);\n }\n catch (error) {\n response = null;\n }\n\n if (request.getStatus() !== 200 || !('data' in response)) {\n throw 'Unexpected response.';\n }\n\n data = JSON.stringify(response.data);\n\n Zabbix.log(3, '[Webhook Script] response data: ' + data);\n\n return data;\n}\ncatch (error) {\n Zabbix.log(3, '[Webhook Script] script execution failed: ' + error);\n throw 'Execution failed: ' + error + '.';\n}",
        "scope": 1,
        "type": 5,
        "timeout": "40s",
        "parameters": [
            {
                "name": "token",
                "value": "{$WEBHOOK.TOKEN}"
            },
            {
                "name": "host",
                "value": "{HOST.HOST}"
            },
            {
                "name": "v",
                "value": "2.2"
            }
        ]
    },
    "id": 1
}
```

Atbilde:

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

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

[comment]: # ({e3a6c1b8-16a09744})
#### Izveidot SSH skriptu

Izveidojiet SSH skriptu ar publiskās atslēgas autentifikāciju, ko var izpildīt
uz hosta un kam ir konteksta izvēlne.

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "script.create",
    "params": {
        "name": "SSH script",
        "command": "my script command",
        "type": 2,
        "authtype": 1,
        "username": "John",
        "publickey": "pub.key",
        "privatekey": "priv.key",
        "password": "secret",
        "port": "12345",
        "scope": 2,
        "menu_path": "All scripts/SSH",
        "usrgrpid": "7",
        "groupid": "4"
    },
    "id": 1
}
```

Atbilde:

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

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

[comment]: # ({189a5044-0e2eb663})
#### Izveidot pielāgotu skriptu

Izveidojiet pielāgotu skriptu, kas pārstartēs serveri. Skriptam būs
nepieciešama rakstīšanas piekļuve hostam, un tas aicinās lietotāju ievadīt 
manuālu ievadi. Pēc veiksmīgas ievades iesniegšanas skripts parādīs
apstiprinājuma ziņojumu lietotāja saskarnē.

[Pieprasījums](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "script.create",
    "params": {
        "name": "Reboot server",
        "command": "reboot server {MANUALINPUT}",
        "type": 0,
        "scope": 2,
        "confirmation": "Are you sure you would like to reboot the server {MANUALINPUT}?",
        "manualinput": 1,
        "manualinput_prompt": "Which server you want to reboot?",
        "manualinput_validator": "[1-9]",
        "manualinput_validator_type": 0,
        "manualinput_default_value": "1"
    },
    "id": 1
}
```

Atbilde:

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

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

[comment]: # ({aecb5455-c363dc9b})
#### Izveidot URL tipa skriptu

Izveidojiet URL tipa skriptu hosta tvērumam, kas paliek tajā pašā logā un kam ir apstiprinājuma teksts.

[Pieprasījums](/manual/api#performing-requests):

```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": "Rediģēt hostu {HOST.NAME}?",
        "new_window": 0
    },
    "id": 1
}
```

Atbilde:

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

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

[comment]: # ({9b0cfc65-83bd22b0})
#### Izveidojiet URL tipa skriptu ar manuālu ievadi

Izveidojiet URL tipa skriptu notikuma tvērumam, kas tiek atvērts jaunā logā un kam ir manuāla ievade.

[Pieprasījums](/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
}
```

Atbilde:

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

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

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

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

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